如何在C#中清除Cursor.Clip并允许光标再次自由移动?

发布于 2024-08-13 02:01:55 字数 297 浏览 2 评论 0原文

我正在尝试将光标锁定到表单中,这是针对鼠标储物柜应用程序的,我正在尝试处置光标,以便在解锁时重置 Cursor.Clip

到目前为止我已经:

Cursor.Clip = new Rectangle(x +8, y +30, Size.Width -16, Size.Height -38);

效果很好。

但我不知道当他们解锁剪辑时如何清除剪辑。 我已经尝试过 Cursor.Dispose(); 但这不起作用。

有什么想法吗? 谢谢。

I am trying to lock the cursor into the form, this is for a mouse locker application, I am trying to dispose the cursor so it will reset the Cursor.Clip when they unlock it.

So far I have:

Cursor.Clip = new Rectangle(x +8, y +30, Size.Width -16, Size.Height -38);

That works fine.

But I cannot figure out how to clear the clip when they unlock it.
I have tried Cursor.Dispose(); But that doesn't work.

Any ideas?
Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

在梵高的星空下 2024-08-20 02:01:55

实际上,我们的想法是将其设置为一个新的矩形,

Cursor.Clip = new Rectangle();

无论情况如何,它都可以工作。

actually the idea is to just set it to a new rectangle

Cursor.Clip = new Rectangle();

It works regardless of the situation.

錯遇了你 2024-08-20 02:01:55

试试这个:当您的应用程序启动时,获取 Cursor.Clip 的值并将其保存为未剪辑的值。然后,当您想要重置剪辑时,请指定未剪辑的值。

更新在此页面中表示要取消剪辑VB.NET 中的光标,只需执行 Cursor.Clip=Nothing 即可。但这很奇怪,因为 Rectangle 是一个结构体,因此不能将其设置为 null。那么在 C# 中,也许它会是 Cursor.Clip=Rectangle.EmptyCursor.Clip=default(Rectangle)

Try this: when your application starts, get the value of Cursor.Clip and save it as the unclipped value. Then when you want to reset the clip, assign the unclipped value.

UPDATE: In this page it says that to unclip the cursor in VB.NET, it is enough to do Cursor.Clip=Nothing. But this is strange since Rectangle is a structure and thus it can't be set to null. So in C#, maybe it would be Cursor.Clip=Rectangle.Empty or Cursor.Clip=default(Rectangle)?

醉生梦死 2024-08-20 02:01:55

Clip 设置为包含屏幕尺寸的 Rectangle

Cursor.Clip = Screen.PrimaryScreen.Bounds;

当然,这不适用于双显示器设置,但您明白了。

Set Clip to a Rectangle that contains the screen's dimensions.

Cursor.Clip = Screen.PrimaryScreen.Bounds;

Of course, this won't work with dual monitor setups, but you get the idea.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文