【问题标题】:Set location of mouse设置鼠标位置
【发布时间】:2015-08-01 09:19:32
【问题描述】:

我无法纠正我的错误:/

if (Cursor.Position = new Point(x, y)

x,y 有错误,例如我想改成50,99

【问题讨论】:

  • if (Cursor.Position = new Point(x, y)if 你需要使用 == 。设置它是可以的,假设 x 和 y 设置正确,根据需要,当然,没有if..
  • 你忘记完成')' if (Cursor.Position = new Point(x, y))
  • 你必须在 Point(x, y) 之后再添加一个括号来关闭 if 条件。
  • 只是错别字,你应该删除问题..
  • 我点击位置,它什么都不做嗯,命中一个点的机会真的很小!试试:if ( new Rectangle(211, 480, 6,6).Contains(Cursor.Position))...

标签: c# position cursor


【解决方案1】:

首先你应该触发 mouseClick 事件。很简单:

this.MouseClick += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseClick);

那么你应该处理这个事件。假设你想要的位置是 (x,y)=(100,100):

private void Form1_MouseClick(object sender, MouseEventArgs e)
    {
        int xDesired = 100;
        int yDesired = 100;
        if (e.X == xDesired && e.Y == yDesired)
            MessageBox.Show("Certain point clicked.");
    }

【讨论】:

  • 首先,你能告诉我你到底想做什么吗?抱歉耽搁了。
  • 我希望当我们点击表格的某个区域时,我希望有一条消息出现,谢谢;)
  • 1.你怎么能保证你点击了某个位置?
  • 你知道c#如何处理事件吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-03-14
  • 2012-12-13
相关资源
最近更新 更多