Click here to Skip to main content
15,888,454 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I tried to change the button background at runtime after the controls has been initialized but the button background does not changed any idea i used the following piece of code

I read the image path from xml file it is ok with path and file name


btn1.BackgroundImage = System.Drawing.Image.FromFile(imagepath + x.Attribute(XName.Get("Image")).Value);
Posted

It works fine for me.
So: the first thing to do is to check that your code is being executed.
Put a breakpoint on the line you show above, and make sure it is hit.
If it is, then create a string which holds the full info:
C#
string path = imagepath + x.Attribute(XName.Get("Image")).Value;
Look at "path" in the debugger, and make sure that the file exists and is fully reachable from that PC.
If that's all ok, look at the BackgroundImage property and make sure it is set to an image.
Then double check that btn1 is actually on the display!

One of those should give you an idea what the problem is: if it doesn't, then tell us what you get at each stage above, and we will see what we can do.
 
Share this answer
 
Comments
Waleedkassem 30-Jul-12 14:33pm    
i have to use the update() method to redraw the ucontrol
winforms or wpf?
try this:
`http://msdn.microsoft.com/en-us/library/system.windows.forms.control.update.aspx[^]
you can "force" a control to repaint by calling the update method. there is also something like "startrender" and "stoprender", but i forgot the exact name and usage.
 
Share this answer
 
Comments
Waleedkassem 30-Jul-12 14:32pm    
thank you

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