How to Change the Icon from the TitleBar
-
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.
-
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.
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 -
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"));
CheersBoth 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.