how about animated cursor in vb2008?

Post your questions regarding programming in Visual Basic 6 in here.
14 posts Page 1 of 2
Contributors
User avatar
utilities
Member
Member
Posts: 45
Joined: Wed Oct 21, 2009 1:23 pm

i put a cursor in my resources and i want to use it in my project
but i don't know how i can use it inside my form please teach me..
because i want to show my custom cursor in other computer without installing a my cursor.
tnx
sorry for my english
=====================================================================================
how about animated cursor.????
Last edited by utilities on Wed Oct 28, 2009 5:49 am, edited 1 time in total.
Image
Image
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Re: custom cursor in vb2008
CodenStuff
Hello,

First make sure your cursor is a *.cur file and then in its "Build Action" propertie choose "Embedded Resource".

Then add this code to the "Form_Load" event:
Code: Select all
 Me.Cursor = New Cursor(Me.GetType(), "YourCursorName.cur")
Happy coding! cooll;
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
utilities
Member
Member
Posts: 45
Joined: Wed Oct 21, 2009 1:23 pm

Re: custom cursor in vb2008
utilities
thanks for that code..
but how to put animated cursor???
Image
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Re: custom cursor in vb2008
Nery
Use a timer to do that.
Make a timer with interval 1 or something, upload the various cursor images, and each time the timer ticks it changes the cursor to the next image.
User avatar
utilities
Member
Member
Posts: 45
Joined: Wed Oct 21, 2009 1:23 pm

nery please give me a sample code tnx
Image
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Just a simple way:
You have a timer with... 1000 interval for example.
On the timer tick propertie you'll have to put something like this:
Code: Select all
If Cursor = cursor 1 then
Cursor = cursor 2
Elseif cursor = cursor 2 then
Cursor = cursor 3
Elseif cursor = cursor 3 then
Cursor = cursor 1
Cursor 1, 2 and 3 are the various cursor images (A Animated cursor is like a gIF, it has many "frames")
User avatar
utilities
Member
Member
Posts: 45
Joined: Wed Oct 21, 2009 1:23 pm

thx for that nery but i have a question
Why my cursor I put in my form is turning to black???
This is the code I put
Me.Cursor = New Cursor(Me.GetType(), "YourCursorName.cur")

is there way to put HD cursor using that code or using
other code.
Image
Image
User avatar
Nery
Co-Admin Moderator
Co-Admin Moderator
Posts: 1117
Joined: Mon Sep 07, 2009 8:11 pm

Mate, "YourCursorName.cur" must be replaced with your Cursor's image name... like "Cursor.cur"
User avatar
CodenStuff
Site Admin
Site Admin
Posts: 4389
Joined: Tue Aug 04, 2009 1:47 am

Hello,

Add these imports to your project:
Code: Select all
Imports System.Runtime.InteropServices
Imports System.Reflection
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Then underneath "Public Class Form.." add this code:
Code: Select all
 <DllImport("user32.dll")> _
    Public Shared Function LoadCursorFromFile(ByVal filename As String) As IntPtr
    End Function
Then in the "Form_Load" event use this:
Code: Select all
 Dim CustomCursor As New Cursor(Cursor.Current.Handle)
        Dim colorcursorhandle As IntPtr = LoadCursorFromFile("C:\YourCursorName.cur")
        CustomCursor.[GetType]().InvokeMember("handle", BindingFlags.[Public] Or BindingFlags.NonPublic Or BindingFlags.Instance Or BindingFlags.SetField, Nothing, CustomCursor, New Object() {colorcursorhandle})
        Me.Cursor = CustomCursor
Then replace the code "C:\YourCursorName.cur" with the location and name of your cursor.

That works.
Welcome to CodenStuff.com Learn Code, Love Code. Thank you for being a member of the community.
User avatar
Doctorfrost
Dedicated Member
Dedicated Member
Posts: 53
Joined: Sun Oct 04, 2009 4:44 am

There is a function in some properties called cursor. You can adjust its picture and animations in there.
If you want another object to react to the cursor then you can do so by using the mousehover feature.

Hope this helps! :)

Sincerely, Doctorfrost
14 posts Page 1 of 2
Return to “General coding help”