单击按钮更改所有表单中的背景 [英] Change background in all forms with a button click

查看:60
本文介绍了单击按钮更改所有表单中的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我制作了两个表格,Form2有背景图像按钮。当我按下所有表格上的按钮设置背景时,我该怎么办?因为我做了一些编码:



this.BackgroundImage = new Bitmap(Properties.Resources._8_8008_by_amplifier404,new Size(800,500));

//其中_8_8008_by_amplifier404是图像的名称



它只更改具有该按钮的表单上的背景图像但我想在单击该按钮更改背景时在所有表格上?!

解决方案

试着这样称呼:



 CheckForm(Color.Red); 

private void CheckForm(Color col)
{
foreach (表格形式 in Application.OpenForms)
{
表格。 BackColor = col;
}
}


default1:

< pre lang =c#> protected void Button1_Click( object sender,EventArgs e)
{
nam.Attributes [ bgcolor] = 红色;
会话[ col] = nam.Attributes [ bgcolor];

}
}



aspx:

< body id =   nam runat =   server >  
< form id = form1 runat = server >
< div>
< asp:button id = Button1 runat = server text = 按钮 onclick = Button1_Click />
< p>
< asp:hyperlink id = HyperLink1 runat = server navigateurl = 〜/ Default2.aspx> new < / asp:hyperlink < span class =code-keyword>>
< / p >
< / form >
< / 正文 >



default2

 受保护  void  Page_Load( object  sender,EventArgs e)
{
sj.Attributes [ bgcolor] =会话[ col]。ToString();
}


设置所有表格的背景图片

  foreach (表单myform  in  Application.OpenForms)
{
myform.BackgroundImage = new 位图( @ C:\ Users \ xxxx \ Desktop\stripe1.png);
}


I made 2 forms and Form2 has buttons for background images. How can I, when I press that button set background on all forms. Because when I did some coding :

this.BackgroundImage = new Bitmap(Properties.Resources._8_8008_by_amplifier404, new Size(800, 500));
// where _8_8008_by_amplifier404 is name of the image

it only changes background image on form which has that button but I want when I click that button to change background on all forms?!

解决方案

Try to call this :

CheckForm(Color.Red);

private void CheckForm(Color col )
{
    foreach(Form form in Application.OpenForms)
    {
        form.BackColor = col;
    }
}


default1:

protected void Button1_Click(object sender, EventArgs e)
    {
        nam.Attributes["bgcolor"] ="Red";
        Session["col"] = nam.Attributes["bgcolor"];
        
    }
}


aspx:

<body id="nam" runat="server">
    <form id="form1" runat="server">
    <div>        
        <asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" />
        <p>
            <asp:hyperlink id="HyperLink1" runat="server" navigateurl="~/Default2.aspx">new</asp:hyperlink>
        </p>
    </form>
</body>


default2

protected void Page_Load(object sender, EventArgs e)
{
       sj.Attributes["bgcolor"] = Session["col"].ToString();
}


set background image for all forms like this

foreach (Form myform in Application.OpenForms)
{
    myform.BackgroundImage = new Bitmap(@"C:\Users\xxx\Desktop\stripe1.png");
}


这篇关于单击按钮更改所有表单中的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆