我已经编写了UserControl
,其中包含Panel
控件中的两个按钮。而且,我有几种形式。我想找到这UserControl
形式和码头底部。
问题是,按钮对齐到右侧。我想离开。这个怎么做。
PS。我正在使用DevExpress,但没有必要。谢谢。面板控制中的对齐按钮
回答
我这里还有一些解决方案可能是最佳的,但我的作品
- 1 - 你可以在一个独立的小面板各按钮并更改 它的填充和停靠,这些拖板父面板
- 2-你可以使用简单的分隔符,并将其颜色设置为 父面板的颜色(并将它们停靠在右边)>>从右到左:按钮分割按钮。
对于winforms AFAIK中的每个控件都有一个名为dock的属性。用它。 或者您可以使用此用户控件的X和Y位置值进行设置。但是在调整窗体大小时,还必须重新定位控件。
如果我用码头的每一个控制,那么它们粘在一起。 – user348173
我相信你也可以使用dock来实现特定的控制。那么为什么每1?你只是希望底部的那些按钮在右侧对齐? – Zenwalker
是的。但在这种情况下不能在按钮之间设置空间。 – user348173
我会把按钮放在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();
}
}
}
- 1. MPMoviePlayer默认控制按钮未对齐
- 2. 用户控制面板和按钮
- 3. 为什么不在堆叠面板中水平对齐按钮?
- 4. 在页面中水平对齐按钮
- 5. 对齐按钮
- 6. 按钮对齐
- 7. 如何在面板底部对齐不同尺寸的按钮?
- 8. PyQt4中的对齐按钮
- 9. WPF GroupBox控件标头按钮和文本对齐对面
- 10. 控制在堆栈面板中未对齐
- 11. 音乐播放器像通知面板中的控制按钮
- 12. 页面控制按钮
- 13. 如何将按钮与更新面板对齐
- 14. 按钮水平面板不想右对齐
- 15. ASP.net - 中心对齐面板?
- 16. 中心对齐表+按钮
- 17. 对齐按钮到中心
- 18. 控制对齐
- 19. 对齐控制
- 20. 显示按钮右侧对齐下面
- 21. Python按钮对齐
- 22. 对齐按钮DIV
- 23. Wpf对齐按钮
- 24. ExtJS按钮对齐
- 25. Android按钮对齐
- 26. 如何控制按钮加载面板中点击
- 27. 按钮位于按钮中心的对齐按钮iOS
- 28. 如何水平对齐动态大小的面板中的按钮
- 29. 如何对齐windows phone 7中的堆叠面板上的按钮?
- 30. java BoxLayout面板的对齐
好的解决方案。谢谢。我会尝试。 – user348173