C#中的光标坐标跟踪 [英] Cursor Coordinates Tracking in C#

查看:148
本文介绍了C#中的光标坐标跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我想制作一种在屏幕上任意位置跟踪鼠标坐标的方法。

I would like to make a method to track the mouse's coordinates anywhere on screen.

理想的设计是用文本框创建一个简单的表单,两个都是空白的。

The ideal design is to make a simple form with a textbox, both blank.

我使用System.Drawing.Point和使用System的Control.MousePosition属性在Cursor.Position上读了一下。 Windows.Forms的。但是在这两种情况下,给出的示例都很简单,与我想要执行的简单任务不相符。

I read a bit on the Cursor.Position using the System.Drawing.Point and also on the Control.MousePosition property using System.Windows.Forms. However in both cases, the example given is simple too out of line with the simple task I want to perform.

当我运行程序时,我希望文本框能够动态地更改每个指针新位置的框架。

When I run the program, I'd like the textbox to dynamically change every frame for the pointer's new position.

private void TrackCursor()

        {

private void TrackCursor()
        {

          }

我得到了这么远,但我无法更改文本框。我错过了什么?

I got this far but I cannot get the textbox to change. What am I missing?

推荐答案

我尝试了你的代码,但我有一个奇怪的工作要让它运行:

I tried your code however i got a quirk to work out to make it run:

public Form1()

        {

            InitializeComponent();

        }

public Form1()
        {
            InitializeComponent();
        }

突然"在当前上下文中不存在"。我不知道为什么会这样。

Suddenly "does not exist in the current context". I am not sure why this is.

我设法加载了互操作,所以没有其他错误。

I managed to load the interops so no other errors.


这篇关于C#中的光标坐标跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆