[英]How do I change my icon of the form on the click of a button?
I am using a form skin and instead of removing everything including the form skin I have been trying to make the form change the icon itself on startup. 我使用的是表单皮肤,而不是删除包括表单皮肤在内的所有内容,我一直试图使表单在启动时更改图标本身。 I have bitmap versions of my logo and when i try to reference those i get the error: Cannot implicitly convert type 'System.Drawing.Bitmap' to 'System.Drawing.Icon'
我有徽标的位图版本,当我尝试引用这些位图版本时,出现错误:无法将类型“ System.Drawing.Bitmap”隐式转换为“ System.Drawing.Icon”
I have tried adding an icon to my resources and trying to reference it, however, only my bitmaps are able to be referenced. 我尝试将图标添加到资源中并尝试引用它,但是,只能引用我的位图。
public Main2()
{
InitializeComponent();
Main2 f1 = new Main2();
f1.Text = "Chaos V2.0.1c";
f1.Icon = Properties.Resources.Logo; //problematic code (line 44)
//My Tab Controls
HomeTabControl.Visible = true;
FullLuaTabControl.Visible = false;
CommandTabControl.Visible = false;
VIPServerTabControl.Visible = false;
JailbreakTabControl.Visible = false;
PhantomForcesTabControl.Visible = false;
MM2TabControl.Visible = false;
RoCitizensTabControl.Visible = false;
BoogaBoogaTabControl.Visible = false;
PrisonLifeTabControl.Visible = false;
BuildABoatTabControl.Visible = false;
LumberTycoon2TabControl.Visible = false;
MeepCityTabControl.Visible = false;
VehicleSimulatorTabControl.Visible = false;
SuperPowerTrainingTabControl.Visible = false;
BeeSwarmSimulatorTabControl.Visible = false;
WeightLiftingTabControl.Visible = false;
MiningSimulatorTabControl.Visible = false;
BlobSimulatorTabControl.Visible = false;
IceCreamSimulatorTabControl.Visible = false;
PetSimulatorTabControl.Visible = false;
StrucidTabControl.Visible = false;
CounterBloxTabControl.Visible = false;
ApocalypseTabControl.Visible = false;
FullLuaScriptsTabControl.Visible = false;
SettingsTabControl.Visible = false;
}
I get the error: 'Resources' does not contain a definition for 'Logo' (Line 44) 我收到错误消息:“资源”不包含“徽标”的定义(第44行)
Check if your Icon in resources is really called Logo. 检查资源中的图标是否真的称为徽标。 You could change Bitmap to Icon, but I don't know if you will be satisfied with result.
您可以将位图更改为图标,但是我不知道您是否会对结果满意。
public Icon ToIcon(Bitmap bmp)
{
IntPtr hicon = bmp.GetHicon();
Icon icon = Icon.FromHandle(hicon);
DestroyIcon(hicon); // prevent memory leak.
return icon;
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
extern static bool DestroyIcon(IntPtr handle);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.