//================================================================================================= // パネル(テーブルレイアウトパネル) // テーブルレイアウトを使用したボタンを表示したプログラム。 // テーブルレイアウトを使用すると、縦横のコントロールの数を決めて格子状にコントロールを並べること // が可能になる。 // // // // 参考文献:やさしいC#(p168) // 2012/11/13/オワタ //================================================================================================= using System; using System.Windows.Forms; class Panel : Form { private Button[] mButton = new Button[6]; //< ボタン * 6 private TableLayoutPanel mTlt; //< テーブルレイアウト //< メイン関数 public static void Main() { Application.Run(new Panel()); } //< コンストラクタ public Panel() { //< Windowの生成 設定 this.Text = "テーブルレイアウト"; this.Width = 300; this.Height = 200; //< テーブルレイアウトパネル生成 設定 mTlt = new TableLayoutPanel(); mTlt.Dock = DockStyle.Fill; //< ドッキング設定 mTlt.ColumnCount = 3; //< コントロール列設定(3列) mTlt.RowCount = 2; //< コントロール行設定(2行) //< ボタンの生成 設定 for (int i = 0; i < mButton.Length; i++) { mButton[i] = new Button(); mButton[i].Text = Convert.ToString(i); mButton[i].Parent = mTlt; } mTlt.Parent = this; } };