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
To move the image, click the move button, click on the image, keep hold the clicked mouse button and drag.
Explanation: Mouse, keyboard, joystick control works when the user clicks it.
Just add an event handler using the +=
operator:
picOneFaceUpA.MouseClick += new MouseEventHandler(your_event_handler);
Or:
picOneFaceUpA.MouseClick += new MouseEventHandler((o, a) => code here);
If you type picOneFaceUpA.Click +=
then hit tab, it will autocomplete for you and implement the event handler:
private void button2_Click(object sender, EventArgs e)
{
PictureBox picOneFaceUpA= new PictureBox();
picOneFaceUpA.Click += new EventHandler(picOneFaceUpA_Click);
}
void picOneFaceUpA_Click(object sender, EventArgs e)
{
throw new NotImplementedException();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With