Zippy.Toast
Data Ghost
2
MONTHS
2 2 MONTHS OF SERVICE
LEVEL 1
300 XP
Introduction:
Welcome to my tutorial on how to create a Mouse Position tool in Visual Basic. This is easy so I will also be explaining Threading.
Steps of Creation:
Step 1:
First we need to import System.Threading so we can use Threads. We also want to create a form with just a label, this will contain our mouse position.
Step 2:
Now we want to create and initiate a Thread on form load...
We also stop checking for illegal cross thread calls because if we don't, it will throw an error when trying to access the label1 control from a new thread because the control was created on the main thread.
Step 3:
Now we want to create our begin function which the new Thread starts on. We want it to update our label text with the mouse position so we put it in a constant loop.
Step 4:
Finally, we want to add in a 0.1 second sleep between each loop of updating our label so it doesn't overuse resources from our computer etc.
Project Complete!
Below is the full source code and download to the project files.
Download
Welcome to my tutorial on how to create a Mouse Position tool in Visual Basic. This is easy so I will also be explaining Threading.
Steps of Creation:
Step 1:
First we need to import System.Threading so we can use Threads. We also want to create a form with just a label, this will contain our mouse position.
- Imports System.Threading
Step 2:
Now we want to create and initiate a Thread on form load...
- CheckForIllegalCrossThreadCalls = False
- Dim
trd As
Thread = New
Thread(AddressOf begin)
- trd.isBackground = True
- trd.Start()
We also stop checking for illegal cross thread calls because if we don't, it will throw an error when trying to access the label1 control from a new thread because the control was created on the main thread.
Step 3:
Now we want to create our begin function which the new Thread starts on. We want it to update our label text with the mouse position so we put it in a constant loop.
- Private
Function
begin()
- Do
While
True
- Label1.Text = "X: "
& MousePosition.X & ", Y: "
& MousePosition.Y
- Loop
- End
Function
Step 4:
Finally, we want to add in a 0.1 second sleep between each loop of updating our label so it doesn't overuse resources from our computer etc.
- Thread.Sleep(100)
Project Complete!
Below is the full source code and download to the project files.
- Imports System.Threading
- Public
Class Form1
- Private
Sub
Form1_Load(sender As
Object
, e As
EventArgs) Handles MyBase.Load
- CheckForIllegalCrossThreadCalls = False
- Dim
trd As
Thread = New
Thread(AddressOf begin)
- trd.isBackground = True
- trd.Start()
- End
Sub
- Private
Function
begin()
- Do
While
True
- Label1.Text = "X: "
& MousePosition.X & ", Y: "
& MousePosition.Y
- Thread.Sleep(100)
- Loop
- End
Function
- End
Class
Download
You must upgrade your account or reply in the thread to view hidden text.