简体   繁体   English

单击按钮如何更改表单图标?

[英]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.

相关问题 如何将表单的图标更改为自己的图像? - How do I change a form's icon to my own image? 当我单击UserControl内部的按钮时,如何更改MainWindow的内容? - How do I change content from my MainWindow when I click a button from inside my UserControl? 如果我单击按钮,请更改我的人形。 我能怎么做? - if i click button, change my human texture. How can i do? 如何通过单击按钮使表单标题动态更改? - How do you make a form title dynamically change with a button click? 我如何做按钮单击背景颜色的更改? - How do I do a button click background color change? 如何在单击另一个表单中的按钮时运行Game1 - How do I run Game1 on click of a button in another form 如何在 Razor 中单击按钮时更改模型值? - How can i change my model value on button click in Razor? 如何单击子窗体上的十字按钮(取消按钮)并转到主窗体? - How do I click the cross button (the cancel button) on the sub form and go to the main form? 如何通过单击另一个表单的按钮来更改一个表单中的按钮的文本? - How to change the Text of a Button in One form with a Button click of another Form? 单击按钮时,将打开一个新表单。 当我点击另一个表单时,如何将此表单保留在前台? - When I click a button, a new form opens. How do I keep this form in the foreground when I click on another form?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM