0

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
  }
techno
  • 6,100
  • 16
  • 86
  • 192
  • "...It does not seem to work..." - this information is not really helpful. It does not say what exactly did not work, i.e. did you get any error messages anywhere, did you try to debug the issue to make sure that it actually does the intended thing. – jazb Dec 18 '18 at 06:51
  • 1
    What makes the control move? By default it wont move, thus your code allows and makes it move. What about dispatching an event from there? – ZorgoZ Dec 18 '18 at 06:57
  • @JohnB Please see update. – techno Dec 18 '18 at 06:58
  • OnMouseMove is raised when the Mouse Pointer move inside a Control's bounds. This allows to move the Control, by updating the Control's position using the relative `e.Location` values. Since this Control movement is constrained by the *Container's* bounds, you can calculate the movents using [something like this](https://stackoverflow.com/questions/53316286/dont-move-the-labels-outside-a-picturebox?answertab=active#tab-top) (already mentioned elsewhere :). You custom control should update and store its new position, so the main procedure can retrieve this reference when needed. – Jimi Dec 18 '18 at 10:10
  • @ZorgoZ This is the control i use https://stackoverflow.com/a/53774101/848968 – techno Dec 18 '18 at 10:58

1 Answers1

2

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.

Reza Aghaei
  • 120,393
  • 18
  • 203
  • 398
Himanshu Mange
  • 104
  • 1
  • 10