Windows  ソフトを  作つくって  みよう!

サンプル  プログラム 1

 

 1: using System;

 2: using System.Windows.Forms;

 3:

 4: class Hello: Form

 5: {

 6:   public static void Main()

 7:   {

 8:     Hello hw = new Hello();

 9:     Application.Run(hw);

10:   }

11: }

  

サンプル  プログラム 2

 

 1: using System;

 2: using System.Windows.Forms;

 3:

 4: class Hello: Form

 5: {

 6:   public static void Main()

 7:   {

 8:     Hello hw = new Hello();

 9:     hw.Text = "Hello, world!";

10:     Application.Run(hw);

11:   }

12: }

  

サンプル  プログラム 3

 

 1: using System;

 2: using System.Windows.Forms;

 3:

 4: class Hello: Form

 5: {

 6:   public static void Main()

 7:   {

 8:     Hello hw = new Hello();

 9:     hw.Text = "アプリケーション名";

10:

11:     Button btn = new Button();

12:     btn.Parent = hw;

13:     btn.Text = "Push";

14:

15:     Application.Run(hw);

16:   }

17: }

  

サンプル  プログラム 4

 

 1: using System;

 2: using System.Windows.Forms;

 3:

 4: class Hello: Form

 5: {

 6:   static void btnOnClick(object sender, EventArgs e) 

 7:   {

 8:     MessageBox.Show("押おしたね!");

 9:   }

10:

11:   public static void Main()

12:   {

13:     Hello hw = new Hello();

14:     hw.Text = "アプリケーション名";

15:

16:     Button btn = new Button();

17:     btn.Parent = hw;

18:     btn.Text = "Push";

19:     btn.Click += new EventHandler(btnOnClick);

20:

21:     Application.Run(hw);

22:   }

23: }

  

サンプル  プログラム 5

 

 1: using System;

 2: using System.Drawing;

 3: using System.Windows.Forms;

 4:

 5: class Hello: Form

 6: {

 7:   static void btnOnClick(object sender, EventArgs e) 

 8:   {

 9:     MessageBox.Show("押おしたね!");

10:   }

11:

12:   public static void Main()

13:   {

14:     Hello hw = new Hello();

15:     hw.Text = "アプリケーション名";

16:

17:     TextBox box = new TextBox();

18:     box.Parent = hw;

19:     box.Text = "こんにちは";

20:

21:     Button btn = new Button();

22:     btn.Parent = hw;

23:     btn.Location = new Point(0, box.Height);

24:     btn.Text = "Push";

25:     btn.Click += new EventHandler(btnOnClick);

26:

27:     Application.Run(hw);

28:   }

29: }

  

サンプル  プログラム 6

 

 1: using System;

 2: using System.Drawing;

 3: using System.Windows.Forms;

 4:

 5: class Hello: Form

 6: {

 7:   static void btn1OnClick(object sender, EventArgs e)

 8:   {

 9:     MessageBox.Show("正解せいかい!");

10:   }

11:

12:   static void btn2OnClick(object sender, EventArgs e)

13:   {

14:     MessageBox.Show("残念ざんねん!");

15:   }

16:

17:   public static void Main()

18:   {

19:     Hello hw = new Hello();

20:     hw.Text = "アプリケーション名めい";

21:

22:     TextBox box = new TextBox();

23:     box.Parent = hw;

24:     box.Width = box.Width*2;

25:     box.Text = "茨城いばらきの  県庁けんちょう  所在地しょざいちは?";

26:

27:     Button btn1 = new Button();

28:     btn1.Parent = hw;

29:     btn1.Location = new Point(0, box.Height);

30:     btn1.Text = "水戸市みとし";

31:     btn1.Click += new EventHandler(btn1OnClick);

32:

33:     Button btn2 = new Button();

34:     btn2.Parent = hw;

35:     btn2.Location = new Point(0, box.Height + btn1.Height);

36:     btn2.Text = "つくば市し";

37:     btn2.Click += new EventHandler(btn2OnClick);

38:

39:     Application.Run(hw);

40:   }

41: }