Click here to Skip to main content
15,906,625 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?!
Posted
Comments
Keno995 13-Jul-13 16:48pm    
It's not colour as background, it's an image like planes or games wallpaper, etc. How to do it with a bitmap as a resource

Try to call this :

C#
CheckForm(Color.Red);

private void CheckForm(Color col )
{
    foreach(Form form in Application.OpenForms)
    {
        form.BackColor = col;
    }
}
 
Share this answer
 
v2
default1:
C#
protected void Button1_Click(object sender, EventArgs e)
    {
        nam.Attributes["bgcolor"] ="Red";
        Session["col"] = nam.Attributes["bgcolor"];
        
    }
}

aspx:
C#
<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
C#
protected void Page_Load(object sender, EventArgs e)
{
       sj.Attributes["bgcolor"] = Session["col"].ToString();
}
 
Share this answer
 
v3
set background image for all forms like this
C#
foreach (Form myform in Application.OpenForms)
{
    myform.BackgroundImage = new Bitmap(@"C:\Users\xxx\Desktop\stripe1.png");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900