2

バックアップ ツールをプログラミングしています。ツールの上に、2 つの toolstripmenuitems を含むメニューストリップがあります。予想通り少し色を変えてみました。集中していないメニューは見栄えがします:

クリックされていないメニュー項目

メニュー項目「ファイル」をクリックしてコンテキストメニューを開くと、色が白に変わり、テキストを読むことができなくなります。

クリックされたメニュー項目

どこでその動作を変更できるか教えてください。Visual Studio 2013 Ultimate、Windows Forms アプリケーション、コードは C# を使用しています。

コードは次のとおりです。

// // initializing menuStrip1 // this.menuStrip1.BackColor = System.Drawing.Color.MediumBlue; this.menuStrip1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center; this.menuStrip1.Font = new System.Drawing.Font("Segoe UI Semilight", 15.75F, System.Drawing.FontStyle.Regular,
System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.fileToolStripMenuItem, this.helpToolStripMenuItem}); this.menuStrip1.Location = new System.Drawing.Point(0, 0); this.menuStrip1.MinimumSize = new System.Drawing.Size(0, 40); this.menuStrip1.Name = "menuStrip1"; this.menuStrip1.Size = new System.Drawing.Size(1056, 40); this.menuStrip1.TabIndex = 77; this.menuStrip1.Text = "menuStrip1"; // // initializing fileToolStripMenuItem and adding to menuStrip1 // this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { this.saveToolStripMenuItem, this.saveAsToolStripMenuItem, this.loadToolStripMenuItem}); this.fileToolStripMenuItem.Font = new System.Drawing.Font("Calibri Light", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.fileToolStripMenuItem.ForeColor = System.Drawing.SystemColors.ControlLightLight; this.fileToolStripMenuItem.Name = "fileToolStripMenuItem"; this.fileToolStripMenuItem.Size = new System.Drawing.Size(54, 36); this.fileToolStripMenuItem.Text = "File"; this.fileToolStripMenuItem.Click += new System.EventHandler (this.fileToolStripMenuItem_Click); // // initializing saveToolStripMenuItem and adding to fileToolStripMenuItem // this.saveToolStripMenuItem.BackColor = System.Drawing.Color.MediumBlue; this.saveToolStripMenuItem.ForeColor = System.Drawing.SystemColors.ControlLightLight; this.saveToolStripMenuItem.Name = "saveToolStripMenuItem"; this.saveToolStripMenuItem.Size = new System.Drawing.Size(166, 30); this.saveToolStripMenuItem.Text = "Save"; this.saveToolStripMenuItem.Click += new System.EventHandler (this.saveToolStripMenuItem_Click);
///

4

2 に答える 2

4

デフォルトでは、この機能はそのままでは利用できません。Rendererこれを実現するには、カスタム ツール ストリップを作成する必要があります。

から継承するクラスを作成しますToolStripProfessionalRenderer-

    private class BlueRenderer : ToolStripProfessionalRenderer
    {
        protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e)
        {
            Rectangle rc = new Rectangle(Point.Empty, e.Item.Size);
            Color c = Color.MediumBlue;
            using (SolidBrush brush = new SolidBrush(c))
                e.Graphics.FillRectangle(brush, rc);
        }
    }

そして、このレンダラーをフォーム コンストラクターのメニュー ストリップにアタッチします。

    public Form1()
    {
        InitializeComponent();
        menuStrip1.Renderer = new BlueRenderer();
    }
于 2016-04-21T11:35:00.807 に答える