使用下面的代码,我想将屏幕上的光标移动到点(200,200),效果很好,但是当我(用手)移动鼠标时,光标立即返回到其原始位置。我究竟做错了什么?
我在跑步XP
on a KVM
虚拟机运行在linux
主机 - 这并不影响该程序的运行方式。
我还尝试了各种公告板建议的其他方法,但它们都得到了相同的效果。
公开课表格1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) 处理 Me.Load
System.Windows.Forms.Cursor.Position = 新点(200, 200)
结束子
结束课程
谢谢您的意见。
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits Windows.Forms.Form
' Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.SuspendLayout()
'
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
End Class
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim abc As New Point
abc.Offset(200, 200)
Cursor.Position = PointToScreen(abc)
End Sub
End Class
上面的部分类是由集成开发环境生成的。最后一部分仅包含您建议的代码。所以我没有做任何事
“鼠标移动”事件。然而,在过去的测试中,我为鼠标移动创建了一个受保护的覆盖子,我的代码将在调试模式下单步执行此子
当我移动光标时。这背后的想法是,如果我重写基类中的 sub - 我可以阻止它在基类中执行任何操作
用鼠标移动(例如将光标移回其原始位置)。但我不确定我的覆盖类是否阻止了这种情况
或者也许光标被基类中的另一个方法移回其原始位置 - 我看不到。
是否有可能能够调试并单步执行属于基类一部分的代码 - 这样我就可以准确地看到正在发生的事情。目前当我踏入
调试时,它只显示我的类中的方法,而不显示基类中的方法。