I am busy making a simple game in Visual C#, and I have no idea how to do this. Is there a way to set a PictureBox's image when a CheckBox is checked? What is the actual code for setting the image?
Thanks,
Varmitharen
I am busy making a simple game in Visual C#, and I have no idea how to do this. Is there a way to set a PictureBox's image when a CheckBox is checked? What is the actual code for setting the image?
Thanks,
Varmitharen
It depends how you've got your image, but you can use:
this.pictureBox.Load(imageFileName);
or
this.pictureBox.Image = image;
where image
is of type Image
Just to complete the answer:
this.checkbox.CheckedChanged += new EventHandler(Checkbox_CheckedChanged);
private void Checkbox_CheckedChanged(object sender, EventArgs e)
{
// Change image here
}
There is a CheckedChanged event of a CheckBox that you can subscribe to with a handler that changes the image. Link: CheckBox.CheckedChanged
this.MyCheckbox.CheckedChanged += new EventHandler(MyCheckbox_CheckedChanged);
private void MyCheckbox_CheckedChanged(object sender, EventArgs e)
{
this.MyPictureBox.Image = // Your image here
}