Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

How to Change Mouse Cursor in VB.Net Applications

Author: DevASP
Download Source Code : 334_Mouse_cursors.zip

In this simple Article You will Learn that how you can change Mouse Cursor in a VB.Net application and make your application user friendly and interactive.

To do this there are some simple steps. First create a Window application then Create Six Buttons in this application having text Press. Now first We will set the cursor of the main form Form1 open its properties and set its cursor property cross. This property set cursor of your main Form. Now we will set Cursor of buttons with code. So for this purpose write these commands in form1 load event:

 

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

 

        Button1.Cursor = System.Windows.Forms.Cursors.WaitCursor

        Button2.Cursor = System.Windows.Forms.Cursors.AppStarting

        Button3.Cursor = System.Windows.Forms.Cursors.Hand

        Button4.Cursor = System.Windows.Forms.Cursors.Help

        Button5.Cursor = System.Windows.Forms.Cursors.IBeam

        Button6.Cursor = System.Windows.Forms.Cursors.NoMove2D

 

End Sub

This is for initial setup.

Now write code for each button click event.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

 

        Button1.Cursor = System.Windows.Forms.Cursors.No

 

End Sub

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

 

        Button2.Cursor = System.Windows.Forms.Cursors.PanNE

 

End Sub

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

 

        Button3.Cursor = System.Windows.Forms.Cursors.PanEast

 

End Sub

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

 

       Button4.Cursor = System.Windows.Forms.Cursors.SizeWE

 

End Sub

 

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click

 

        Button5.Cursor = System.Windows.Forms.Cursors.SizeNESW

 

End Sub

 

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

 

        Button6.Cursor = System.Windows.Forms.Cursors.HSplit

 

End Sub

 

End Class

 

Now when you click on the button it change its initial cursor to new one. This is very simple code for the beginners and after this they have no problem in case of cursors.

Article Comments
Hello, i have a question, can u change the image on the mouse cursor/pointer to a custom image?

Posted on 6/5/2007 10:21:54 PM by Heem

Yes with

Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
Me.Cursor = New Cursor("C:\Windows\Cursors\pen_m.cur")
End Sub
End Class

Posted on 12/4/2009 5:34:28 AM by Berger

I do this and it gives me that the .cur error is invalid

Posted on 12/1/2010 11:08:02 AM by Connor

Hi,

Download its code files and check all required system APIs required to do it.

Thnaks

Posted on 12/2/2010 11:23:34 AM by Zunair

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< How to Work With Menus in VB.net.

Disclaimer - Privacy
© 2002-2017 DevASP.net