MouseEventArgs & DragEventArgs

115 views
Skip to first unread message

Ramon Lopes

unread,
Feb 4, 2009, 8:46:04 AM2/4/09
to DotNetDe...@googlegroups.com
Hello everybody,


I've faced some problems using DragEventArgs. The matter is just that  according to the library the X and Y properties of DragEventArgs return "coordinate of the mouse pointer, in screen coordinates." (http://msdn.microsoft.com/en-us/library/system.windows.forms.drageventargs_members.aspx).
I would like to get the coordinate of the mouse during the generating mouse event, like the MouseEventArgs.X property does.

Could someone help me?

Thanks!

--
Ramon Pereira Lopes

AstroDrabb

unread,
Feb 7, 2009, 9:41:09 AM2/7/09
to DotNetDe...@googlegroups.com

Do you want to get the mouse coordinates outside of your window? Or do you want
to convert the screen coordinates to client coordinates? If so, controls have
PointToScreen() and PointToClient() methods.

If the later, you can use:

[DllImport("user32.dll")]
static extern bool GetCursorPos(ref Point lpPoint);

Point defPnt = new Point();

// Call the function and pass the Point, defPnt
GetCursorPos(ref defPnt);

// Now after calling the function, defPnt contains the coordinates
which we can read
string x = defPnt.X.ToString();
string y = defPnt.Y.ToString();

Ramon Lopes

unread,
Feb 7, 2009, 11:09:28 AM2/7/09
to DotNetDe...@googlegroups.com
The PointToScreen() method worked pretty fine!!
Thanks!!!
--
Ramon Pereira Lopes
Reply all
Reply to author
Forward
0 new messages