code_junkie

.Net WinForms Design Time Rules

Nov 12th, 2011
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. using System;
  2. using System.ComponentModel;
  3. using System.Windows.Forms;
  4.  
  5. namespace Test
  6. {
  7. public class ComponentClass : Component
  8. {
  9. public ComponentClass()
  10. {
  11. MessageBox.Show("Runtime!");
  12. }
  13. }
  14. }
  15.  
  16. using System;
  17. using System.ComponentModel;
  18. using System.Windows.Forms;
  19.  
  20. namespace Test
  21. {
  22. public class ComponentClass : Component
  23. {
  24. public ComponentClass()
  25. {
  26. if (LicenseManager.UsageMode != LicenseUsageMode.Designtime)
  27. {
  28. MessageBox.Show("Runtime!");
  29. }
  30. }
  31. }
  32. }
  33.  
  34. public static bool DesignMode
  35. {
  36. get { return (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv"); }
  37. }
  38.  
  39. if (!DesignMode)
  40. {
  41. // Run code that breaks in VS Designer (like trying to get a DB connection)
  42. }
  43.  
  44. public static bool IsAnyInDesignMode(Control control){
  45. while(control != null){
  46. if(control.Site != null && control.Site.DesignMode)
  47. return true;
  48. control = control.Parent;
  49. }
  50. return false;
  51. }
Add Comment
Please, Sign In to add comment