简体   繁体   中英

ToolStripDropDownButton right aligned showing up outside application's window

During working on my project I came across strange problem. When I do a right alignment of ToolStripDropDownButton in the ToolStrip of my application then it appears outside of my window. Even fullscreened it shows up on my second monitor. I thought that I was a window's worry to align menus properly but it seems that I'm wrong. I use Windows Forms.

Here's what I am talking about. Here's a snipped generating similar problem.

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

Is there a way to force Windows to draw this menu to the left?

在此处输入图片说明

Just set the DropDownDirection on the button to control how the drop down menu aligns with the button. I think BelowLeft is the one you are looking for

toolStripDropDownButton1.DropDownDirection = ToolStripDropDownDirection.BelowLeft;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM