如何使用c#.net windows应用程序从数据库中更改Windows窗体图标?
问题描述:
您好,
如何使用c#.net windows应用程序从数据库更改Windows窗体图标?
我们如何使用c#.net windows应用程序动态或运行时更改图标?
请帮助我。
Ankit Agarwal
软件工程师
Hello,
How to change windows form icon from database using c# .net windows application?
How can we change icon dynamically or runtime using c# .net windows application?
Please help me.
Ankit Agarwal
Software Engineer
答
参见 Bitmap.GetHicon Method [ ^ ]。
1。将图标图像作为.jpg图像保存在数据库中。
2.将图标图像检索到位图变量,比如位图。
See Bitmap.GetHicon Method[^].
1. Save your icon image in the DB as a .jpg image.
2. Retrieve your icon image into a Bitmap variable, say bitmap.
Bitmap bitmap;
3.将位图转换为图标句柄。
3. Convert the Bitmap into an Icon handle.
IntPtr icon_handle = bitmap.GetHicon ( );
4.从Icon手柄创建新图标。
4. Create new Icon from the Icon handle.
Icon icon = Icon.FromHandle ( icon_handle );
5.将表格图标设置为新图标。
5. Set Form Icon to the new icon.
this.Icon = icon;
6.销毁图标,因为表单会创建自己的图标副本。
6. Destroy the icon, since the form creates its own copy of the icon.
[ System.Runtime.InteropServices.DllImport ( "user32.dll",
CharSet = CharSet.Auto ) ]
extern static bool DestroyIcon(IntPtr handle);
DestroyIcon ( icon.Handle );