Results 1 to 25 of 25

Thread: [2005] Custom Mouse Cursor

  1. #1

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Exclamation [2005] Custom Mouse Cursor

    I have seen multiple programs where you can choose a fancier mouse cursor to use instead of the plain white one. For instance, the cursor with a flame around it. I am in need of some code to change the mouse cursor to a specific Icon file on my computer. I would appreciate any code that you know works for sure.
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

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

    Re: [2005] Custom Mouse Cursor

    chech this thread

  3. #3

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: [2005] Custom Mouse Cursor

    I've tried many things, including what was in that thread. I always get this error:

    "Image format is not valid. The image file may be corrupted.
    Parameter name: stream"
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

  4. #4

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: [2005] Custom Mouse Cursor

    Here's My Code:

    VB Code:
    1. Dim curPCPI As Cursor
    2.         Dim cursorfile As IO.Stream
    3.         cursorfile = Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("PCPI.cur")
    4.         curPCPI = New Cursor(cursorfile)
    5.         Me.Cursor = curPCPI
    6.         curPCPI = Nothing

    I Actually get this error:

    "Object reference not set to an instance of an object."

    Directed at the line: "curPCPI = New Cursor(cursorfile)"
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

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

    Re: [2005] Custom Mouse Cursor

    is your cursor file in the app's resurse file? If yes then use this code:
    VB Code:
    1. Me.Cursor = New Cursor(Me.GetType(), "PCPI.cur")

  6. #6

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: [2005] Custom Mouse Cursor

    I am now getting the image corrupt error:

    "Image format is not valid. The image file may be corrupted.
    Parameter name: stream"

    Although, there is nothing wrong with my image.
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

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

    Re: [2005] Custom Mouse Cursor

    Quote Originally Posted by StreaksAthlete
    I am now getting the image corrupt error:

    "Image format is not valid. The image file may be corrupted.
    Parameter name: stream"

    Although, there is nothing wrong with my image.
    that error can acure when the the file can't be read. Are you sure that the iamge file is .cur (cursor) file? and it exists in the resurs file with the same name?

  8. #8

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: [2005] Custom Mouse Cursor

    Yes, I am sure
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

  9. #9
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Custom Mouse Cursor

    I just tried adding a cursor file to the Resources tab and then accessing it via My.Resources. It produced that same error. That's doesn't really help you fix the issue but as far as I can see that should have worked so it at least confirms that you are not insane... or at least no more than me.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: [2005] Custom Mouse Cursor

    I am not sure why it happens but I am sure there is some thing wrong with the cursor file. Not if the image was created with the jpg format and later the extension got changed to .cur it does not change the format of the image. It is still have jpg format. Try to use it with another cursor file to test the code. You can find cursor file in the “C:\WINDOWS\Cursors” directory.

  11. #11

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: [2005] Custom Mouse Cursor

    I tried it with an alternate Windows cursor, and I did not get any error, BUT, the cursor still didn't change, it stayed the same Default cursor.


    EDIT:

    Nevermind, I got the C:\Windows\Cursor to work, so the problem must be my image file. It was an Icon file, saved from an Icon editor, and I changed it to a .cur file, is that the problem?
    Last edited by StreaksAthlete; Dec 10th, 2006 at 07:54 PM.
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

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

    Re: [2005] Custom Mouse Cursor

    Ok try this. It works i tested it!
    VB Code:
    1. Dim ms As New IO.MemoryStream(My.Resources._3dsns)
    2.         Me.Cursor = New Cursor(ms)
    3.         ms.Close()
    4.         ms.Dispose()

  13. #13

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: [2005] Custom Mouse Cursor

    Error 1 Overload resolution failed because no accessible 'New' can be called with these arguments:
    'Public Sub New(buffer() As Byte)': Value of type 'System.Drawing.Bitmap' cannot be converted to '1-dimensional array of Byte'.
    'Public Sub New(capacity As Integer)': Value of type 'System.Drawing.Bitmap' cannot be converted to 'Integer'.
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

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

    Re: [2005] Custom Mouse Cursor

    can you post your project?

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

    Re: [2005] Custom Mouse Cursor

    I don't get any error. Here check this simple project.
    Attached Files Attached Files

  16. #16

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: [2005] Custom Mouse Cursor

    Here it is:
    Attached Files Attached Files
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

  17. #17
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Custom Mouse Cursor

    I created a resource from a standard Windows cursor file. I then tried loading that cursor from the disc file via a FileStream, which worked, and from the resource via a MemoryStream, which didn't. Can anyone see any obvious issues with this:
    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Using fs As New IO.FileStream("C:\WINDOWS\Cursors\arrow_i.cur", IO.FileMode.Open)
    3.         Me.Cursor = New Cursor(fs)
    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.     Using ms As New IO.MemoryStream
    9.         Dim buffer As Byte() = My.Resources.arrow_i
    10.  
    11.         ms.Write(buffer, 0, buffer.Length)
    12.         Me.Cursor = New Cursor(ms)
    13.     End Using
    14. End Sub
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  18. #18

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: [2005] Custom Mouse Cursor

    The problem is that my file is not a valid .cur file. I renamed an Icon (.ico) to .cur which is most likely the problem. But, how do I make it a valid Cursor file?
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

  19. #19
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Custom Mouse Cursor

    Ah HA!: There was something obviously wrong:
    VB Code:
    1. Using ms As New IO.MemoryStream
    2.     Dim buffer As Byte() = My.Resources.arrow_i
    3.  
    4.     ms.Write(buffer, 0, buffer.Length)
    5.     [U]ms.Seek(0, IO.SeekOrigin.Begin)[/U]
    6.     Me.Cursor = New Cursor(ms)
    7. End Using
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  20. #20
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Custom Mouse Cursor

    Quote Originally Posted by StreaksAthlete
    The problem is that my file is not a valid .cur file. I renamed an Icon (.ico) to .cur which is most likely the problem. But, how do I make it a valid Cursor file?
    If you renamed myfile.mdb to myfile.doc would you expect Microsoft Word to open it successfully? The extension doesn't change the contents of a file, only how Windows tries to handle it. An ICO file with a CUR extension is still an icon file. Visual Studio allows you to create cursor and icon objects. You'll need to open the icon, copy its graphical content and paste that into a new cursor. You then save the cursor as a resource and you can access it. I would suggest using the My.Resources method I showed previously.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  21. #21

    Thread Starter
    Hyperactive Member StreaksAthlete's Avatar
    Join Date
    Sep 2004
    Posts
    348

    Re: [2005] Custom Mouse Cursor

    The sarcasm isn't needed. I am thankfull for everybody's help! You guys should get paid for everyword.

    Now, is there a way to make this custom cursor a System-Wide change?
    Last edited by StreaksAthlete; Dec 10th, 2006 at 08:37 PM.
    Unity Programs™ - Downloads To Make Your Computer Life Easier - UnityPrograms.com, check it out
    My small company, I need feedback.


    If someone's post was useful, don't forget to Rate It by clicking the Rate This Post link under the avatar.
    If this post has been resolved. Please mark it as Resolved by going through the Thread Tools above and clicking on the Mark Thread Resolved option.
    We ride together, We die together, .NET for life. - Working With Visual Studio.NET 2005

    Application Deployment, General Developer Forum, Visual Basic .NET

  22. #22
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Custom Mouse Cursor

    It wasn't sarcasm. It was an example to illustrate why what you were trying to do couldn't possibly work. Is that a guilty conscience I smell?

    You can change the Windows.Forms.Cursor.Current property but every object will simply use its own cursor as soon as you move the mouse. If you want to affect the system-wide cursor settings then you'd have to edit those Windows settings. I would guess that those settings are stored in the registry. You can find them relatively easily by checking what the location of your current cursor is in the Mouse properties and then searching the registry for that value.
    Last edited by jmcilhinney; Dec 10th, 2006 at 09:11 PM.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: [2005] Custom Mouse Cursor

    Quote Originally Posted by jmcilhinney
    Ah HA!: There was something obviously wrong:
    VB Code:
    1. Using ms As New IO.MemoryStream
    2.     Dim buffer As Byte() = My.Resources.arrow_i
    3.  
    4.     ms.Write(buffer, 0, buffer.Length)
    5.     [U]ms.Seek(0, IO.SeekOrigin.Begin)[/U]
    6.     Me.Cursor = New Cursor(ms)
    7. End Using
    Ah so this is how to access randomly to the data! It seems the other stream objects dose not have that method. Good info! Sorry I can’t give any rep it doesn’t let me, but I like to. This is a good info thanks.

  24. #24
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2005] Custom Mouse Cursor

    Quote Originally Posted by VBDT
    Ah so this is how to access randomly to the data! It seems the other stream objects dose not have that method. Good info! Sorry I can’t give any rep it doesn’t let me, but I like to. This is a good info thanks.
    Some stream types can seek while others can't. Every stream has a CanSeek property to indicate whether it can or not. Those that can are usually those that are sitting on your own machine. Those that can't are usually those coming from elsewhere, like a NetworkStream. It doesn't make sense to randomly access a stream that you haven't received all of from a remote source.

    Note that classes like a StreamReader are NOT streams and thus have no CanSeek property. A StreamReader is an object that reads text from a stream. Its BaseStream property is a reference to a stream. That stream has a CanSeek property. Note that a StreamReader can read any type of stream, including FileStream, MemoryStream, NetworkStream, etc. Whether you can reread the contents of a StreamReader depends on the type of its BaseStream, e.g.
    VB Code:
    1. If myStreamReader.BaseStream.CanSeek Then
    2.     'Reset the stream position to the beginning.
    3.     myStreamReader.BaseStream.Seek(0, IO.SeekOrigin.Begin)
    4. End If
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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

    Re: [2005] Custom Mouse Cursor

    Thanks again Jmc for the great info

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