Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Hi Friends!

I need to change the image in a picturebox each time I double click.

The following code can handle one single "MouseDoubleClick" event.
private void BtnPicBoxDCS_OnMouseDoubleClick(object sender, EventArgs e)
        {
            BtnPicBoxDCS.Image = global::CvSharp.Properties.Resources._035;
        }


the corresponding handler(in Form1.Designer.cs)
this.BtnPicBoxDCS.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.BtnPicBoxDCS_OnMouseDoubleClick);



But, what I want to do is each time I double click the "BtnPicBoxDCS" it loads a different image(basically there are two images that has to alternate on each double click).

Please help!
Thanks!
Posted
Updated 30-Apr-11 3:01am
v2
Comments
Kim Togo 30-Apr-11 9:05am    
Do you what to swap between 2 images ?
AmarjeetAlien 30-Apr-11 9:29am    
Yes....but on double click.

1 solution

You can use a simple bool value.

bool image1 = true;

private void BtnPicBoxDCS_OnMouseDoubleClick(object sender, EventArgs e)
{
  BtnPicBoxDCS.Image = this.image1 ? global::CvSharp.Properties.Resources._035 : global::CvSharp.Properties.Resources._038;

  this.image1 = this.image1 ? false : true;
}
 
Share this answer
 
Comments
AmarjeetAlien 30-Apr-11 10:27am    
Thanks a lot Kim!
It worked happily.
Kim Togo 30-Apr-11 16:09pm    
You are welcome.
Nish Nishant 30-Apr-11 12:28pm    
My vote of 5, good answer.
Kim Togo 30-Apr-11 16:13pm    
Thanks Nishant

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