Generic.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. using Terminal.Gui;
  2. namespace UICatalog.Scenarios;
  3. [ScenarioMetadata ("Generic", "Generic sample - A template for creating new Scenarios")]
  4. [ScenarioCategory ("Controls")]
  5. public sealed class MyScenario : Scenario
  6. {
  7. public override void Main ()
  8. {
  9. // Init
  10. Application.Init ();
  11. // Setup - Create a top-level application window and configure it.
  12. Window appWindow = new ()
  13. {
  14. Title = $"{Application.QuitKey} to Quit - Scenario: {GetName ()}"
  15. };
  16. int leftMargin = 0;
  17. var just = Justification.Justified;
  18. var button = new Button { X = Pos.Justify(just), Y = Pos.Center (), Text = "Press me!" };
  19. button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed the button!", "Ok");
  20. appWindow.Add (button);
  21. button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Two" };
  22. button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
  23. button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Two!", "Ok");
  24. appWindow.Add (button);
  25. button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Three" };
  26. button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
  27. button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  28. appWindow.Add (button);
  29. button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Four" };
  30. button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
  31. button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  32. appWindow.Add (button);
  33. button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Five" };
  34. button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
  35. button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  36. appWindow.Add (button);
  37. button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Six" };
  38. button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
  39. button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  40. appWindow.Add (button);
  41. button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Seven" };
  42. button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
  43. button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  44. appWindow.Add (button);
  45. button = new Button { X = Pos.Justify (just), Y = Pos.Center (), Text = "Eight" };
  46. button.Margin.Thickness = new Thickness (leftMargin, 0, 0, 0);
  47. button.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  48. appWindow.Add (button);
  49. just = Justification.FirstLeftRestRight;
  50. var checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "Check boxes!" };
  51. checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed the checkbox!", "Ok");
  52. appWindow.Add (checkbox);
  53. checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckTwo" };
  54. checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Two!", "Ok");
  55. appWindow.Add (checkbox);
  56. checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckThree" };
  57. checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  58. appWindow.Add (checkbox);
  59. checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckFour" };
  60. checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  61. appWindow.Add (checkbox);
  62. checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckFive" };
  63. checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  64. appWindow.Add (checkbox);
  65. checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckSix" };
  66. checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  67. appWindow.Add (checkbox);
  68. checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckSeven" };
  69. checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  70. appWindow.Add (checkbox);
  71. checkbox = new CheckBox { X = 5, Y = Pos.Justify (just), Text = "CheckEight" };
  72. checkbox.Accept += (s, e) => MessageBox.ErrorQuery ("Error", "You pressed Three!", "Ok");
  73. appWindow.Add (checkbox);
  74. // Run - Start the application.
  75. Application.Run (appWindow);
  76. appWindow.Dispose ();
  77. // Shutdown - Calling Application.Shutdown is required.
  78. Application.Shutdown ();
  79. }
  80. }