Guest User

Untitled

a guest
May 27th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7.  
  8. namespace web.frmcolor
  9. {
  10. public class FormEx : Form
  11. {
  12. /// <summary>
  13. /// Set the default color for the designer
  14. /// </summary>
  15. static FormEx()
  16. {
  17. _globalBackgroundColor = default(Color?);
  18. }
  19.  
  20. private static void InvalidateForms()
  21. {
  22. try
  23. {
  24. for (int i1 = 0; i1 < Application.OpenForms.Count; i1++)
  25. {
  26. try
  27. {
  28. FormEx frm = (Application.OpenForms[i1] as FormEx);
  29. if (frm != null)
  30. {
  31. frm.Invalidate(true);
  32. frm.Refresh();
  33. }
  34. }
  35. catch
  36. {
  37. //Should never happen
  38. }
  39. }
  40. }
  41. catch
  42. {
  43. //this will catch if the form count changes
  44. }
  45. }
  46.  
  47. private static Color? _globalBackgroundColor;
  48. /// <summary>
  49. /// Sets the background color for all forms
  50. /// </summary>
  51. public static Color? GlobalBackgroundColor
  52. {
  53. get { return FormEx._globalBackgroundColor; }
  54. set
  55. {
  56. if (FormEx._globalBackgroundColor != value)
  57. {
  58. FormEx._globalBackgroundColor = value;
  59. InvalidateForms();
  60. }
  61. }
  62. }
  63.  
  64. public override Color BackColor
  65. {
  66. get
  67. {
  68. return (_globalBackgroundColor == null ? base.BackColor : (Color)_globalBackgroundColor);
  69. }
  70. set
  71. {
  72. base.BackColor = value;
  73. }
  74. }
  75.  
  76. /// <summary>
  77. /// Create a new colored form
  78. /// </summary>
  79. public FormEx()
  80. : base()
  81. {
  82. }
  83.  
  84. private void InitializeComponent()
  85. {
  86. this.SuspendLayout();
  87. //
  88. // FormEx
  89. //
  90. this.ClientSize = new System.Drawing.Size(292, 266);
  91. this.Name = "FormEx";
  92. this.Load += new System.EventHandler(this.FormEx_Load);
  93. this.ResumeLayout(false);
  94.  
  95. }
  96.  
  97. private void FormEx_Load(object sender, EventArgs e)
  98. {
  99.  
  100. }
  101.  
  102.  
  103. }
  104. }
Add Comment
Please, Sign In to add comment