0

ToolStripDropDownButton のドロップダウンでドロップダウン シャドウを無効にしたい。ドロップダウン メニューにドロップダウン自体を持つアイテムが含まれている場合 (マルチレベル メニューなど)、ToolStripDropDownButton で DropShadowEnabled を false に設定すると、トップ レベルのドロップダウンが間違った位置に表示されます。添付の写真を参照してください。

ここに画像の説明を入力

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
        toolStripDropDownButton1.DropDown.DropShadowEnabled = false;
    }
}


partial class Form1
{
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.IContainer components = null;

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
    protected override void Dispose(bool disposing)
    {
        if (disposing && (components != null))
        {
            components.Dispose();
        }
        base.Dispose(disposing);
    }

    #region Windows Form Designer generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
        System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
        this.toolStrip1 = new System.Windows.Forms.ToolStrip();
        this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
        this.item1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.subitem1ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
        this.toolStrip1.SuspendLayout();
        this.SuspendLayout();
        // 
        // toolStrip1
        // 
        this.toolStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.toolStripDropDownButton1});
        this.toolStrip1.Location = new System.Drawing.Point(0, 0);
        this.toolStrip1.Name = "toolStrip1";
        this.toolStrip1.Size = new System.Drawing.Size(292, 25);
        this.toolStrip1.TabIndex = 0;
        this.toolStrip1.Text = "toolStrip1";
        // 
        // toolStripDropDownButton1
        // 
        this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
        this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.item1ToolStripMenuItem});
        this.toolStripDropDownButton1.Image = ((System.Drawing.Image)(resources.GetObject("toolStripDropDownButton1.Image")));
        this.toolStripDropDownButton1.ImageTransparentColor = System.Drawing.Color.Magenta;
        this.toolStripDropDownButton1.Name = "toolStripDropDownButton1";
        this.toolStripDropDownButton1.Size = new System.Drawing.Size(29, 22);
        this.toolStripDropDownButton1.Text = "toolStripDropDownButton1";
        // 
        // item1ToolStripMenuItem
        // 
        this.item1ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.subitem1ToolStripMenuItem});
        this.item1ToolStripMenuItem.Name = "item1ToolStripMenuItem";
        this.item1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
        this.item1ToolStripMenuItem.Text = "item1";
        // 
        // subitem1ToolStripMenuItem
        // 
        this.subitem1ToolStripMenuItem.Name = "subitem1ToolStripMenuItem";
        this.subitem1ToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
        this.subitem1ToolStripMenuItem.Text = "subitem1";
        // 
        // Form1
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(292, 273);
        this.Controls.Add(this.toolStrip1);
        this.Name = "Form1";
        this.Text = "Form1";
        this.toolStrip1.ResumeLayout(false);
        this.toolStrip1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    private System.Windows.Forms.ToolStrip toolStrip1;
    private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
    private System.Windows.Forms.ToolStripMenuItem item1ToolStripMenuItem;
    private System.Windows.Forms.ToolStripMenuItem subitem1ToolStripMenuItem;
}
4

1 に答える 1

1

これは、ToolStripItem クラスでの非常に典型的な損失です。明らかにバグです。Windows の問題を回避するためにハックを適用したときに導入された可能性があります。内部バグ番号は引き続き参照ソースで確認できます。

public bool DropShadowEnabled {
    get {
        // VSWhidbey 338272 - DropShadows are only supported on TopMost windows
        // due to the flakeyness of the way it's implemented in the OS. (Non toplevel
        // windows can have parts of the shadow disappear because another window can get
        // sandwiched between the SysShadow window and the dropdown.)
        return dropShadowEnabled && TopMost && DisplayInformation.IsDropShadowEnabled;
    }
    set {  // etc... }
}

しかし、セッターとレンダラーに対応する修正がありません。

彼らが言及した不安定さは、Vista で実際に修正されました。まだ XP で実行しているので、それを見ることはできません。ドロップ シャドウは、Aero デスクトップでは異なる方法で実行されます。ドロップ シャドウが有効かどうかはシステム設定です。そのため、このプロパティを使用しても、Aero ではまったく効果がありません。

これらの ToolStripItem クラスのバグは、.NET 2.0 のリリース後も修正されず、Winforms チーム全体が WPF グループに移行しました。そして、これらの問題は現在修正されていません。connect.microsoft.com でバグを報告しても意味がありません。

プロパティはシステム設定になっているため、新しいバージョンの Windows では影響を与えられないというしわが追加されているため、ここで行うべき唯一の論理的なことは、タオルを投げ入れることです。プロパティを変更しないでください。

于 2012-12-15T14:22:19.293 に答える