这似乎是一件相当基本的事情,但由于某种原因,它只是默默地失败了:
/// <summary>
/// Sets the button to show it's busy image
/// </summary>
public void SetBusy()
{
if (Control is Button)
{ ((Button)Control).Image = BusyImage; }
else if (Control is ToolStripButton)
{ ((ToolStripButton)Control).Image = BusyImage; }
}
BusyImage 设置使用BusyImage = Properties.Resources.Busy;
如果我对此进行调试,我可以看到图像似乎设置正确(如果我在断点处将鼠标悬停在 Image 成员上,我可以看到它发生变化),但是当您查看按钮时它实际上并没有改变图像.
我注意到,当上述所有代码与 UI 都托管在同一个项目文件中时,这可以工作,但是当它被运送到不同的项目(但在同一个解决方案中)时,它会默默地失败。
有什么想法我哪里出错了吗?
谢谢
编辑 1:即使尝试将图像设置为与 ToolStripButton 相同的项目的资源中的文件也不起作用(仍然静默失败)。
有趣的是,无论图像在哪个项目中,使用普通按钮时它都可以正常工作。
为什么 Button 和 ToolStripButton 的行为存在差异?
编辑 2:似乎将设置图像的代码移动到与 ToolStripButton 相同的项目中。但是,如果可能的话,我想把它放在一个单独的项目中......