FormTest.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. public FormTest () : base ()
  7. {
  8. label = new Label ();
  9. label.Parent = this;
  10. label.Text = "Hello";
  11. }
  12. // - verifies the WndProc can be overridden propery
  13. // - verifies the Application.MessageLoop is working properly
  14. protected override void WndProc (ref Message m)
  15. {
  16. base.WndProc (ref m);
  17. // should be true after the Run command is reached
  18. Console.WriteLine ("Application.MessageLoop: " +
  19. Application.MessageLoop);
  20. }
  21. public class MouseMoveMessageFilter : IMessageFilter {
  22. public bool PreFilterMessage(ref Message m)
  23. {
  24. Console.WriteLine ("PreFilter(ing) message");
  25. if (m.Msg == Win32.WM_MOUSEMOVE) {
  26. Console.WriteLine ("captured mousemove");
  27. return true;
  28. }
  29. return false;
  30. }
  31. }
  32. static public void Test1 ()
  33. {
  34. MessageBox.Show ("test derived form");
  35. FormTest form = new FormTest ();
  36. MouseMoveMessageFilter f = new MouseMoveMessageFilter();
  37. Application.AddMessageFilter (f);
  38. // should be false
  39. Console.WriteLine ("Application.MessageLoop: " +
  40. Application.MessageLoop);
  41. Application.Run (form);
  42. Application.RemoveMessageFilter (f);
  43. }
  44. static public void Test2 ()
  45. {
  46. MessageBox.Show ("test non-derived form, ctrl-c from console to quit");
  47. Form form = new Form ();
  48. form.Show ();
  49. Application.DoEvents ();
  50. Application.Run ();
  51. }
  52. static public int Main (String[] args)
  53. {
  54. Test1();
  55. //Test2();
  56. return 0;
  57. }
  58. }