Results 1 to 11 of 11

Thread: [Resovled] Custom Cursor in .Net 2003

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Location
    St. Louis MO
    Posts
    129

    [Resovled] Custom Cursor in .Net 2003

    I've seen several posts regarding using custom cursors in .net, but they all seem to be for 2005. (I say that simply because the steps don't match up with my options)

    I have a usercontrol and two cur files I want to use from within it.
    Simply put - how?!

    Could someone post some .net 2003 code or something?

    thanks
    Last edited by Tony Martin; Dec 1st, 2006 at 10:13 AM. Reason: Resolution to problem.

  2. #2
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Custom Cursor in .Net 2003

    Here an example. Note that Cursor class doesn't suport animated cursors.
    VB Code:
    1. 'Create a new cursor from the file and assign it to the form
    2.         Dim cur As New Cursor("your .cur file path")
    3.         Me.Cursor = cur
    you change it back by
    VB Code:
    1. Me.Cursor = Cursors.Default
    2. cur.Dispose

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Location
    St. Louis MO
    Posts
    129

    Question Re: Custom Cursor in .Net 2003

    But if I add the cur files to my project (Right click, add item, cursor file), doesn't it become part of my project and therefore, "pathless"? - Like resource files used to be in VB6?

  4. #4
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: Custom Cursor in .Net 2003

    Quote Originally Posted by Tony Martin
    I've seen several posts regarding using custom cursors in .net, but they all seem to be for 2005. (I say that simply because the steps don't match up with my options)

    I have a usercontrol and two cur files I want to use from within it.
    Simply put - how?!

    Could someone post some .net 2003 code or something?

    thanks
    Hi,

    Here's a link about Custom Cursors with an example;

    http://msdn2.microsoft.com/en-us/lib...ms.cursor.aspx

    Hope it helps,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  5. #5
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Custom Cursor in .Net 2003

    Quote Originally Posted by Tony Martin
    But if I add the cur files to my project (Right click, add item, cursor file), doesn't it become part of my project and therefore, "pathless"? - Like resource files used to be in VB6?
    Honestly I don’t understand your question. First of all forget what you were doing in VB 6 because now you are using VB.Net and the concepts are different. “Cursor” constructor is overloaded; take a look in the image. I provided you the method so it is your responsibility to figure it out.
    Attached Images Attached Images  

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Location
    St. Louis MO
    Posts
    129

    Re: Custom Cursor in .Net 2003

    "Honestly I don’t understand your question." and "I provided you the method so it is your responsibility to figure it out."
    You often throw out "answers" and make crappy comments to things you don't understand?

    Sparrows link was most helpful and gave me the lead I needed. Thank you Sparrow.

    Here is how the code ended up:

    'Somewhere at the top....
    Dim curHandOpen As Cursor 'A cursor that looks like a open hand.
    Dim curHandClosed As Cursor 'A cursor that looks like a closed hand.


    'Somewhere in the New Constructor
    Dim cursorfile As IO.Stream

    'Load the image for the first cursor..
    cursorfile = Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("AB.HandOpen.cur")
    curHandOpen = New Cursor(cursorfile)

    'Load the image for the second cursor..
    cursorfile = Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("AB.HandClosed.cur")
    curHandClosed = New Cursor(cursorfile)

    'Anyplace in the code where you want to change the cursor shape...
    'Use Object.Cursor=Cursor
    'ex:
    'Me.Cursor = curHandOpen
    'pbImage.Cursor=CurHandClosed
    'etc...

    'Somewhere in the destructor
    CurHandOpen=Nothing
    CurHandClosed=Nothing
    Last edited by Tony Martin; Dec 1st, 2006 at 10:15 AM.

  7. #7
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: Custom Cursor in .Net 2003

    Quote Originally Posted by Tony Martin
    "Honestly I don’t understand your question." and "I provided you the method so it is your responsibility to figure it out."
    You often throw out "answers" and make crappy comments to things you don't understand?

    Sparrows link was most helpful and gave me the lead I needed. Thank you Sparrow.

    Here is how the code ended up:

    'Somewhere at the top....
    Dim curHandOpen As Cursor 'A cursor that looks like a open hand.
    Dim curHandClosed As Cursor 'A cursor that looks like a closed hand.


    'Somewhere in the New Constructor
    Dim cursorfile As IO.Stream

    'Load the image for the first cursor..
    cursorfile = Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("AB.HandOpen.cur")
    curHandOpen = New Cursor(cursorfile)

    'Load the image for the second cursor..
    cursorfile = Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("AB.HandClosed.cur")
    curHandClosed = New Cursor(cursorfile)

    'Anyplace in the code where you want to change the cursor shape...
    'Use Object.Cursor=Cursor
    'ex:
    'Me.Cursor = curHandOpen
    'pbImage.Cursor=CurHandClosed
    'etc...

    'Somewhere in the destructor
    CurHandOpen=Nothing
    CurHandClosed=Nothing
    And what would be the crappy comments I threw out? Can you point one out? In your original post you did not state about having your files in your resource file so how should I know what is in your mind! After all, I showed you how to do it and Sparrows link shows the same thing too. I am not here to write the code for you but show the right direction even though I don’t get paid for that, and that is your THANK YOU I got. NO more crappy comments for crappy people!!!

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Mar 2002
    Location
    St. Louis MO
    Posts
    129

    Re: [Resovled] Custom Cursor in .Net 2003

    Well now that we've thoughly pushed each others buttons....

    The first post was asking how, the second question was how if the cur file was in the application solution (manifest, Assembly, "list of things making up your program.." whatever you call it in .NET). The reply to that came across as getting my head bitten off for no good reason.

    Thank you for your efforts (you and Sparrow were,after all, the only ones to reply ANYTHING) and I can admit reading to much into it and offer the peace pipe if you want to share some puffs of it with me.
    Last edited by Tony Martin; Dec 4th, 2006 at 03:22 PM.

  9. #9
    New Member
    Join Date
    Dec 2006
    Posts
    6

    Re: [Resovled] Custom Cursor in .Net 2003

    Hi VBDT

    Your code is great. Its very simple and straight to the point, which I like
    And it works absolutely perfect during runtime

    However when I publish it it is still relying on the build.cur file within my project folder
    So if I remove this file from the project folder, or if someone on another computer wants to run it, it wont work

    Here is the code I have used: (note the build.cur file is sitting in the resources folder)

    Public Class Form1
    Dim cur As New Cursor("build.cur")

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.Cursor = cur
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Me.Cursor = Cursors.Default
    End Sub

    End Class


    Do you have any suggestion on how I can either publish that file, or use the correct path name

    Thanks in advance
    Jules

  10. #10
    PowerPoster VBDT's Avatar
    Join Date
    Sep 2005
    Location
    CA - USA
    Posts
    2,922

    Re: [Resovled] Custom Cursor in .Net 2003

    Quote Originally Posted by Jules_NZ
    Hi VBDT

    Your code is great. Its very simple and straight to the point, which I like
    And it works absolutely perfect during runtime

    However when I publish it it is still relying on the build.cur file within my project folder
    So if I remove this file from the project folder, or if someone on another computer wants to run it, it wont work

    Here is the code I have used: (note the build.cur file is sitting in the resources folder)

    Public Class Form1
    Dim cur As New Cursor("build.cur")

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Me.Cursor = cur
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    Me.Cursor = Cursors.Default
    End Sub

    End Class


    Do you have any suggestion on how I can either publish that file, or use the correct path name

    Thanks in advance
    Jules
    The simplest way to do it (with out any problems) you can add the cursor file to the projects recourse file by right clicking on the project in the solution explorer -> select Resources tab -> set the resource type to Files -> click on “AddRecource” and browse (set the dialog box’s file type to “All Files”) and select the cursor file (see the image); it will add the file to the project resource then use this code:
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.         Using ms As New IO.MemoryStream(My.Resources.build)
    3.             Me.Cursor = New Cursor(ms)
    4.         End Using
    5.     End Sub
    6.  
    7.     Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    8.         Me.Cursor = Cursors.Default
    9.     End Sub
    Attached Images Attached Images  

  11. #11
    New Member
    Join Date
    Dec 2006
    Posts
    6

    Re: [Resovled] Custom Cursor in .Net 2003

    That worked perfect!!!
    Thank you so much for the code

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width