自动下推控制不起作用
Push down control automatically not working
前段时间我问了问题。我得到了答案,并且当时效果很好。但是现在,我正在尝试做同样的事情,但没有奏效。我有一个 Form
和一个 FlowLayoutPanel
以与答案相同的方式设置,但它不起作用。 Form
FLowLayoutPanel
已将 AutoSize
设置为 true 且 FlowDirection
已设置为 TopDown
但表单在垂直方向增长而没有按下 progressBar
控件和 label
本身。这是单击按钮几次后我的表单的样子(按钮的代码与 link 中接受的问题相同,我 linked):
我错过了什么?
好的,我已经测试了您之前 post 中建议的解决方案,它对我来说工作正常...
测试这些东西:
确保 Label 和 ProgressBar 都位于 FlowLayoutPanel 内
如果您的意思是它水平增长 <---->,则将 FlowLayoutPanel 的 MaximumSize-Width 设置为在切换到新行之前可以达到的宽度(并从那里增长而是垂直!)
否则请提供更多信息,以便我可以为您提供帮助。
试试这个,看看它是否有效!
public Form1()
{
InitializeComponent();
Size = new Size(400, 150);
AutoSize = true;
AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly;
FlowLayoutPanel panel = new FlowLayoutPanel();
panel.Size = new Size(200, 150);
panel.MaximumSize = new System.Drawing.Size(panel.Width, int.MaxValue);
panel.FlowDirection = FlowDirection.TopDown;
panel.AutoSize = true;
panel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly;
Controls.Add(panel);
Label label = new Label();
label.Text = "Starting text!\n";
label.Padding = new System.Windows.Forms.Padding(0, 0, 0, 50);
label.AutoSize = true;
panel.Controls.Add(label);
ProgressBar progressBar = new ProgressBar();
progressBar.Location = new Point(0, 125);
progressBar.Size = new Size(190, 25);
panel.Controls.Add(progressBar);
Button button = new Button();
button.Location = new Point(275, 50);
button.Text = "Click me!";
button.Click += (object sender, EventArgs e) => { label.Text += "some more text, "; };
Controls.Add(button);
}
前段时间我问了Form
和一个 FlowLayoutPanel
以与答案相同的方式设置,但它不起作用。 Form
FLowLayoutPanel
已将 AutoSize
设置为 true 且 FlowDirection
已设置为 TopDown
但表单在垂直方向增长而没有按下 progressBar
控件和 label
本身。这是单击按钮几次后我的表单的样子(按钮的代码与 link 中接受的问题相同,我 linked):
我错过了什么?
好的,我已经测试了您之前 post 中建议的解决方案,它对我来说工作正常... 测试这些东西:
确保 Label 和 ProgressBar 都位于 FlowLayoutPanel 内
如果您的意思是它水平增长 <---->,则将 FlowLayoutPanel 的 MaximumSize-Width 设置为在切换到新行之前可以达到的宽度(并从那里增长而是垂直!)
否则请提供更多信息,以便我可以为您提供帮助。
试试这个,看看它是否有效!
public Form1()
{
InitializeComponent();
Size = new Size(400, 150);
AutoSize = true;
AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly;
FlowLayoutPanel panel = new FlowLayoutPanel();
panel.Size = new Size(200, 150);
panel.MaximumSize = new System.Drawing.Size(panel.Width, int.MaxValue);
panel.FlowDirection = FlowDirection.TopDown;
panel.AutoSize = true;
panel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowOnly;
Controls.Add(panel);
Label label = new Label();
label.Text = "Starting text!\n";
label.Padding = new System.Windows.Forms.Padding(0, 0, 0, 50);
label.AutoSize = true;
panel.Controls.Add(label);
ProgressBar progressBar = new ProgressBar();
progressBar.Location = new Point(0, 125);
progressBar.Size = new Size(190, 25);
panel.Controls.Add(progressBar);
Button button = new Button();
button.Location = new Point(275, 50);
button.Text = "Click me!";
button.Click += (object sender, EventArgs e) => { label.Text += "some more text, "; };
Controls.Add(button);
}