C# 面板控制中的对齐按钮

C# 面板控制中的对齐按钮,c#,winforms,devexpress,C#,Winforms,Devexpress,我已经编写了UserControl,其中包含面板中的两个按钮。我有几种形式。我想在表单中找到这个UserControl,并停靠在底部。 问题是按钮向右对齐。我想离开。如何做到这一点。 另外,我正在使用DevExpress,但这不是必需的。谢谢。winforms AFAIK中的每个控件都有一个名为dock的属性。使用它。 也可以使用此usercontrol的X和Y位置值来设置。但是在调整窗体大小时,您还必须重新定位控件。winforms AFAIK中的每个控件都有一个名为dock的属性。使用它。

我已经编写了
UserControl
,其中包含
面板中的两个按钮。我有几种形式。我想在表单中找到这个
UserControl
,并停靠在底部。
问题是按钮向右对齐。我想离开。如何做到这一点。

另外,我正在使用DevExpress,但这不是必需的。谢谢。

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

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

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

  • 1-您可以在单独的小面板中制作每个按钮并更改 它的填充和停靠这些拖曳面板到父面板
  • 2-您可以使用更简单的分隔符,并将其颜色设置为 父面板颜色(也将它们停靠在右侧)。>从右到左:按钮拆分器按钮

  • 这里有一些解决方案可能是最佳的,但我可以

  • 1-您可以在单独的小面板中制作每个按钮并更改 它的填充和停靠这些拖曳面板到父面板
  • 2-您可以使用更简单的分隔符,并将其颜色设置为 父面板颜色(也将它们停靠在右侧)。>从右到左:按钮拆分器按钮

  • 我会将按钮放在一行两列的tablelayoutpanel中,其中行高=自动调整大小,第一列的宽度为100%,第二列的宽度为自动调整大小。然后,我会将按钮添加到每个列,并将锚定设置为每个列的右上角

    我还提供了一个表单的代码

    表格C:

    using System;
    
    使用System.Collections.Generic; 使用系统组件模型; 使用系统数据; 使用系统图; 使用系统文本; 使用System.Windows.Forms

    命名空间Windows窗体应用程序8 { 公共部分类Form1:Form { private System.Windows.Forms.DataGridView dataGridView1; private System.Windows.Forms.TableLayoutPanel TableLayoutPanel 1; private System.Windows.Forms.Button按钮1; private System.Windows.Forms.Button按钮2

        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();
    
        }
    }
    
    public Form1()
    {
    初始化组件();
    }
    /// 
    ///设计器支持所需的方法-不修改
    ///此方法的内容与代码编辑器一起使用。
    /// 
    私有void InitializeComponent()
    {
    this.dataGridView1=new System.Windows.Forms.DataGridView();
    this.TableLayoutPanel 1=新系统.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();
    这个.SuspendLayout();
    // 
    //dataGridView1
    // 
    this.dataGridView1.columnHeadershightSizeMode=System.Windows.Forms.datagridviewColumnHeadershightSizeMode.AutoSize;
    this.dataGridView1.Dock=System.Windows.Forms.DockStyle.Fill;
    this.dataGridView1.Location=新系统.Drawing.Point(0,0);
    this.dataGridView1.Name=“dataGridView1”;
    this.dataGridView1.Size=新系统.Drawing.Size(620269);
    this.dataGridView1.TabIndex=0;
    // 
    //tableLayoutPanel1
    // 
    this.tableLayoutPanel1.AutoSize=true;
    this.tableLayoutPanel1.AutoSizeMode=System.Windows.Forms.AutoSizeMode.GrowtandShrink;
    this.tableLayoutPanel1.ColumnCount=2;
    this.tableLayoutPanel1.ColumnStyles.Add(新的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=新系统.Drawing.Point(0240);
    this.tableLayoutPanel1.Name=“tableLayoutPanel1”;
    this.tableLayoutPanel1.RowCount=1;
    this.tableLayoutPanel1.RowStyles.Add(new System.Windows.Forms.RowStyle());
    this.tableLayoutPanel1.Size=新系统图纸尺寸(620,29);
    this.tableLayoutPanel1.TabIndex=1;
    // 
    //按钮1
    // 
    this.button1.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right));
    此.button1.Location=新系统图纸点(542,3);
    this.button1.Name=“button1”;
    this.button1.Size=新系统图纸尺寸(75,23);
    this.button1.TabIndex=0;
    this.button1.Text=“button1”;
    this.button1.UseVisualStyleBackColor=true;
    // 
    //按钮2
    // 
    this.button2.Anchor=((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right));
    this.button2.Location=新系统图纸点(461,3);
    this.button2.Name=“button2”;
    this.button2.Size=新系统图纸尺寸(75,23);
    this.button2.TabIndex=1;
    this.button2.Text=“button2”;
    this.button2.UseVisualStyleBackColor=true;
    // 
    //表格1
    // 
    此.AutoScaleDimensions=新系统.Drawing.SizeF(6F,13F);
    this.AutoScaleMode=System.Windows.Forms.AutoScaleMode.Font;
    this.ClientSize=新系统图纸尺寸(620269);
    this.Controls.Add(this.tableLayoutPanel1);
    this.Controls.Add(this.dataGridView1);
    this.Name=“Form1”;
    this.Text=“Form1”;
    ((系统)