I try to make a simple program where I have an image in a label.
The name of the label is just label1.
The name of the old image is dob1.png and is initially placed in label1.image property using the Form.cs designer.
Now I want to replace dob1.png by the new dob2.png at runtime when you click on a button.
I know that I must put the code in the button-click event, but I dont know what the code should be.
What I think is that it should start with something like
this.label1.image .......
but what comes next? I cannot find it in the help of Visual-C# Express.
Can somebody help me out?
Loading
syncanPosted Nov 16, 2010, 7:21 AM
From what you wrote it is easiest to use the picturebox, followed by your:
label1.Image = pictureBox1.Image
EDIT: I tried it this way and hided the new dob2 under a panel. This way I was able to make it visible during run-time. I plan to make my own little dice-game, so a lot of other things should be added on the form.
Zoran HorvatPosted Nov 16, 2010, 7:10 AM
You can load image from file using Image.FromFile method.
You can embed image in local resources and then use it at runtime like in this article.
You can set image to a different control, e.g. some PictureBox and then just do: label1.Image = pictureBox1.Image.