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.
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?
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;
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.
Rating is a way of saying thank you. Don't forget to rate always!
"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.
"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!!!
Last edited by VBDT; Dec 2nd, 2006 at 12:26 AM.
Rating is a way of saying thank you. Don't forget to rate always!
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.
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
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:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Using ms As New IO.MemoryStream(My.Resources.build)
Me.Cursor = New Cursor(ms)
End Using
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
Rating is a way of saying thank you. Don't forget to rate always!