Move cursor position?

Using the code below, I want to move the cursor on the screen to a point (200,200), which works fine, but when I move the mouse (by 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, and not that this should affect the execution of this program.

I also tried other methods offered by different bulletin boards, but they all get the same effect.

Public class Form1 Private Sub Form1_Load (ByVal sender as an object, ByVal e As System.EventArgs) processes Me.Load System.Windows.Forms.Cursor.Position = New point (200, 200) End Sub End class

Thanks 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 created by the integrated development environment. The last section contains only the code you offer. So I did nothing with the Mouse Movement event. However, in the last test I made a protected overridden Sub to move the mouse over the mouse, and my code would step over this sub in debug mode when I moved the cursor. The idea is that if I redefine sub in the base class, I could prevent it from doing anything in the base class with the mouse moving (for example, moving the cursor to its original position). However, I'm not sure if my override class prevented this, or perhaps the cursor returns to its original location in a different way in the base class, which I don't see.

Is it possible to be able to debug and embed code that is part of the base class - so I can see exactly what is happening. Currently, when I'm debugging, it only shows my methods in my classes, not methods in the base class.

+4
Mar 10 '14 at 7:33
source share
2 answers

Yes, I tried 32-bit native on windows xp - there are no virtual machines, and cursor.position = new point (200,200) works as expected. Therefore, the problem should be related to the configuration of my virtual machine. I tried this on both Virtual Box and KVM, and both of them didn’t execute the cursor position command correctly.

+2
Mar 13 '14 at 12:56
source share

Exaplanation

We will take any variable and declare it as New Point . The next step we will do is locate the variable abc using the offset control. Finally, move the mouse to abc.

Code and example

 abc.Offset(200, 200) Cursor.Position = PointToScreen(abc) 

I hope this works efficiently!

-one
Mar 10 '14 at 7:46
source share



All Articles