2012-12-15 49 views
0

我想禁用ToolStripDropDownButton下拉列表中的下拉阴影。如果下拉菜单包含本身具有下拉菜单的项目(例如,多级菜单),则在ToolStripDropDownButton上将DropShadowEnabled设置为false会导致顶级下拉菜单出现在错误的位置。见附图。在多级别下拉菜单中将ToolStripDropDown.DropShadowEnabled设置为false

enter image description here

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; 
} 

回答

1

这是ToolStripItem的类非常典型的lossage。显然这是一个bug,它可能是在他们应用黑客来解决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中flakeyness,你仍然在XP上运行,所以你不能看到它。在Aero桌面上放置阴影的方式不同,它是否是启用的系统设置。所以在Aero上使用该属性完全无效。

这些的ToolStripItem类的错误没有得到固定的.NET 2.0发布后,对整个团队的WinForms上移动到WPF组。而且他们现在肯定没有得到修复,没有点在connect.microsoft.com提交bug,尽管你可以自由地这样做。

与添加的皱纹,物业就不能有效果再上更高版本的Windows,因为它现在是系统设置,在这里做的唯一合乎逻辑的做法是认输。不要更改属性。