Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I change a image on a Button using Windows Forms?

How do I toggle between two images on a Button? I have a "Lock" and "Unlock" image I would like to use on the same button.

So far I have used the property window to set a single image..

UPDATE: Many good answers, but I should have mention that my two images is in the Property folder. How do I access them with a relative path?

like image 562
radbyx Avatar asked Jan 17 '12 13:01

radbyx


1 Answers

Easy:

button1.Image = System.Drawing.Image.FromFile(@"C:\Users\Administrator\Pictures\forestfloor.jpg");

P.S. Before set image, check if it exist

like image 86
zzfima Avatar answered Sep 25 '22 00:09

zzfima