SplitContainerExample.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. using Terminal.Gui;
  2. using System;
  3. using Terminal.Gui.Graphs;
  4. namespace UICatalog.Scenarios {
  5. [ScenarioMetadata (Name: "Split Container", Description: "Demonstrates the SplitContainer functionality")]
  6. [ScenarioCategory ("Controls")]
  7. public class SplitContainerExample : Scenario {
  8. private SplitContainer splitContainer;
  9. private MenuItem miVertical;
  10. /// <summary>
  11. /// Setup the scenario.
  12. /// </summary>
  13. public override void Setup ()
  14. {
  15. // Scenario Window's.
  16. Win.Title = this.GetName ();
  17. Win.Y = 1;
  18. splitContainer = new SplitContainer {
  19. Width = Dim.Fill (),
  20. Height = Dim.Fill (),
  21. SplitterDistance = Pos.Percent(50),
  22. };
  23. Label lbl1;
  24. splitContainer.Panel1.Add (new Label ("Hello"));
  25. splitContainer.Panel1.Add (lbl1 = new Label ("Type Something:"){Y=2});
  26. splitContainer.Panel1.Add (new TextField (){Width = Dim.Fill(),Y=2,X=Pos.Right(lbl1)+1});
  27. Label lbl2;
  28. splitContainer.Panel2.Add (new Label ("World"));
  29. splitContainer.Panel2.Add (lbl2 = new Label ("Type Here Too:"){Y=2});
  30. splitContainer.Panel2.Add (new TextField (){Width = Dim.Fill(),Y=2,X=Pos.Right(lbl2)+1});
  31. Win.Add (splitContainer);
  32. var menu = new MenuBar (new MenuBarItem [] {
  33. new MenuBarItem ("_File", new MenuItem [] {
  34. new MenuItem ("_Quit", "", () => Quit()),
  35. }),
  36. new MenuBarItem ("_Options", new MenuItem [] {
  37. miVertical = new MenuItem ("_Vertical", "", () => ToggleOrientation())
  38. {
  39. Checked = splitContainer.Orientation == Orientation.Vertical,
  40. CheckType = MenuItemCheckStyle.Checked
  41. }})
  42. });
  43. Application.Top.Add (menu);
  44. }
  45. public void ToggleOrientation()
  46. {
  47. miVertical.Checked = !miVertical.Checked;
  48. splitContainer.Orientation = miVertical.Checked ? Orientation.Vertical : Orientation.Horizontal;
  49. }
  50. private void Quit ()
  51. {
  52. Application.RequestStop ();
  53. }
  54. }
  55. }