Search code examples
c#.netwinformssystem.drawing

Detect if the Control was Moved inside the picturebox


I have added a custom control to picturebox.I need to check if the control has been moved. Currently i use pictureboxmousemove event,which obviously has some issues. I have tried adding the mousemouse event to the control as well.It does not seem to work.How can i sort this issue?

 pictureBox5.Controls.Clear();
 var c = new FrameControl();
 c.Size = obj.Size;
 c.Location = obj.Location;
 pictureBox5.Controls.Add(c);     

UPDATE: I have tried overriding the mousemove event of the Frame Control but it does not seem to work.

protected override void OnMouseMove(MouseEventArgs e)
  {
 base.OnMouseMove(e);
//Debugger does not hit breakpoint
  }

Solution

  • MouseMove event is called when you hover mouse on the control. If you want to check whether control is moved then please use LocationChanged event.