Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Winforms 在多级下拉列表中将ToolStripDropDown.DropShadowEnabled设置为false_Winforms_Shadow_Toolstripdropdown - Fatal编程技术网

Winforms 在多级下拉列表中将ToolStripDropDown.DropShadowEnabled设置为false

Winforms 在多级下拉列表中将ToolStripDropDown.DropShadowEnabled设置为false,winforms,shadow,toolstripdropdown,Winforms,Shadow,Toolstripdropdown,我想禁用ToolStripDropDownButton下拉菜单上的下拉阴影。如果下拉菜单包含本身具有下拉菜单的项目(例如,多级菜单),则在ToolStripDropDownButton上将DropShadowEnabled设置为false会导致顶级下拉菜单出现在错误的位置。见附图 public partial class Form1 : Form { public Form1() { InitializeComponent(); toolStrip

我想禁用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;
}

公共部分类表单1:表单
{
公共表格1()
{
初始化组件();
toolStripDropDownButton1.DropDown.DropShadowEnabled=false;
}
}
部分类Form1
{
/// 
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager资源=新的System.ComponentModel.ComponentResourceManager(typeof(Form1));
this.toolStrip1=new System.Windows.Forms.ToolStrip();
this.toolStripDropDownButton1=新系统.Windows.Forms.ToolStripDropDownButton();
this.item1ToolStripMenuItem=new System.Windows.Forms.ToolStripMenuItem();
this.subitem1ToolStripMenuItem=新建System.Windows.Forms.ToolStripMenuItem();
this.toolStrip1.SuspendLayout();
这个.SuspendLayout();
// 
//工具条1
// 
this.toolStrip1.Items.AddRange(新的System.Windows.Forms.ToolStripItem[]{
此.toolStripDropDownButton1});
this.toolStrip1.Location=新系统.Drawing.Point(0,0);
this.toolStrip1.Name=“toolStrip1”;
this.toolStrip1.Size=新系统.Drawing.Size(292,25);
this.toolStrip1.TabIndex=0;
this.toolStrip1.Text=“toolStrip1”;
// 
//toolStripDropDownButton1
// 
this.toolStripDropDownButton1.DisplayStyle=System.Windows.Forms.ToolStripItemDisplayStyle.Image;
此.toolStripDropDownButton1.DropDownItems.AddRange(新的System.Windows.Forms.ToolStripItem[]{
此参数为.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=新系统图尺寸(29,22);
this.toolStripDropDownButton1.Text=“toolStripDropDownButton1”;
// 
//item1ToolStripMenuItem
// 
this.item1ToolStripMenuItem.DropDownItems.AddRange(新的System.Windows.Forms.ToolStripItem[]{
此参数为.subitem1ToolStripMenuItem});
this.item1ToolStripMenuItem.Name=“item1ToolStripMenuItem”;
this.item1ToolStripMenuItem.Size=新系统.图纸.尺寸(152,22);
this.item1ToolStripMenuItem.Text=“item1”;
// 
//子项1 ToolStripMenuItem
// 
this.subitem1ToolStripMenuItem.Name=“subitem1ToolStripMenuItem”;
this.subitem1ToolStripMenuItem.Size=新系统.Drawing.Size(152,22);
this.subitem1ToolStripMenuItem.Text=“subitem1”;
// 
//表格1
// 
此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=新系统.Drawing.Size(292,273);
this.Controls.Add(this.toolStrip1);
this.Name=“Form1”;
this.Text=“Form1”;
此.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
此选项为.resume布局(false);
这个。执行布局();
}
#端区
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
private System.Windows.Forms.ToolStripMenuItem项目1 ToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem子项ToolStripMenuItem;
}

这是ToolStripItem类中非常典型的丢失。显然,这是一个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... }
}
但是在setter和渲染器中没有相应的修复

他们提到的flakeyness实际上在Vista中得到了修复,你仍然在XP上运行,所以你看不到它。放置阴影在Aero桌面上的方式有所不同,是否启用阴影是一种系统设置。因此,在Aero上使用该属性是完全无效的

这些ToolStripItem类错误在.NET2.0发布后没有得到修复,大约整个Winforms团队都转移到了WPF组。而且他们现在肯定没有得到修复,在connect.microsoft.com上提交bug毫无意义,尽管你可以这样做

由于该属性现在是一个系统设置,因此不能再对更高版本的Windows产生影响,因此,在这里,唯一合乎逻辑的做法就是认输。不要更改属性