ボタンの列を含むフォームを作成したいと思います。ボタンはすべての幅のフォームに収まる必要があります。また、私は可能な限りフォームの上にそれをプッシュしたい。設定ボタンは、WinForms内のすべての幅と親の上に塗りつぶします
通常、私はC++/Qtで動作し、レイアウトは豊富です。私は理解しているので、C#はあまり良くありません。私は、1列のTableLayoutPanel
がそれを行うことができることを発見しました。私が欲しいのは、すべてのボタンを一番上に押すことだけです。 だから私は、次のコードを作成しました:
// panelButton was created by VS with following params:
this.panelButton = new System.Windows.Forms.TableLayoutPanel();
this.panelButton.Dock = System.Windows.Forms.DockStyle.Fill;
this.panelButton.Name = "panelButton";
this.panelButton.RowCount = 1;
for(int i = 0;i < 3;i ++)
{
Button button = new Button();
button.Dock = DockStyle.Fill;
button.Height = 40;
button.Text = "Button" + i;
button.Click += new EventHandler(delegate(object o, EventArgs args) {});
panelButton.Controls.Add(button, 0, i);
}
をしかし、私は取得レイアウトが間違っている - 予想通りbutton0
とbutton1
は40ピクセルの高さですが、私はそれが40ピクセルになります期待していたときにbutton2
は、すべての空間を満たします。
追加:回避策が見つかりました。私はループの後に
panelButton.Controls.Add(new Control(), 0, rowIndex);
を追加し、期待どおりに動作します。
セットの '' button.Dock' System.Windows.Forms.DockStyle.Top' –
へちなみに、レイアウトは 'C# 'とは関係がありません.Windows FormsとWPFのようなUIフレームワークの両方がうまく動作します。 –
@RezaAghaeiも、動作しません。すべてのボタンの高さは40ピクセルですが、レイアウトの高さは増加しません。すべてのボタンの高さ>パネルの高さでスクロールバーを追加する場合 – folibis