changing mousepointer over command buttons

Posted on 2000-03-31
Last Modified: 2012-06-21
  How do I make the mousepointer change to a finger when the mouse moves over a command button in VB?  I need to be able to do this for buttons that I currently have on forms and buttons that will be created and loaded during the application's runtime.
Thanks for your help,
Question by:DoughBoy
  • 3
  • 2
  • 2
  • +1
LVL 32

Expert Comment

ID: 2675446
Create a Cursor in the shape you like then store it in a Resource file.  Assign it to the button like this:

Private Sub Form_Load()
    Command1.MousePointer = 99 'custom
    'Create a custom cursor and save it in a resource file
    'The ID of the cursor is the first arg to LoadResPicture
    Command1.MouseIcon = LoadResPicture(101, vbResCursor)
End Sub

Expert Comment

ID: 2675583
You can set the MouseIcon property of the command button to the picture you want at design time and that's all you have to do. The cursor will be saved in the form's resource file (.frx)automatically.

Erick37- Does this method use more resources?

Expert Comment

ID: 2675715
Here it goes my friend.

First create a control array. Set these at designtime for the 0 th index object as:

MouseIcon = vbHand (Choose from cursors)

Then in form load code this

For i = 1 To command1.Count - 1
    Command1(i).MouseIcon = Command1(0).MouseIcon
    Command1(i).MousePointer = Command1(0).MousePointer

If u add any other control also set the same again to that control. Now it should work fine. <Smile> Get back to me

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.


Accepted Solution

AshokKumar earned 100 total points
ID: 2675722
Oops. i clicked comment instead of answer. The above code is your solution friend. <Smile>
LVL 32

Expert Comment

ID: 2676025
>>>MouseIcon = vbHand ?

What is this?  Shoudn't this point to an ico file?

If you store a custom cursor in the form (frx), then it will take more resources than by using a resource file if you have more than one form with custom cursors.  It is good practice to use resource files to store cursors, icons and strings.

Expert Comment

ID: 2676171
Erick37 - Thanks, I was wondering about that.

See 'ya,

Author Comment

ID: 2678740
Thanks very much!
It works very well.
Best Regards



Expert Comment

ID: 2678765
MouseIcon=VbHand  In the brackets i ahve mentioned to select from available cursors or icons. I thought it would be simpler if i say like that. Sorry if i am not clear.

Thanks guy. <Smile and Wink>

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question