Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Custom Cursor from Bytes

Custom Cursor from Bytes

Scheduled Pinned Locked Moved C#
data-structurestutorialquestionlearning
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    jspano
    wrote on last edited by
    #1

    Anyone know how to get a cusor to load from an array of bytes? I have a byte[] in a resorce file that is a custom cursor. I need to load a System.Windows.Forms.Cursor from it. I don't have to use a resource file for it, but it needs to be embeded in the exe some how and not on disk. Thanks in advance.

    H 1 Reply Last reply
    0
    • J jspano

      Anyone know how to get a cusor to load from an array of bytes? I have a byte[] in a resorce file that is a custom cursor. I need to load a System.Windows.Forms.Cursor from it. I don't have to use a resource file for it, but it needs to be embeded in the exe some how and not on disk. Thanks in advance.

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      It's easier if you don't embed it in a ResX file. Instead, add the .cur file to your project and change it's Build Action (in the properties displayed when you click on the file) to "Embedded Resource". To get the Cursor (Icons work this way, too), either use Assembly.GetManifestResourceStream or - easier - use this particular Cursor constructor:

      Cursor cur = new Cursor(typeof(SomeClass), "MyCursor.cur");

      ...where SomeClass is a Type that scopes the resource (provides both the assembly reference and the namespace to find the embedded resource by name). For more information, see the aforementioned constructor. Basically, if SomeClass exists in the namespace MyCompany.MyProject, the example would look for an embedded resource named "MyCompany.MyProject.MyCursor.cur".

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      J 1 Reply Last reply
      0
      • H Heath Stewart

        It's easier if you don't embed it in a ResX file. Instead, add the .cur file to your project and change it's Build Action (in the properties displayed when you click on the file) to "Embedded Resource". To get the Cursor (Icons work this way, too), either use Assembly.GetManifestResourceStream or - easier - use this particular Cursor constructor:

        Cursor cur = new Cursor(typeof(SomeClass), "MyCursor.cur");

        ...where SomeClass is a Type that scopes the resource (provides both the assembly reference and the namespace to find the embedded resource by name). For more information, see the aforementioned constructor. Basically, if SomeClass exists in the namespace MyCompany.MyProject, the example would look for an embedded resource named "MyCompany.MyProject.MyCursor.cur".

        -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

        J Offline
        J Offline
        jspano
        wrote on last edited by
        #3

        Thanks Heath. I ended up doing it this way. I added it to the project and used a resourcemanager to pull it out. It works great this way. Resources are one spot in .net that I find lacking. MS didn't even provide a good resource editor. All I can find on the net don't work with custom cursors. I had one that was an adding for vs02 but lost it and can't find it again. It worked great.

        H 1 Reply Last reply
        0
        • J jspano

          Thanks Heath. I ended up doing it this way. I added it to the project and used a resourcemanager to pull it out. It works great this way. Resources are one spot in .net that I find lacking. MS didn't even provide a good resource editor. All I can find on the net don't work with custom cursors. I had one that was an adding for vs02 but lost it and can't find it again. It worked great.

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          Why did you use the ResourceManager? You simply grab the manifest resource stream. The ResourceManager is for ResX files. VS.NET has a great resource editor, far better than VS6. It still handles cursors, icons, and bitmaps internally. Instead of string resources, you're supposed to use ResX files. The great thing is that you can embed any file as an embedded resource. If you right-click, you can select "Open with..." to open ANY resource with ANY program (and keep a cached list of programs you use). In VS6, if the resource wasn't understood / handled by the IDE, you had to export the resource, browse to it and open it with the associated application (or open the application then open the file). That was a pain. In any case, 'tis far easier to just embed the .cur file as an embedded resource and use the Cursor constructor I mentioned, not the ResourceManager. Besides, binary files are stored as bse64 encodings by default. The ResourceManager has overhead for setting things up, then has to find the resource and decode it. The other way is quick and is closer to how it would be done in Win32 when loading a cursor from a persistent file.

          -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups