[英]Change icon of all running forms
I have got 3 forms and on one of them there is a button which is supposed to change icons of all my running forms. 我有3种表单,其中一种表单上有一个按钮,可以用来更改我所有正在运行的表单的图标。
I cannot figure out how to change the icon on the other two forms, I have managed to do so on just one form (where the button is located). 我无法弄清楚如何更改其他两种表单上的图标,我设法仅在一种表单(按钮所在的位置)上进行了更改。
I have tried this way: 我已经尝试过这种方式:
private void button2_Click(object sender, EventArgs e)
{
this.Icon = Properties.Resources.Purple;
Form1 f1 = new Form1();
Form f2 = new Form2();
f1.Icon = Properties.Resources.Purple;
f2.Icon = Properties.Resources.Purple;
}
... but had no success. ...但是没有成功。
Basically, I am stuck here now, since the code above doesn't work for me: 基本上,我现在停留在这里,因为上面的代码对我不起作用:
private void button2_Click(object sender, EventArgs e)
{
this.Icon = Properties.Resources.Purple;
}
Any ideas? 有任何想法吗?
You should be able to use the OpenForms
collection in the Application
class to iterate over all the open Forms and set the Icon
您应该能够使用Application
类中的OpenForms
集合来遍历所有打开的Forms并设置Icon
Example: 例:
foreach (var form in Application.OpenForms.Cast<Form>())
{
form.Icon = Properties.Resources.Purple;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.