如何转换屏幕坐标,形成相对坐标(的WinForms)? [英] How to convert screen coordinates to form relative coordinates (winforms)?
本文介绍了如何转换屏幕坐标,形成相对坐标(的WinForms)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下的功能(这是不正确的):
I have the following function (that is incorrect):
private void TreeView_DragDrop(object sender, DragEventArgs e)
{
TreeNode CurrentNode =
TreeView.GetNodeAt(e.X - this.Left - NotesView.Left,
e.Y - this.Top - NotesView.Top);
// [snip]...
}
但是,这是不正确因为它没有考虑到形式的装饰......我敢肯定,必须有一个更好的办法做的比硬编码它这个其他(which'll是错误的,无论如何,这取决于几件事情,如Vista的XP VS 。在Win2k VS),但我不能找到它。
But this is incorrect because it doesn't take into account the forms decorations... I'm sure there has to be a better way to do this other than hard coding it (which'll be wrong anyway, depending on several things such as Vista vs XP vs Win2k), but I can't find it.
推荐答案
您可以使用:
Point clientPoint = TreeView.PointToClient( new Point( e.X, e.Y ) );
要获得相对坐标。
这篇关于如何转换屏幕坐标,形成相对坐标(的WinForms)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文