FormTest.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System;
  2. using System.Windows.Forms;
  3. // Test basic functionality of the Application and Form class
  4. class FormTest : Form {
  5. Label label;
  6. Button button;
  7. public FormTest () : base ()
  8. {
  9. label = new Label ();
  10. label.Top = 50;
  11. label.Left = 10;
  12. label.Width = 50;
  13. label.Height = 50;
  14. label.Parent = this;
  15. label.Text = "Label";
  16. button = new Button ();
  17. button.Top = 50;
  18. button.Left = 120;
  19. button.Width = 50;
  20. button.Height = 50;
  21. button.Parent = this;
  22. button.Text = "Button";
  23. }
  24. // - verifies the WndProc can be overridden propery
  25. // - verifies the Application.MessageLoop is working properly
  26. protected override void WndProc (ref Message m)
  27. {
  28. base.WndProc (ref m);
  29. // should be true after the Run command is reached
  30. Console.WriteLine ("Application.MessageLoop: " +
  31. Application.MessageLoop);
  32. }
  33. public class MouseMoveMessageFilter : IMessageFilter {
  34. public bool PreFilterMessage(ref Message m)
  35. {
  36. Console.WriteLine ("PreFilter(ing) message");
  37. if (m.Msg == Win32.WM_MOUSEMOVE) {
  38. Console.WriteLine ("captured mousemove");
  39. return true;
  40. }
  41. return false;
  42. }
  43. }
  44. static public void Test1 ()
  45. {
  46. MessageBox.Show ("test derived form");
  47. FormTest form = new FormTest ();
  48. MouseMoveMessageFilter f = new MouseMoveMessageFilter();
  49. Application.AddMessageFilter (f);
  50. // should be false
  51. Console.WriteLine ("Application.MessageLoop: " +
  52. Application.MessageLoop);
  53. Application.Run (form);
  54. Application.RemoveMessageFilter (f);
  55. }
  56. static public void Test2 ()
  57. {
  58. MessageBox.Show ("test non-derived form, ctrl-c from console to quit");
  59. Form form = new Form ();
  60. form.Show ();
  61. Application.DoEvents ();
  62. Application.Run ();
  63. }
  64. static public int Main (String[] args)
  65. {
  66. Test1();
  67. //Test2();
  68. return 0;
  69. }
  70. }