473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

c# Change background in all forms with a button click

I made 2 forms and Form2 has buttons with images like planets and game wallpapers etc. When I write the code for button:

Expand|Select|Wrap|Line Numbers
  1. this.BackgroundImage = new Bitmap(Properties.Resources._8_8008_by_amplifier404); this.BackgroundImageLayout = ImageLayout.Stretch;
  2. // where _8_8008_by_amplifier404 is name of the image located in resources
it only changes background in form which has those buttons as long the form is used. Once I go back to form1 it's changed to null. How to set background in all forms with a button click which will be there until another button with an image is clicked.
Attached Images
File Type: jpg two.jpg (69.7 KB, 413 views)
File Type: jpg three.jpg (76.7 KB, 445 views)
Jul 14 '13 #1
3 3941
Frinavale
9,735 Expert Mod 8TB
You could raise an event that is caught by all pages that need to change their background when the background is changed. Pass the value for the new background image using a custom EventArgs.

Handle the event in the forms that need to change their backgrounds and in this method retrieve the new value from the EventArgs so that they can actually change the background.

If the forms that need to change their backgrounds do not have an instance of the control that causes the background to change, than make sure that your event is a Shared/Static event so that they can still handle it.

Be sure to remove handlers to shared events when objects are destroyed/disposed of.

-Frinny
Jul 15 '13 #2
Can you write a code for that?!
Jul 16 '13 #3
Frinavale
9,735 Expert Mod 8TB
You can find information about Raising events here:
Raising an Event
You can find information about Handling events here:
Handling and Raising Events

Instead of just having a public delegate you can define it's scope as a public static delegate so that it is shared event that can be caught by all windows.
Jul 16 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Cary Linkfield | last post by:
I have a standard form I use. It inherits from Windows.Forms.Form. I usually add a Cancel button the form in the designer. I want to raise the Cancel button's Click event when the user presses...
3
by: Scott Schade | last post by:
I have a form onto which I add a control during execution. The control is a control that I wrote. The control has a number of controls on it. I would like to click on a button on the control and...
18
by: jrhoads23 | last post by:
Hello, I am trying to find a way to tell if an .NET windows forms Button (System.Windows.Forms.Button) is "depressed" (pushed down). For my application, I can not use a check box control set to...
11
by: CW | last post by:
I have message entry screen that's causing me a bit of an issue. At the moment, there are 2 buttons, one is used to send message to another user (btnSend) and another is used to send messages to...
1
by: Waqas Pitafi | last post by:
Hi, 3rd day is already gone without any solution. My problem is, I have a Windows Server 2003 sp1 machine as my development platform having NTFS filesystem. Other notable components installed...
11
by: Sarah | last post by:
I have code that I want to run so that if the result is true, it changes the current button's ".DialogResult" property to "DialogResult.OK". Problem is, when I run this code on the ".Click" event...
2
by: sonali_aurangabadkar | last post by:
i want to hide some columns of a details view on a button click and want to change the name of that button my problem is that i am able to hide the column but can't able to change name of...
3
by: GauravGupta | last post by:
i want to know that is it posible to call button click event before page load event on post back.... please help me....
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
3
by: Andrew Jocelyn | last post by:
Hi I have couple of dropdown controls each with a requiredfieldvalidator. I clear the dropdownlist in the button click event. When the page is rendered the dropdown validator already flags it's...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.