AuthorQuestion
Adding a mouse click eventhandler to a PictureBox
Posted on: 19 Nov 2012
Hi there

I have a picturebox control and upon clicking it another PictureBox appears at a specific location. I.o.w it wasnt added from the toolbox.

PictureBox picOneFaceUpA = new PictureBox();
picOneFaceUpA.Location = new Point(42, 202);
picOneFaceUpA.Width = 90;
picOneFaceUpA.Height = 120;
picOneFaceUpA.Image = Image.FromFile("../../Resources/" + picFaceUpToBeMoved[0] + ".png");
Controls.Add(picOneFaceUpA);
picOneFaceUpA.BringToFront();

How would I add a MouseClick eventhandler to this control?

Thanks


[ + ]
AuthorReply
Vulpes
  • 3
  • 0
Re: Adding a mouse click eventhandler to a PictureBox
Posted on: 19 Nov 2012  
Add this line to your code:

   picOneFaceUpA.MouseClick += picOneFaceUpA_MouseClick;

and then add this handler to your form:

   private void picOneFaceUpA_MouseClick(Object sender, MouseEventArgs e)
   {
      // add code to make other PictureBox appear  
   }

Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts