demo.cs 924 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Drawing;
  3. using System.Windows.Forms;
  4. class X {
  5. static void Clicked (object o, EventArgs args)
  6. {
  7. Console.WriteLine ("the button was clicked");
  8. }
  9. static void Demo_Window ()
  10. {
  11. Form form = new Form ();
  12. form.Text = "hello";
  13. Label l = new Label ();
  14. l.Location = new Point (20, 20);
  15. l.Text = "Hello world";
  16. form.Controls.Add (l);
  17. Button b = new Button ();
  18. b.Text = "a button";
  19. b.Location = new Point (20, 60);
  20. b.Click += new EventHandler (Clicked);
  21. form.Controls.Add (b);
  22. form.Visible = true;
  23. Application.Run ();
  24. }
  25. static void Demo_AppRun ()
  26. {
  27. Form form = new Form ();
  28. form.Text = "hello";
  29. Application.Run (form);
  30. }
  31. static void Main (string [] args)
  32. {
  33. string demo = "window";
  34. if (args.Length > 0)
  35. demo = args [0];
  36. switch (demo){
  37. case "window":
  38. Demo_Window ();
  39. break;
  40. case "app_run":
  41. Demo_AppRun ();
  42. break;
  43. }
  44. }
  45. }