Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/301.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
C# ToolStripDropDownButton右对齐显示在应用程序外部';窗户_C#_Winforms - Fatal编程技术网

C# ToolStripDropDownButton右对齐显示在应用程序外部';窗户

C# ToolStripDropDownButton右对齐显示在应用程序外部';窗户,c#,winforms,C#,Winforms,在我的项目中,我遇到了一个奇怪的问题。当我在应用程序的ToolStrip中右对齐ToolStripDropDownButton时,它会出现在我的窗口之外。甚至全屏显示在我的第二个显示器上。我以为我是一个窗口的担心,以调整菜单正确,但似乎我错了。我使用Windows窗体 这就是我要说的。 这是一个产生类似问题的剪报 partial class Form2 { /// <summary> /// Required designer variable. /// &l

在我的项目中,我遇到了一个奇怪的问题。当我在应用程序的ToolStrip中右对齐ToolStripDropDownButton时,它会出现在我的窗口之外。甚至全屏显示在我的第二个显示器上。我以为我是一个窗口的担心,以调整菜单正确,但似乎我错了。我使用Windows窗体

这就是我要说的。 这是一个产生类似问题的剪报

partial class Form2
{
    /// <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(Form2));
        this.toolStrip1 = new System.Windows.Forms.ToolStrip();
        this.toolStripDropDownButton1 = new System.Windows.Forms.ToolStripDropDownButton();
        this.itemToolStripMenuItem = 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(763, 25);
        this.toolStrip1.TabIndex = 0;
        this.toolStrip1.Text = "toolStrip1";
        // 
        // toolStripDropDownButton1
        // 
        this.toolStripDropDownButton1.Alignment = System.Windows.Forms.ToolStripItemAlignment.Right;
        this.toolStripDropDownButton1.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Text;
        this.toolStripDropDownButton1.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
        this.itemToolStripMenuItem});
        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(30, 22);
        this.toolStripDropDownButton1.Text = "\\/";
        // 
        // itemToolStripMenuItem
        // 
        this.itemToolStripMenuItem.Name = "itemToolStripMenuItem";
        this.itemToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
        this.itemToolStripMenuItem.Text = "Item";
        // 
        // Form2
        // 
        this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
        this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
        this.ClientSize = new System.Drawing.Size(763, 612);
        this.Controls.Add(this.toolStrip1);
        this.Name = "Form2";
        this.Text = "Form2";
        this.toolStrip1.ResumeLayout(false);
        this.toolStrip1.PerformLayout();
        this.ResumeLayout(false);
        this.PerformLayout();

    }

    #endregion

    public Form2()
    {
        InitializeComponent();
    }

    private System.Windows.Forms.ToolStrip toolStrip1;
    private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
    private System.Windows.Forms.ToolStripMenuItem itemToolStripMenuItem;
}
部分类表单2
{
/// 
///必需的设计器变量。
/// 
private System.ComponentModel.IContainer components=null;
/// 
///清理所有正在使用的资源。
/// 
///如果应释放托管资源,则为true;否则为false。
受保护的覆盖无效处置(布尔处置)
{
if(处理和(组件!=null))
{
组件。Dispose();
}
基地。处置(处置);
}
#区域Windows窗体设计器生成的代码
/// 
///设计器支持所需的方法-不修改
///此方法的内容与代码编辑器一起使用。
/// 
私有void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager资源=新的System.ComponentModel.ComponentResourceManager(typeof(Form2));
this.toolStrip1=new System.Windows.Forms.ToolStrip();
this.toolStripDropDownButton1=新系统.Windows.Forms.ToolStripDropDownButton();
this.itemToolStripMenuItem=new 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=新系统图纸尺寸(763,25);
this.toolStrip1.TabIndex=0;
this.toolStrip1.Text=“toolStrip1”;
// 
//toolStripDropDownButton1
// 
this.toolStripDropDownButton1.Alignment=System.Windows.Forms.ToolStripItemAlignment.Right;
this.toolStripDropDownButton1.DisplayStyle=System.Windows.Forms.ToolStripItemDisplayStyle.Text;
此.toolStripDropDownButton1.DropDownItems.AddRange(新的System.Windows.Forms.ToolStripItem[]{
此参数为.itemToolStripMenuItem});
this.toolStripDropDownButton1.Image=((System.Drawing.Image)(resources.GetObject(“toolStripDropDownButton1.Image”));
this.toolStripDropDownButton1.ImageTransparentColor=System.Drawing.Color.Magenta;
this.toolStripDropDownButton1.Name=“toolStripDropDownButton1”;
this.toolStripDropDownButton1.Size=新系统图尺寸(30,22);
this.toolStripDropDownButton1.Text=“\\/”;
// 
//itemToolStripMenuItem
// 
this.itemToolStripMenuItem.Name=“itemToolStripMenuItem”;
this.itemToolStripMenuItem.Size=新系统.Drawing.Size(152,22);
this.itemToolStripMenuItem.Text=“Item”;
// 
//表格2
// 
此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize=新系统.Drawing.Size(763612);
this.Controls.Add(this.toolStrip1);
this.Name=“Form2”;
this.Text=“Form2”;
此.toolStrip1.ResumeLayout(false);
this.toolStrip1.PerformLayout();
此选项为.resume布局(false);
这个。执行布局();
}
#端区
公共表格2()
{
初始化组件();
}
private System.Windows.Forms.ToolStrip toolStrip1;
private System.Windows.Forms.ToolStripDropDownButton toolStripDropDownButton1;
private System.Windows.Forms.ToolStripMenuItem ToolStripMenuItem;
}
有没有办法强制Windows将此菜单绘制到左侧


只需在按钮上设置
下拉方向
,即可控制下拉菜单如何与按钮对齐。我想下面就是你要找的那个

toolStripDropDownButton1.DropDownDirection = ToolStripDropDownDirection.BelowLeft;

是的,我知道,但我一直在寻找更普遍的解决方案。自动调整此下拉列表位置的功能。如果按钮本身是右对齐的,则始终位于左下方似乎是明智的。如果按钮在toolstrip中浮动,并且有时仅在右端,那么我认为您唯一的解决方案是在下拉打开期间检查按钮的实际右坐标,并调整下拉位置以适应。