Click here to Skip to main content
15,860,844 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Use Icons for cursors, not ".CUR"

Rate me:
Please Sign up or sign in to vote.
5.00/5 (18 votes)
16 Mar 2010CPOL2 min read 82.6K   11   12
Many developers use ".cur" cursor files. Using them myself in Visual Studio 2008, they are not the easiest things to work with for many reasons.They are not easy to create without expensive software. (unless you are using the editor within Visual Studio)They cannot easily be ported in the...
Many developers use ".cur" cursor files. Using them myself in Visual Studio 2008, they are not the easiest things to work with for many reasons.


  1. They are not easy to create without expensive software. (unless you are using the editor within Visual Studio)
  2. They cannot easily be ported in the express editions of Visual Studio, which leaves most hobbyist developers out. (You must first import them as a resource or
  3. Sometimes they can be hard to even link into your code.





To get around using ".cur" files for your cursors, We will be using Icons. With Icons you can still use transparency and create shadows.


You may use either Visual Studio or the VB.NET Express edition(which is free for use):


http://www.microsoft.com/express/Downloads/#2008-Visual-Basic




Step 1:


Create a new VB.net project



note : I am using VB Express






This menu shows the generic Windows cursors

You can access this menu by code as shown.
Step 2:


Getting it ready




To create cursors from icons, you must obviously have an icon to do so with. There are many programs you can use the many Devs or hobbyists might have. I am going to use GIMP: http://www.gimp.org/downloads/ {New window}


GIMP is a free photo manipulator similar to Photoshop, but it can also be used for image creation.


If you do not have an image to use or create, right-click and save this one :




Step 3:

Making it work



Import the Icon as a resource.
Choose the option "Add existing file"




Make sure that the Access Modifier is set to "Public"




Simply put the code that lets the icon get a handle so that it might be used as a cursor.
VB
Me.Cursor = New Cursor(My.Resources.Form1.cursor.Handle)





The finished project

The only foreseeable problem with the use of an icon as a cursor is that the location of the pointer will be in the center of the cursor. This can be easily overcome by making the image larger, while keeping the image in the lower-right corner. As shown:

I also added a shadow to the cursor.







Thank you for reading my Tips 'n Tricks post. I hope to see you in later tips or articles. :cool:


EDIT: I added a dotted line to the last cursor illustrating where the cursors hotspot will be. I also added a shadow to that cursor.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Student Student
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralReason for my vote of 5 Very Simple and Handy Pin
ArghavanMostafa13-Jun-11 8:08
ArghavanMostafa13-Jun-11 8:08 
Reason for my vote of 5
Very Simple and Handy

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.