TimeAndDate.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using Terminal.Gui;
  3. namespace UICatalog {
  4. [ScenarioMetadata (Name: "Time And Date", Description: "Illustrates TimeField and time & date handling")]
  5. [ScenarioCategory ("Controls")]
  6. [ScenarioCategory ("Bug Repro")] // Issue #246
  7. class TimeAndDate : Scenario {
  8. public override void Setup ()
  9. {
  10. var longTime = new TimeField (DateTime.Now) {
  11. X = Pos.Center (),
  12. Y = 2,
  13. IsShortFormat = false,
  14. ReadOnly = false,
  15. };
  16. Win.Add (longTime);
  17. var shortTime = new TimeField (DateTime.Now) {
  18. X = Pos.Center (),
  19. Y = Pos.Bottom(longTime) + 1,
  20. IsShortFormat = true,
  21. ReadOnly = false,
  22. };
  23. Win.Add (shortTime);
  24. var shortDate = new DateField (DateTime.Now) {
  25. X = Pos.Center (),
  26. Y = Pos.Bottom (shortTime) + 1,
  27. IsShortFormat = true,
  28. ReadOnly = true,
  29. };
  30. Win.Add (shortDate);
  31. var longDate = new DateField (DateTime.Now) {
  32. X = Pos.Center (),
  33. Y = Pos.Bottom (shortDate) + 1,
  34. IsShortFormat = false,
  35. ReadOnly = true,
  36. };
  37. Win.Add (longDate);
  38. Win.Add (new Button ("Swap Long/Short & Read/Read Only") {
  39. X = Pos.Center (),
  40. Y = Pos.Bottom (Win) - 5,
  41. Clicked = () => {
  42. longTime.ReadOnly = !longTime.ReadOnly;
  43. shortTime.ReadOnly = !shortTime.ReadOnly;
  44. longTime.IsShortFormat = !longTime.IsShortFormat;
  45. shortTime.IsShortFormat = !shortTime.IsShortFormat;
  46. longDate.ReadOnly = !longDate.ReadOnly;
  47. shortDate.ReadOnly = !shortDate.ReadOnly;
  48. longDate.IsShortFormat = !longDate.IsShortFormat;
  49. shortDate.IsShortFormat = !shortDate.IsShortFormat;
  50. }
  51. });
  52. }
  53. }
  54. }