0

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

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
Varmitharen
  • 13
  • 1
  • 6

3 Answers3

2

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
}
ChrisF
  • 134,786
  • 31
  • 255
  • 325
1

There is a CheckedChanged event of a CheckBox that you can subscribe to with a handler that changes the image. Link: CheckBox.CheckedChanged

KeithS
  • 70,210
  • 21
  • 112
  • 164
  • Yes, I know how to get the event working. Sorry if my question was ambiguous. What I meant was: Whats the actual code to change the pictureBox? – Varmitharen Feb 04 '11 at 19:59
  • You should be able to use the PictureBox.Image property and set it to a new Bitmap or whatever. – KeithS Feb 04 '11 at 22:41
0
this.MyCheckbox.CheckedChanged += new EventHandler(MyCheckbox_CheckedChanged);

private void MyCheckbox_CheckedChanged(object sender, EventArgs e)
{
    this.MyPictureBox.Image = // Your image here
}
tbridge
  • 1,754
  • 1
  • 18
  • 35