WinForms中的游标位置

时间:2014-03-24 23:09:11

标签: c# winforms position

我尝试将光标设置在窗体内的特定位置,当窗体最大化时可以正常但是当窗体大小改变时,光标位置在窗体之外

抱歉我的英文。

private void button1_Click(object sender, EventArgs e)
{
    int xp = 585;
    int yp = 330;
    Cursor.Position = PointToClient(new Point(xp, yp));
    Point mousep = PointToClient(Cursor.Position);
    tbX1.Text = mousep.X.ToString();
    tbY1.Text = mousep.Y.ToString();
}

1 个答案:

答案 0 :(得分:1)

如果变量xp和yp是窗口内的偏移量......

Cursor.Position = new Point(Location.X + xp, Location.Y + yp);