2011-08-16 63 views
1

我已经编写了UserControl,其中包含Panel控件中的两个按钮。而且,我有几种形式。我想找到这UserControl形式和码头底部。
问题是,按钮对齐到右侧。我想离开。这个怎么做。
enter image description here PS。我正在使用DevExpress,但没有必要。谢谢。面板控制中的对齐按钮

回答

2

我这里还有一些解决方案可能是最佳的,但我的作品

  1. 1 - 你可以在一个独立的小面板各按钮并更改 它的填充和停靠,这些拖板父面板
  2. 2-你可以使用简单的分隔符,并将其颜色设置为 父面板的颜色(并将它们停靠在右边)>>从右到左:按钮分割按钮。
+0

好的解决方案。谢谢。我会尝试。 – user348173

2

对于winforms AFAIK中的每个控件都有一个名为dock的属性。用它。 或者您可以使用此用户控件的X和Y位置值进行设置。但是在调整窗体大小时,还必须重新定位控件。

+0

如果我用码头的每一个控制,那么它们粘在一起。 – user348173

+0

我相信你也可以使用dock来实现特定的控制。那么为什么每1?你只是希望底部的那些按钮在右侧对齐? – Zenwalker

+0

是的。但在这种情况下不能在按钮之间设置空间。 – user348173

1

我会把按钮放在1行2列tablelayoutnel中,行高= autosize,第一列的宽度是100%,第二列的宽度是自动调整的。然后,我会将按钮添加到每列,并将锚点设置在每个列的右上角。

我还为此提供了表单的代​​码。

Form.cs:

using System; 

使用System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text;使用System.Windows.Forms的 ;

命名空间WindowsFormsApplication8 { 公共部分Form1类:表格{ 私人 System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.TableLayoutPanel tableLayoutPanel1; private System.Windows.Forms.Button button1; private System.Windows.Forms.Button button2;

public Form1() 
    { 
     InitializeComponent(); 
    } 

    /// <summary> 
    /// Required method for Designer support - do not modify 
    /// the contents of this method with the code editor. 
    /// </summary> 
    private void InitializeComponent() 
    { 
     this.dataGridView1 = new System.Windows.Forms.DataGridView(); 
     this.tableLayoutPanel1 = new System.Windows.Forms.TableLayoutPanel(); 
     this.button1 = new System.Windows.Forms.Button(); 
     this.button2 = new System.Windows.Forms.Button(); 
     ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); 
     this.tableLayoutPanel1.SuspendLayout(); 
     this.SuspendLayout(); 
     // 
     // dataGridView1 
     // 
     this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; 
     this.dataGridView1.Dock = System.Windows.Forms.DockStyle.Fill; 
     this.dataGridView1.Location = new System.Drawing.Point(0, 0); 
     this.dataGridView1.Name = "dataGridView1"; 
     this.dataGridView1.Size = new System.Drawing.Size(620, 269); 
     this.dataGridView1.TabIndex = 0; 
     // 
     // tableLayoutPanel1 
     // 
     this.tableLayoutPanel1.AutoSize = true; 
     this.tableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; 
     this.tableLayoutPanel1.ColumnCount = 2; 
     this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 100F)); 
     this.tableLayoutPanel1.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); 
     this.tableLayoutPanel1.Controls.Add(this.button1, 1, 0); 
     this.tableLayoutPanel1.Controls.Add(this.button2, 0, 0); 
     this.tableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Bottom; 
     this.tableLayoutPanel1.Location = new System.Drawing.Point(0, 240); 
     this.tableLayoutPanel1.Name = "tableLayoutPanel1"; 
     this.tableLayoutPanel1.RowCount = 1; 
     this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle()); 
     this.tableLayoutPanel1.Size = new System.Drawing.Size(620, 29); 
     this.tableLayoutPanel1.TabIndex = 1; 
     // 
     // button1 
     // 
     this.button1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 
     this.button1.Location = new System.Drawing.Point(542, 3); 
     this.button1.Name = "button1"; 
     this.button1.Size = new System.Drawing.Size(75, 23); 
     this.button1.TabIndex = 0; 
     this.button1.Text = "button1"; 
     this.button1.UseVisualStyleBackColor = true; 
     // 
     // button2 
     // 
     this.button2.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 
     this.button2.Location = new System.Drawing.Point(461, 3); 
     this.button2.Name = "button2"; 
     this.button2.Size = new System.Drawing.Size(75, 23); 
     this.button2.TabIndex = 1; 
     this.button2.Text = "button2"; 
     this.button2.UseVisualStyleBackColor = true; 
     // 
     // Form1 
     // 
     this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 
     this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 
     this.ClientSize = new System.Drawing.Size(620, 269); 
     this.Controls.Add(this.tableLayoutPanel1); 
     this.Controls.Add(this.dataGridView1); 
     this.Name = "Form1"; 
     this.Text = "Form1"; 
     ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); 
     this.tableLayoutPanel1.ResumeLayout(false); 
     this.ResumeLayout(false); 
     this.PerformLayout(); 

    } 
} 

}