为什么tableLayoutPanel.Dock = DockStyle.Fill;
不起作用且tableLayoutPanel
未填充Form
中的所有可用空间?
如何扩展button.Text = "Button";
?
namespace Scalability
{
static class Program
{
/// <summary>
/// Главная точка входа для приложения.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
ViewForm viewForm = new ViewForm();
Application.Run(viewForm);
}
}
}
namespace Scalability.Forms
{
class ViewForm:Form
{
public ViewForm()
{
TableLayoutPanel tableLayoutPanel = new TableLayoutPanel();
Button button = new Button();
button.Text = "Button";
button.Dock = DockStyle.Fill;
Label label = new Label();
label.Text="Label";
label.Dock = DockStyle.Fill;
TextBox textBox = new TextBox();
textBox.Text = "textBox";
textBox.Dock = DockStyle.Fill;
tableLayoutPanel.Controls.Add(button, 0, 0);
tableLayoutPanel.Controls.Add(label, 0, 1);
tableLayoutPanel.Controls.Add(textBox, 1, 0);
tableLayoutPanel.Dock = DockStyle.Fill;
this.Controls.Add(tableLayoutPanel);
}
}
}
答案 0 :(得分:0)
配置RowStyles
的{{1}}以使其延长
TableLayoutPanel
答案 1 :(得分:0)
但确实有效。 :)
1)尝试将颜色附加到控件上。
Button button = new Button();
button.Text = "Button";
button.BackColor = Color.Orange;
button.Dock = DockStyle.Fill;
Label label = new Label();
label.Text = "Label";
label.BackColor = Color.Yellow;
label.Dock = DockStyle.Fill;
TextBox textBox = new TextBox();
textBox.Text = "textBox";
textBox.BackColor = Color.Green;
textBox.Dock = DockStyle.Fill;
现在您将看到控件完全按照您放置它们的方式使用整个窗口。所以按钮是col 0,第0行(左,上)。文本框为col 1,第0行(右,上)。标签是col 0,第1行(左下角)。 col 1行1中没有任何内容(右下角&#34;中心位置&#34;为空)。
如果向1,1添加按钮,它将在剩余空间中拉伸。喜欢这个
// Blue button.
Button bbutton = new Button();
bbutton.Text = "Button";
bbutton.BackColor = Color.Blue;
bbutton.Dock = DockStyle.Fill;
tableLayoutPanel.Controls.Add(button, 0, 0);
tableLayoutPanel.Controls.Add(label, 0, 1);
tableLayoutPanel.Controls.Add(textBox, 1, 0);
// We added this one.
tableLayoutPanel.Controls.Add(bbutton, 1, 1);
tableLayoutPanel.Dock = DockStyle.Fill;
所以你有它。