views:

98

answers:

1

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?

+4  A: 

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));

    ...
}
Frederick
That seems to do what I want, but I still have problems... in the rest of the code :b
BCS
What are those problems?
Frederick