Generic.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #nullable enable
  2. using Terminal.Gui;
  3. namespace UICatalog.Scenarios;
  4. [ScenarioMetadata ("Generic", "Generic sample - A template for creating new Scenarios")]
  5. [ScenarioCategory ("Controls")]
  6. public sealed class Generic : Scenario
  7. {
  8. public override void Main ()
  9. {
  10. // Init
  11. Application.Init ();
  12. // Setup - Create a top-level application window and configure it.
  13. Window appWindow = new ()
  14. {
  15. Title = GetQuitKeyAndName (),
  16. BorderStyle = LineStyle.None
  17. };
  18. var button = new Shortcut()
  19. {
  20. CanFocus = true,
  21. Id = "button",
  22. X = Pos.Center (),
  23. Y = 1,
  24. ShadowStyle = ShadowStyle.None,
  25. Text = "HelpText",
  26. Title = "Command",
  27. Key = Key.F10,
  28. HighlightStyle = HighlightStyle.None
  29. };
  30. button.ColorScheme = Colors.ColorSchemes ["Error"];
  31. button.Padding!.Thickness = new (1);
  32. button.Padding.ColorScheme = Colors.ColorSchemes ["Toplevel"];
  33. button.Margin!.Thickness = new (1);
  34. button.Accepting += (s, e) =>
  35. {
  36. // When Accepting is handled, set e.Handled to true to prevent further processing.
  37. e.Handled = true;
  38. MessageBox.ErrorQuery ("Error", "You pressed the button!", "_Ok");
  39. };
  40. appWindow.Add (button);
  41. // Run - Start the application.
  42. Application.Run (appWindow);
  43. appWindow.Dispose ();
  44. // Shutdown - Calling Application.Shutdown is required.
  45. Application.Shutdown ();
  46. }
  47. }