如何在C#中清除Cursor.Clip并允许光标再次自由移动?
我正在尝试将光标锁定到表单中,这是针对鼠标储物柜应用程序的,我正在尝试处置光标,以便在解锁时重置 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
实际上,我们的想法是将其设置为一个新的矩形,
无论情况如何,它都可以工作。
actually the idea is to just set it to a new rectangle
It works regardless of the situation.
试试这个:当您的应用程序启动时,获取 Cursor.Clip 的值并将其保存为未剪辑的值。然后,当您想要重置剪辑时,请指定未剪辑的值。
更新:在此页面中表示要取消剪辑VB.NET 中的光标,只需执行
Cursor.Clip=Nothing
即可。但这很奇怪,因为 Rectangle 是一个结构体,因此不能将其设置为 null。那么在 C# 中,也许它会是Cursor.Clip=Rectangle.Empty
或Cursor.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 beCursor.Clip=Rectangle.Empty
orCursor.Clip=default(Rectangle)
?将
Clip
设置为包含屏幕尺寸的Rectangle
。当然,这不适用于双显示器设置,但您明白了。
Set
Clip
to aRectangle
that contains the screen's dimensions.Of course, this won't work with dual monitor setups, but you get the idea.