.net - 移动光标位置?

标签 .net vb.net

使用下面的代码,我想将屏幕上的光标移动到可以正常工作的点 (200,200),但是当我移动鼠标(用手)时,光标立即返回到其原始位置。我究竟做错了什么?

我在运行 XPKVM运行在 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

上面的部分类是由集成开发环境生成的。最后一部分仅包含您建议的代码。所以我没有对任何
“鼠标移动”事件。但是,在过去的测试中,我为 on Mouse Move 制作了一个 Protected Override Sub,我的代码将在 Debug模式下单步执行此 sub
当我移动光标时。这背后的想法是,如果我覆盖基类中的 sub - 我可以阻止它在基类中做任何事情
用鼠标移动(例如将光标移回原来的位置)。但是我不确定我的覆盖类是否阻止了这个
或者可能是基类中的另一个方法将光标移回其原始位置 - 我看不到。

是否有可能能够调试并进入作为基类一部分的代码 - 这样我就可以准确地看到发生了什么。目前当我进入
调试,它只显示我的类中的方法而不是基类中的方法。

最佳答案

是的,我在 windows xp 32 位 native 上试过 - 没有虚拟机,并且 cursor.position = new point (200,200) 按预期工作。所以问题一定出在我的虚拟机设置上。我在 Virtual Box 和 KVM 上都尝试过,但都没有正确处理光标位置命令。

关于.net - 移动光标位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22294429/

相关文章:

.net - ByRef 与 ByVal 会产生错误吗?

c# - 使用 Generics C# 3.5 时出现编译错误

c# - 谁能向我解释为什么在 lambda 表达式中使用迭代变量是个坏主意

vb.net - ActiveX 控件 '8856f961-340a-11d0-a96b-00c04fd705a2' 无法实例化,因为当前线程不在单线程单元中

c# - IBackgroundTask 类中的任务类型

c# - 使用 typeof 时与依赖注入(inject)有什么区别?

vb.net - VB.NET错误-使用结果时,在运行时可能会出现Null引用异常

c# - 将 c# 转换为 vb.net。如何处理比较运算符和接口(interface)?

c# - 是否存在 Application.Exit() 不引发 FormClosing 事件的情况?

vb.net - Ms Word Addin 中的isolatedStorageException