0

I'm working on a WinForms app and need to record the location of MouseDown and MouseUp events. My problem is that the events happen on different controls so their coordinate systems don't match (all I need is the amount of drag). I tried adding in the location of the sending control but it still doesn't work right.

Is there a simple solution to this?

BCS
  • 75,627
  • 68
  • 187
  • 294

1 Answers1

4

You may use PointToScreen method for the purpose. Your mouse handler code could then look like this:

private void Form1_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
{   
    Control control = (Control) sender;
    Point pointOnScreen = control.PointToScreen(new Point(e.X, e.Y));

    ...
}
G S
  • 35,511
  • 22
  • 84
  • 118
  • That seems to do what I want, but I still have problems... in the rest of the code :b – BCS Jun 29 '09 at 16:08