ウィンドウについて
まずはGUIプログラミングの基盤となるウィンドウについて説明します。
.NET Frameworkにおいてウィンドウを表すクラスはFormです。
下記にウィンドウを表示するだけのサンプルコードです。
using System; using System.Drawing; using System.Windows.Forms; public class Sample { public static void Main(String[] args) { Application.Run(new Form()); } }
サンプルを実行するとウィンドウが表示されます。
上記のサンプルの場合、ウィンドウの設定を何も行っていないため全てデフォルトの設定になっています。
例えば、ウィンドウのサイズは縦幅300px、横幅300pxがデフォルト値になっています。
Formクラスの主なプロパティ
タイトル
ウィンドウのタイトルに表示する文字列を設定するにはTextプロパティを使用します。
using System; using System.Drawing; using System.Windows.Forms; public class Sample { public static void Main(String[] args) { Form f = new Form(); f.Text = "タイトル"; Application.Run(f); } }
サイズ
ウィンドウの幅を設定するにはWidthプロパティを、ウィンドウの高さを設定するにはHeightプロパティを使用します。
using System; using System.Drawing; using System.Windows.Forms; public class Sample { public static void Main(String[] args) { Form f = new Form(); f.Width = 500; f.Height = 400; Application.Run(f); } }