如何在c#windows应用程序中实现“第二个鼠标光标”?

时间:2021-05-26 19:54:46

I actually don't want it to be a "real" mouse cursor, i.e. no need for ability to click on buttons, select text etc. It should just look like a cursor (or kinda like it) and be able to move around the app's window (no need to go outside). It will be controlled by the computer, and the user should be able to use the mouse as usual during this time.

我实际上不希望它是一个“真正的”鼠标光标,即不需要能够点击按钮,选择文本等。它应该看起来像一个光标(或者有点像),并能够移动到应用程序的窗口(无需外出)。它将由计算机控制,用户应该能够在此期间照常使用鼠标。

What's a good way to do something like this? How do I make a floating entity that I can move around the window programmatically?

做这样的事情的好方法是什么?如何创建一个可以以编程方式在窗口中移动的浮动实体?

2 个解决方案

#1


If it is a forms application, just create a PictureBox, load a mouse cursor graphic that has a transparent background, and just move it around your form.

如果它是一个表单应用程序,只需创建一个PictureBox,加载一个具有透明背景的鼠标光标图形,然后只需在表单上移动它。

#2


If this is a WPF application, then you can do this: Put a Canvas object on your display. Add an image of a mouse cursor as a child of the canvas. Set the Canvas.Left and Canvas.Top properties on the image to move it around. Set the ZOrder of the image so that it appears above all of the other controls.

如果这是一个WPF应用程序,那么您可以这样做:在显示器上放置一个Canvas对象。添加鼠标光标的图像作为画布的子项。在图像上设置Canvas.Left和Canvas.Top属性以移动它。设置图像的ZOrder,使其显示在所有其他控件上方。

You don't say how the actions are to be determined. If it is according to a script, then there are ways WPF can handle the timing of the motion for you. Otherwise, you can just update the position by whatever means you want in response to a timer.

您没有说明如何确定行动。如果它是根据脚本,那么WPF可以为您处理动作的时间。否则,您可以通过任何方式更新位置以响应计时器。

Wait a minute. I just noticed this was posted ten months ago.

等一下。我刚刚注意到这是十个月前发布的。

So what did you end up doing? :)

那么你最终做了什么? :)

#1


If it is a forms application, just create a PictureBox, load a mouse cursor graphic that has a transparent background, and just move it around your form.

如果它是一个表单应用程序,只需创建一个PictureBox,加载一个具有透明背景的鼠标光标图形,然后只需在表单上移动它。

#2


If this is a WPF application, then you can do this: Put a Canvas object on your display. Add an image of a mouse cursor as a child of the canvas. Set the Canvas.Left and Canvas.Top properties on the image to move it around. Set the ZOrder of the image so that it appears above all of the other controls.

如果这是一个WPF应用程序,那么您可以这样做:在显示器上放置一个Canvas对象。添加鼠标光标的图像作为画布的子项。在图像上设置Canvas.Left和Canvas.Top属性以移动它。设置图像的ZOrder,使其显示在所有其他控件上方。

You don't say how the actions are to be determined. If it is according to a script, then there are ways WPF can handle the timing of the motion for you. Otherwise, you can just update the position by whatever means you want in response to a timer.

您没有说明如何确定行动。如果它是根据脚本,那么WPF可以为您处理动作的时间。否则,您可以通过任何方式更新位置以响应计时器。

Wait a minute. I just noticed this was posted ten months ago.

等一下。我刚刚注意到这是十个月前发布的。

So what did you end up doing? :)

那么你最终做了什么? :)