首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如果窗体使用IsMdiContainer = true最大化,如何将窗体图标设置为

问如果窗体使用IsMdiContainer = true最大化,如何将窗体图标设置为
EN

Stack Overflow用户
提问于 2013-11-22 15:28:05
回答 1查看 1.1K关注 0票数 1

当子窗体最大化为父窗体时,如何设置窗体图标。我把我的IsMdiContainer =真。我只是想把图标去掉,因为它把我的菜单栏搞砸了。

最小化:

​

​

最大限度地:

​

​

对不起,我还是c# winforms的新手。谢谢你帮我..。:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-22 15:55:03

MenuStrip正在为您添加一个菜单。您可以使用以下代码停止它:

代码语言:javascript
复制
private void menuStrip1_ItemAdded(object sender, ToolStripItemEventArgs e)
{
    if (e != null && e.Item != null && e.Item.GetType().Name == "SystemMenuItem")
    {
        this.menuStrip1.Items.RemoveAt(0);
    }
}

以下是我的完整工作示例:

代码语言:javascript
复制
using System;
using System.Windows.Forms;

namespace WindowsFormsApplication1
{
    public class ExampleForm : Form
    {
        private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;

        public ExampleForm()
        {
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(1002, 24);
            this.menuStrip1.TabIndex = 1;
            this.menuStrip1.Text = "menuStrip1";
            this.menuStrip1.ItemAdded += new System.Windows.Forms.ToolStripItemEventHandler(this.menuStrip1_ItemAdded);
            // 
            // fileToolStripMenuItem
            // 
            this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.openToolStripMenuItem});
            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            this.fileToolStripMenuItem.Text = "&File";
            // 
            // openToolStripMenuItem
            // 
            this.openToolStripMenuItem.Name = "openToolStripMenuItem";
            this.openToolStripMenuItem.ShortcutKeys = ((System.Windows.Forms.Keys)((System.Windows.Forms.Keys.Control | System.Windows.Forms.Keys.O)));
            this.openToolStripMenuItem.Size = new System.Drawing.Size(146, 22);
            this.openToolStripMenuItem.Text = "&Open";
            this.openToolStripMenuItem.Click += new System.EventHandler(this.openToolStripMenuItem_Click);
            // 
            // Form1
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(1002, 674);
            this.Controls.Add(this.menuStrip1);
            this.IsMdiContainer = true;
            this.MainMenuStrip = this.menuStrip1;
            this.Name = "Form1";
            this.Text = "Form1";
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var form = new Form
            {
                Text = "Child",
                MdiParent = this,
                ShowIcon = false
            };
            form.Show();
        }

        private void menuStrip1_ItemAdded(object sender, ToolStripItemEventArgs e)
        {
            if (e != null && e.Item != null && e.Item.GetType().Name == "SystemMenuItem")
            {
                this.menuStrip1.Items.RemoveAt(0);
            }
        }
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20148481

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档