相对于应用程序的光标位置
我知道如何获得光标的位置:
int X = Cursor.Position.X; int Y = Cursor.Position.Y;
但这与屏幕有关。 我如何获得相对于我的表格的坐标?
使用Control.PointToClient
方法 。 假设this
指向有问题的表格:
var relativePoint = this.PointToClient(new Point(X, Y));
或者干脆:
var relativePoint = this.PointToClient(Cursor.Position);
我会像这样使用PointToClient
:
Point p = yourForm.PointToClient(Cursor.Position); //if calling it in yourForm class, just replace yourForm with this or simply remove it.
如何使用Control.PointToClient尝试这样: –
上述就是C#学习教程:相对于应用程序的光标位置分享的全部内容,如果对大家有所用处且需要了解更多关于C#学习教程,希望大家多多关注—计算机技术网(www.ctvol.com)!
public Form() { InitializeComponent(); panel = new System.Windows.Forms.Panel(); panel.Location = new System.Drawing.Point(90, 150); panel.Size = new System.Drawing.Size(200, 100); panel.Click += new System.EventHandler(this.panel_Click); this.Controls.Add(this.panel); } private void panel_Click(object sender, EventArgs e) { Point point = panel.PointToClient(Cursor.Position); MessageBox.Show(point.ToString()); }
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/cdevelopment/958963.html