我试图用IronPython实现这个例子。我使用以下方法成功捕获游标:
def MoveCursor(self):
#Set the Current cursor, move the cursor's Position,
#and set its clipping rectangle to the form.
if self.MouseLocked == False:
self.Cursor = System.Windows.Forms.Cursor(System.Windows.Forms.Cursor.Current.Handle)
System.Windows.Forms.Cursor.Position = System.Drawing.Point(self.Cursor.Position.X - 50, self.Cursor.Position.Y - 50)
System.Windows.Forms.Cursor.Clip = System.Drawing.Rectangle(self.Location, self.Size)
self.MouseLocked = True
elif self.MouseLocked == True:
self.Cursor = System.Windows.Forms.Cursor(System.Windows.Forms.Cursor.Current.Handle)
#System.Windows.Forms.Cursor.Position = System.Drawing.Point(self.Cursor.Position.X - 50, self.Cursor.Position.Y - 50)
System.Windows.Forms.Cursor.Clip = None
self.MouseLocked = False
我尝试使用类变量来切换捕获,但它不像我预期的那样工作。如何释放鼠标?我需要使用哪个方法或事件?
更新:我试着使用self.Cursor.Dispose(),但这只会让我的光标无形:D,有点好笑,不过不是我需要的。
,"释放;光标的剪切称为">清除"从技术方面来说,会产生更好的搜索结果。web上有许多其他的例子(这里有一个)在专门的c#中处理这个确切的问题,在ironpython中做同样的事情也没有什么不同。
当您查看文档时,第一句话隐含地回答了您的问题(强调我的):
下面的代码示例从当前光标句柄创建一个光标,改变其位置和剪切矩形.
要清除先前设置的位置和剪切矩形,您需要将Clip
属性设置为new,空Rectangle
:
Cursor.Clip = new Rectangle();
此有效地清除光标的位置和剪切矩形。您的特殊情况将把它放在elif
块中:
elif self.MouseLocked == True:
...
System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle()
...