Program.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using Terminal.Gui;
  3. using Attribute = Terminal.Gui.Attribute;
  4. namespace Designer {
  5. class Surface : Window {
  6. public Surface () : base ("Designer")
  7. {
  8. }
  9. }
  10. class MainClass {
  11. static void Close ()
  12. {
  13. MessageBox.ErrorQuery (50, 7, "Error", "There is nothing to close", "Ok");
  14. }
  15. static void Copy ()
  16. {
  17. TextField textField = menu.LastFocused as TextField;
  18. if (textField != null && textField.SelectedLength != 0) {
  19. textField.Copy ();
  20. }
  21. }
  22. static void Cut ()
  23. {
  24. TextField textField = menu.LastFocused as TextField;
  25. if (textField != null && textField.SelectedLength != 0) {
  26. textField.Cut ();
  27. }
  28. }
  29. static void Paste ()
  30. {
  31. TextField textField = menu.LastFocused as TextField;
  32. if (textField != null) {
  33. textField.Paste ();
  34. }
  35. }
  36. public static MenuBar menu;
  37. public static void Main (string [] args)
  38. {
  39. Application.Init ();
  40. menu = new MenuBar (new MenuBarItem [] {
  41. new MenuBarItem ("_File", new MenuItem [] {
  42. new MenuItem ("_Close", "", () => Close ()),
  43. new MenuItem ("_Quit", "", () => { Application.RequestStop (); })
  44. }),
  45. new MenuBarItem ("_Edit", new MenuItem [] {
  46. new MenuItem ("_Copy", "", Copy),
  47. new MenuItem ("C_ut", "", Cut),
  48. new MenuItem ("_Paste", "", Paste)
  49. }),
  50. });
  51. var login = new Label ("Login: ") { X = 3, Y = 6 };
  52. var password = new Label ("Password: ") {
  53. X = Pos.Left (login),
  54. Y = Pos.Bottom (login) + 1
  55. };
  56. var test = new Label ("Test: ") {
  57. X = Pos.Left (login),
  58. Y = Pos.Bottom (password) + 1
  59. };
  60. var surface = new Surface () {
  61. X = 0,
  62. Y = 1,
  63. Width = Dim.Percent (50),
  64. Height = Dim.Percent (50)
  65. };
  66. var loginText = new TextField("") {
  67. X = Pos.Right(password),
  68. Y = Pos.Top(login),
  69. Width = Dim.Percent(90),
  70. ColorScheme = new ColorScheme() {
  71. Focus = Attribute.Make(Color.BrightYellow, Color.DarkGray),
  72. Normal = Attribute.Make(Color.Green, Color.BrightYellow),
  73. HotFocus = Attribute.Make(Color.BrightBlue, Color.Brown),
  74. HotNormal = Attribute.Make(Color.Red, Color.BrightRed),
  75. },
  76. };
  77. loginText.MouseEnter += LoginText_MouseEnter;
  78. loginText.MouseLeave += LoginText_MouseLeave;
  79. loginText.Enter += LoginText_Enter;
  80. loginText.Leave += LoginText_Leave;
  81. var passText = new TextField ("") {
  82. Secret = true,
  83. X = Pos.Left (loginText),
  84. Y = Pos.Top (password),
  85. Width = Dim.Width (loginText)
  86. };
  87. var testText = new TextField ("") {
  88. X = Pos.Left (loginText),
  89. Y = Pos.Top (test),
  90. Width = Dim.Width (loginText)
  91. };
  92. surface.Add (login, password, test, loginText, passText, testText);
  93. Application.Top.Add (menu, surface);
  94. Application.Run ();
  95. }
  96. private static void LoginText_Leave (object sender, EventArgs e)
  97. {
  98. ((TextField)sender).Text = $"Leaving from: {sender}";
  99. }
  100. private static void LoginText_Enter (object sender, EventArgs e)
  101. {
  102. ((TextField)sender).Text = $"Entering in: {sender}";
  103. }
  104. private static void LoginText_MouseLeave (object sender, MouseEvent e)
  105. {
  106. ((TextField)sender).Text = $"Mouse leave at X: {e.X}; Y: {e.Y} HasFocus: {e.View.HasFocus}";
  107. }
  108. private static void LoginText_MouseEnter (object sender, MouseEvent e)
  109. {
  110. ((TextField)sender).Text = $"Mouse enter at X: {e.X}; Y: {e.Y} HasFocus: {e.View.HasFocus}";
  111. }
  112. }
  113. }