移动光标位置? [英] Moving cursor position?

查看:53
本文介绍了移动光标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我正在 linux 主机上运行的 KVM 虚拟机上运行 XP -但这不会影响该程序的运行方式./p>

我还尝试了各种公告板建议的其他方法,但是它们都具有相同的效果.

公开课表格1私有子Form1_Load(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理Me.LoadSystem.Windows.Forms.Cursor.Position =新点(200,200)结束子结束班

谢谢您的评论.

 < Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()>_局部类表格1继承Windows.Forms.Form'继承System.Windows.Forms.Form'表单替代项用于清理组件列表.< System.Diagnostics.DebuggerNonUserCode()>_受保护的重写子Dispose(ByVal以布尔方式进行处置)如果处置AndAlso组件不算什么,那么components.Dispose()万一MyBase.Dispose(处理)结束子'Windows窗体设计器需要私有组件为System.ComponentModel.IContainer注意:Windows窗体设计器需要执行以下步骤'可以使用Windows窗体设计器进行修改.'请勿使用代码编辑器对其进行修改.< System.Diagnostics.DebuggerStepThrough()>_私有子InitializeComponent()Me.SuspendLayout()'''Form1'Me.AutoScaleDimensions =新的System.Drawing.SizeF(6.0 !, 13.0!)Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.FontMe.ClientSize =新的System.Drawing.Size(292,266)Me.Name ="Form1"Me.Text ="Form1"Me.ResumeLayout(False)结束子末级公开课表格1私有子Form1_Load(ByVal发送者作为对象,ByVal e作为System.EventArgs)处理Me.LoadDim abc作为新点abc.Offset(200,200)Cursor.Position = PointToScreen(abc)结束子末级 

上面的局部类是由集成开发环境生成的.最后一部分仅包含您建议的代码.所以我在任何事情上都没有做任何事情鼠标移动"事件.但是,在过去的测试中,我为on Mouse Move做了一个Protected Override Sub,我的代码将在调试模式下逐步通过此Sub.当我移动光标时.这背后的想法是,如果我在基类中重写了子类,则可以防止它在基类中做任何事情用鼠标移动(如将光标移回其原始位置).但是我不确定我的替代类是否阻止了这种情况或可能是通过基类中的另一种方法将光标移回了其原始位置-我看不到.

是否有可能能够调试并进入属于基类的代码-这样,我可以确切地看到发生了什么.目前,当我走进调试时,它仅显示我的类中的方法,而不显示基类中的方法.

解决方案

是的,我在Windows XP 32位本机上尝试过-没有虚拟机,cursor.position = new point(200,200)可以按预期工作.因此问题必须出在我的虚拟机设置上.我在Virtual Box和KVM上都尝试过,但都不能正确处理光标位置命令.

With the below code, I want to shift the cursor on the screen to the point (200,200) which works fine, but when I move the mouse (with my hand) the cursor immediately returns to its original location. What am I doing wrong?

I am running XP on a KVM virtual machine running on a linux host - not that this should effect how this program runs.

I have also tried other methods suggested by various bulletin boards but they all get the same effect.

Public Class Form1 Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load System.Windows.Forms.Cursor.Position = New Point(200, 200) End Sub End Class

Thank-you for your comments.

<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

The partial class above was generated by the integrated development environment. The last section only contains your suggested code. So I have done nothing with regard to any "Mouse Move" event. However, in a past test I made a Protected Override Sub for the the on Mouse Move and my code would step through this sub in debug mode when I moved the cursor. The thinking behind this that if I override the sub in the base class - I could prevent it from doing anything in the base class with mouse move ( . such as moving the cursor back to its original location ) . I am not sure however whether my override class prevented this or perhaps the cursor is being moved back to its original location by another method in the base class - which I can not see.

Is it possible to be able to debug and step into code that is part of the base class - this way I could see exactly what is going on. Currently when I step into debugging, it only shows my methods in my classes not methods in the base class.

解决方案

Yes I tried on windows xp 32-bit native - no virtual machines and the cursor.position = new point (200,200) works as expected. So the problem must be with my virtual machine set up. I tried it on both Virtual Box and KVM and both did not handle the cursor position command properly.

这篇关于移动光标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆