Got .PNG file. Want embeffffded icon resource displayed as icon on form title bar

前端 未结 5 1169
予麋鹿
予麋鹿 2021-01-03 18:25

This was an interview question. Given Visual Studio 2008 and an icon saved as a .PNG file, they required the image as an embedded resource and to be used as the icon within

5条回答
  •  春和景丽
    2021-01-03 18:49

    Fire up VS, start new Windows Application. Open the properties sheet, add the .png file as a resource (in this example: glider.png ). From hereon, you can access the resource as a Bitmap file as WindowsFormsApplication10.Properties.Resources.glider

    Code for using it as an application icon:

     public Form1()
            {
                InitializeComponent();
                Bitmap bmp = WindowsFormsApplication10.Properties.Resources.glider;
                this.Icon = Icon.FromHandle(bmp.GetHicon());
            }
    

提交回复
热议问题