我在动态设置应用程序图标方面遇到了麻烦。在VS2012中进行调试时,一切正常(应用程序顶部栏和任务栏上的图标更改。但是当我部署应用程序时,任务栏上的图标更改不起作用。在这种情况下应用程序更改顶部栏(左侧)和弹出窗口中的图标后,将光标移动到任务栏图标上 - 如屏幕截图所示。
dynamically icon change - proof of concept
代码非常简单(概念证明):
public partial class Form1 : Form
{
private Bitmap bitmap;
private IntPtr hicon;
private Icon selectedIcon;
public Form1()
{
InitializeComponent();
}
private void SetUpIcon(Bitmap resource)
{
hicon = resource.GetHicon();
selectedIcon = Icon.FromHandle(hicon);
this.Icon = selectedIcon;
}
private void btnFirstIcon_Click(object sender, EventArgs e)
{
bitmap = Resources.Resources.save_main;
SetUpIcon(bitmap);
lblStatus.Text = "First icon set up!";
}
private void btnSecondIcon_Click(object sender, EventArgs e)
{
bitmap = Resources.Resources.search;
SetUpIcon(bitmap);
lblStatus.Text = "Second icon set up!";
}
private void btnThirdIcon_Click(object sender, EventArgs e)
{
bitmap = Resources.Resources.team;
SetUpIcon(bitmap);
lblStatus.Text = "Third icon set up!";
}
感谢您提出的解决此问题的所有建议。 : - )