MenuTest.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Windows.Forms;
  3. // Test basic functionality of the Application and Form class
  4. class MenuTest : Form {
  5. Button button;
  6. MainMenu testMenu_ = null;
  7. public MenuTest () : base ()
  8. {
  9. CreateMyMainMenu();
  10. button = new Button ();
  11. button.Top = 20;
  12. button.Left = 20;
  13. button.Width = 50;
  14. button.Height = 50;
  15. button.Parent = this;
  16. button.Text = "Menu";
  17. button.Click += new EventHandler(OnMenuButtonClick);
  18. }
  19. // Doesn't gets called, waiting for Button implementation
  20. void OnMenuButtonClick( object c, EventArgs e)
  21. {
  22. if( Menu != null) {
  23. Menu = null;
  24. }
  25. else {
  26. Menu = testMenu_;
  27. }
  28. }
  29. public void CreateMyMainMenu()
  30. {
  31. testMenu_ = new MainMenu();
  32. MenuItem menuItem1 = new MenuItem();
  33. MenuItem menuItem2 = new MenuItem();
  34. MenuItem menuItem3 = new MenuItem();
  35. menuItem1.Text = "&File";
  36. menuItem2.Text = "&Edit";
  37. menuItem3.Text = "E&xit";
  38. testMenu_.MenuItems.Add(menuItem1);
  39. testMenu_.MenuItems.Add(menuItem2);
  40. testMenu_.MenuItems.Add(menuItem3);
  41. Menu = testMenu_;
  42. }
  43. // - verifies the WndProc can be overridden propery
  44. // - verifies the Application.MessageLoop is working properly
  45. protected override void WndProc (ref Message m)
  46. {
  47. base.WndProc (ref m);
  48. // should be true after the Run command is reached
  49. //Console.WriteLine ("Application.MessageLoop: " +
  50. //Application.MessageLoop);
  51. }
  52. static public void Test1 ()
  53. {
  54. MenuTest form = new MenuTest ();
  55. //should be false
  56. Console.WriteLine ("Application.MessageLoop: " +
  57. Application.MessageLoop);
  58. Application.Run (form);
  59. }
  60. static public int Main (String[] args)
  61. {
  62. Test1();
  63. return 0;
  64. }
  65. }