BrushExt.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. ///
  2. using System;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.ComponentModel;
  6. using System.Drawing.Design;
  7. using System.Collections;
  8. // Namespace BaseDef, include BrushExt, PenExt, FontData
  9. namespace GraEditor.BaseDef
  10. {
  11. /// <summary>
  12. /// Define our own Brush class, use it to store the color
  13. /// </summary>
  14. public class BrushExt
  15. {
  16. static BrushExt()
  17. {
  18. solidBrush = new SolidBrush(Color.Transparent);//construct a new brush
  19. }
  20. public BrushExt()
  21. {
  22. this.Color = Color.DarkBlue;
  23. }
  24. public BrushExt(Color color)//set color
  25. : this()
  26. {
  27. this.Color = color;
  28. }
  29. private static SolidBrush solidBrush;// static SolidBrush variable
  30. public Brush Brush //send the color of BrushExt to Solidbrush variable
  31. {
  32. get
  33. {
  34. solidBrush.Color = this.Color;//send color to brush variable
  35. return solidBrush;
  36. }
  37. set // set the color of BrushExt with Brush's color
  38. {
  39. SolidBrush b = value as SolidBrush; //Income value will change to SolidBrush type
  40. if(b == null)
  41. return;
  42. this.Color = b.Color;
  43. }
  44. }
  45. protected Color color;//color property of BrushExt
  46. public Color Color
  47. {
  48. get { return color; }
  49. set
  50. {
  51. //if( value == this.color)
  52. // return;
  53. this.color = value;
  54. //solidBrush.Color = this.color;
  55. }
  56. }
  57. }
  58. }