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. Managed C++/CLI
  4. How to Change the Icon from the TitleBar

How to Change the Icon from the TitleBar

Scheduled Pinned Locked Moved Managed C++/CLI
graphicshelptutorial
3 Posts 2 Posters 3 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.
  • P Offline
    P Offline
    Peter Fonk
    wrote on last edited by
    #1

    Hello, I can't change the small icon from the Main Form with the following code in my project: this->Icon = new System::Drawing::Icon("SAVE.BMP"); With this pice of code i get the following exception error Unhandled Exception: System.ArgumentException: The argument 'picture' must be a picture that can be used as a Icon. The same picture is working perfect if i use it for a menubar icon. Many thanks for a good anwser :-D Peter.

    J 1 Reply Last reply
    0
    • P Peter Fonk

      Hello, I can't change the small icon from the Main Form with the following code in my project: this->Icon = new System::Drawing::Icon("SAVE.BMP"); With this pice of code i get the following exception error Unhandled Exception: System.ArgumentException: The argument 'picture' must be a picture that can be used as a Icon. The same picture is working perfect if i use it for a menubar icon. Many thanks for a good anwser :-D Peter.

      J Offline
      J Offline
      Jeff J
      wrote on last edited by
      #2

      Apparently, a System::Drawing::Icon can only be created from an .ico file, and not a .bmp file. There do not seem to be any Icon constructors that take a bitmap. I do not know how you managed it for your menubar icon. Perhaps the easiest solution would be to copy the bitmap to an .ico file (via resource editor or other), then use the method you posted. Of course, with an .ico you could just set the form's icon from the propery settings, if you are integrated with C#. If you are purely MC++, I suppose you would have jump through a few hoops to compile the icon into a raw resource, and link it in to your executable. Supposedly VS.Net 2003 will make that ea$ier. If you are mainly interested in converting a bitmap file to an Icon, you could alternatively do: Bitmap *bmp = new Bitmap("MyIcon.bmp"); this->Icon = Icon::FromHandle(bmp->GetHicon()); or... Icon *ico = Icon::FromHandle(new Bitmap("MyIcon.bmp")); Cheers

      P 1 Reply Last reply
      0
      • J Jeff J

        Apparently, a System::Drawing::Icon can only be created from an .ico file, and not a .bmp file. There do not seem to be any Icon constructors that take a bitmap. I do not know how you managed it for your menubar icon. Perhaps the easiest solution would be to copy the bitmap to an .ico file (via resource editor or other), then use the method you posted. Of course, with an .ico you could just set the form's icon from the propery settings, if you are integrated with C#. If you are purely MC++, I suppose you would have jump through a few hoops to compile the icon into a raw resource, and link it in to your executable. Supposedly VS.Net 2003 will make that ea$ier. If you are mainly interested in converting a bitmap file to an Icon, you could alternatively do: Bitmap *bmp = new Bitmap("MyIcon.bmp"); this->Icon = Icon::FromHandle(bmp->GetHicon()); or... Icon *ico = Icon::FromHandle(new Bitmap("MyIcon.bmp")); Cheers

        P Offline
        P Offline
        Peter Fonk
        wrote on last edited by
        #3

        Both answers work Perfect :)) I have used for the MenuBar a Image List, I guess it was wrong thinking that a 'ico' file is a renamed Bitmap file !! Peter.

        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