Während der Arbeit an meinem Projekt stieß ich auf seltsames Problem. Wenn ich ToolStripDropDownButton im ToolStrip meiner Anwendung rechtsbündig anordne, erscheint es außerhalb meines Fensters. Sogar auf dem zweiten Bildschirm erscheint es. Ich dachte, dass ich ein Fenster sorge, um Menüs richtig auszurichten, aber es scheint, dass ich falsch liege. Ich benutze Windows Forms.ToolStripDropDownButton right aligned zeigt sich außerhalb des Fensters der Anwendung
Hier ist, worüber ich spreche. Hier ist ein Snipped Generierung ähnliches 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;
}
Gibt es eine Möglichkeit, um Windows zu zwingen, dieses Menü auf der linken Seite zu ziehen?
Ja, ich weiß darüber, aber ich war eher auf der Suche nach allgemeineren Lösung. Etwas, das den Standort dieses Drop-down automatisch anpassen würde. – greenshade
Wenn die Schaltfläche selbst rechtsbündig ausgerichtet ist, erscheint es sinnvoll, immer unter BelowLeft zu gehen. Wenn die Schaltfläche in einem Toolstrip schwebte und nur manchmal auf der rechten Seite war, dann wäre Ihre einzige Lösung, die tatsächliche Koordinate der Schaltfläche während der DropDownOpening zu überprüfen und die DropDownLocation entsprechend anzupassen. –