Program.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using ConFrames;
  7. namespace Sample
  8. {
  9. class Window1 : Window
  10. {
  11. public Window1() :base("Window 1", new Rect(0, 0, 100, 20))
  12. {
  13. }
  14. public override void OnPaint(PaintContext ctx)
  15. {
  16. for (int i=0; i<20; i++)
  17. {
  18. ctx.WriteLine("This is line {0}", i + 1);
  19. }
  20. }
  21. }
  22. class Window2 : Window
  23. {
  24. public Window2() : base("Window 2", new Rect(0, 20, 100, 20))
  25. {
  26. CursorVisible = true;
  27. CursorX = 5;
  28. CursorY = 1;
  29. }
  30. public override void OnPaint(PaintContext ctx)
  31. {
  32. ctx.WriteLine("Type something, or use Ctrl+Tab to switch windows");
  33. ctx.Write("blah>");
  34. }
  35. public override bool OnKey(ConsoleKeyInfo key)
  36. {
  37. if (key.KeyChar != 0)
  38. {
  39. var ctx = GetPaintContext();
  40. ctx.SetChar(CursorX++, CursorY, key.KeyChar);
  41. }
  42. else
  43. {
  44. switch (key.Key)
  45. {
  46. case ConsoleKey.LeftArrow:
  47. if (CursorX > 0)
  48. CursorX--;
  49. break;
  50. case ConsoleKey.RightArrow:
  51. if (CursorX < ClientSize.Width)
  52. CursorX++;
  53. break;
  54. }
  55. }
  56. return base.OnKey(key);
  57. }
  58. }
  59. class Program
  60. {
  61. static void Main(string[] args)
  62. {
  63. var desktop = new Desktop(100, 40);
  64. var w1 = new Window1();
  65. var w2 = new Window2();
  66. w1.Open(desktop);
  67. w2.Open(desktop);
  68. desktop.Process();
  69. }
  70. }
  71. }