A question about object sender
-
I use a PictureBox array in my project;
public PictureBox[] illustration; illustration = new PictureBox[10]; ... myInkPicture[IntSelectPage].illustration[i] = new System.Windows.Forms.PictureBox(); ... myInkPicture[IntSelectPage].illustration[i].MouseDown += new System.Windows.Forms.MouseEventHandler(myInkPicture[IntSelectPage].illustration_MouseDown);
the ten PictureBoxes use the same MouseDown event handler,public void illustration_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { pictureBox1.Capture = true; startMoveLocation = new Point(e.X, e.Y); }
I want thepictureBox1
to be theillustration[i]
, How can I typecast the object sender to be the illustration[i] PictureBox...?? -
I use a PictureBox array in my project;
public PictureBox[] illustration; illustration = new PictureBox[10]; ... myInkPicture[IntSelectPage].illustration[i] = new System.Windows.Forms.PictureBox(); ... myInkPicture[IntSelectPage].illustration[i].MouseDown += new System.Windows.Forms.MouseEventHandler(myInkPicture[IntSelectPage].illustration_MouseDown);
the ten PictureBoxes use the same MouseDown event handler,public void illustration_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { pictureBox1.Capture = true; startMoveLocation = new Point(e.X, e.Y); }
I want thepictureBox1
to be theillustration[i]
, How can I typecast the object sender to be the illustration[i] PictureBox...??Hi, In your mouse down event handler sender is the object that caused the event. In this case it will be whatever picturebox the mouse went down over. I believe that by casting sender to a picturebox you will have the picturebox that the mouse went down on aka illustration[i]. Do this with ((PictureBox)sender).Capture = true; Karl
-
Hi, In your mouse down event handler sender is the object that caused the event. In this case it will be whatever picturebox the mouse went down over. I believe that by casting sender to a picturebox you will have the picturebox that the mouse went down on aka illustration[i]. Do this with ((PictureBox)sender).Capture = true; Karl
I have tried and it really works !! Thank you very much :-D