PenExt.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*************************************************************************************************
  2. *****File Name : PENEXT.CS, Version : 1.0, 8 November 2004****************************************
  3. *******************Author : Siva Kovvuri*********************************************************
  4. **This class represents the functionality of a pen object. This class extends the pen class **
  5. **from the System.Drawing. It encapsulates functionality for defining the color, width for **
  6. **the pen object. It includes methods for defining the default pen object with color black **
  7. **and pen object with any color. **
  8. **The FontData structure sets the name, type and size of the fonts. **
  9. ** **
  10. *************************************************************************************************/
  11. using System;
  12. using System.Drawing;
  13. using System.Drawing.Drawing2D;
  14. using System.ComponentModel;
  15. using System.Drawing.Design;
  16. using System.Windows.Forms;
  17. using System.Windows.Forms.Design;
  18. //Namespace BaseDef, include BrushExt, PenExt, FontData
  19. namespace GraEditor.BaseDef
  20. {
  21. /// <summary>
  22. /// //FontData structure, set the Font Name, Size and Font style
  23. /// </summary>
  24. [Serializable]
  25. public struct FontData
  26. {
  27. public FontData(Font font)
  28. {
  29. this.Name = font.Name; //Name
  30. this.Size = font.SizeInPoints;//Size;
  31. this.Style = font.Style;//Syle
  32. }
  33. public string Name;
  34. public float Size;
  35. public FontStyle Style;
  36. public bool IsEmpty() //No font
  37. {
  38. return Name.Length == 0 || Size <= 0;
  39. }
  40. }
  41. //Define our own Pen class, use it to store the color, width, dash style.
  42. public class PenExt
  43. {
  44. /// <summary>
  45. /// construct a new pen
  46. /// </summary>
  47. static PenExt()
  48. {
  49. _penObj = new Pen(Color.Black,1);
  50. }
  51. public PenExt()
  52. {
  53. this.color = Color.Black;//default color is black
  54. }
  55. //set color
  56. public PenExt(Color c)
  57. {
  58. this.color = c;
  59. }
  60. //set color, width and dash style
  61. public PenExt(Color c,int w,DashStyle s)
  62. :this(c)
  63. {
  64. this.width = w;
  65. this.dashStyle = s;
  66. }
  67. private static Pen _penObj; //static Pen variable
  68. public Pen Pen //send the color, width, dash style of PenExt to pen variable
  69. {
  70. get
  71. {
  72. _penObj.Color = this.Color; //send color to pen variable
  73. _penObj.Width = this.Width;//send width to pen variable
  74. _penObj.DashStyle = this.dashStyle;//send dash style to pen variable
  75. return _penObj;
  76. }
  77. set
  78. {
  79. if(value == null)
  80. return;
  81. color = value.Color; // set the color of PenExt with Pen's color
  82. width = value.Width;// set the width of PenExt with Pen's width
  83. dashStyle = value.DashStyle;//// set the dash style of PenExt with Pen's style
  84. }
  85. }
  86. protected Color color;
  87. //Color property of PenExt
  88. public Color Color
  89. {
  90. get { return color; }
  91. set
  92. {
  93. if( value == color)
  94. return;
  95. color = value;
  96. }
  97. }
  98. protected float width;
  99. // width property of PenExt
  100. public float Width
  101. {
  102. get { return width; }
  103. set
  104. {
  105. if( value == width)
  106. return;
  107. width = value;
  108. }
  109. }
  110. protected DashStyle dashStyle;
  111. //dash styple property of PenExt
  112. public DashStyle DashStyle
  113. {
  114. get { return dashStyle; }
  115. set
  116. {
  117. if(value == dashStyle)
  118. return;
  119. if(dashStyle == DashStyle.Custom)
  120. return;
  121. dashStyle = value;
  122. }
  123. }
  124. }
  125. }