I am developing a Windows C#, VS 2008 application. I have a MDI Container form to which I add a new form at runtime during the click of a button. When the child form is created I add to it at runtime a panel control and a picture box control to the panel.
I add mouse event handlers for mouse up, mouse down and mouse move for the picturebox. Mouse up and down work as expected, but mouse move event keeps firing continuously when the mouse is over the picturebox and not moving. I know the event is getting fired because inside the mouse move event i keep a counter variable and increment and update the value to a label every time the mousemove event is called.
Why does this happen? Code I am using is below.
Thanks
Form frm = new Form();
frm.Deactivate += new EventHandler(MDIChildDeactivate);
PictureBox pi = new PictureBox();
pi.Dock = DockStyle.Fill;
pi.MouseUp += new MouseEventHandler(ImageMouseUp);
pi.MouseDown += new MouseEventHandler(ImageMouseDown);
pi.MouseMove += new MouseEventHandler(ImageMouseMove);
pi.Paint += new PaintEventHandler(CanvasPaint);
pi.KeyDown += new KeyEventHandler(ImageKeyDown);
pi.KeyPress += new KeyPressEventHandler(ImageKeyPress);
/////////////////////////////////////////////////////////
pi.PreviewKeyDown += new PreviewKeyDownEventHandler(pi_PreviewKeyDown);
/////////////////////////////////////////////////////////
if (!IsTabbedMdi)
frm.ClientSize = size;
frm.AutoScroll = true;
pi.Name = ProjectFileName;
Panel pnl = new Panel();
pnl.Dock = DockStyle.None;
pnl.Size = WarpArt.Properties.Resources.GreyCheckerBoard.Size;
pi.Image = WarpArt.Properties.Resources.GreyCheckerBoard;
pnl.AutoScroll = true;
pnl.HorizontalScroll.Visible = true;
pnl.VerticalScroll.Visible = true;
pnl.AutoSizeMode = AutoSizeMode.GrowAndShrink;
pnl.Name = ProjectFileName;
pnl.Controls.Add(pi);
frm.Controls.Add(pnl);
frm.MdiParent = this;
frm.Show();
count++; lblCounter.Text = count.ToString();- over.drive