PenExt.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. // _penObj1 = new Pen(Color.Black,1);
  50. // }
  51. public PenExt()
  52. {
  53. this.color = Color.Black;//default color is black
  54. _penObj = new Pen(Color.Black, 1);
  55. }
  56. //set color
  57. public PenExt(Color c)
  58. {
  59. this.color = c;
  60. }
  61. //set color, width and dash style
  62. public PenExt(Color c,int w,DashStyle s)
  63. :this(c)
  64. {
  65. this.width = w;
  66. this.dashStyle = s;
  67. }
  68. // private static Pen _penObj1;
  69. private Pen _penObj; //static Pen variable
  70. public Pen Pen //send the color, width, dash style of PenExt to pen variable
  71. {
  72. get
  73. {
  74. _penObj.Color = this.Color; //send color to pen variable
  75. _penObj.Width = this.Width;//send width to pen variable
  76. _penObj.DashStyle = this.dashStyle;//send dash style to pen variable
  77. return _penObj;
  78. }
  79. set
  80. {
  81. if(value == null)
  82. return;
  83. color = value.Color; // set the color of PenExt with Pen's color
  84. width = value.Width;// set the width of PenExt with Pen's width
  85. dashStyle = value.DashStyle;//// set the dash style of PenExt with Pen's style
  86. }
  87. }
  88. protected Color color;
  89. //Color property of PenExt
  90. public Color Color
  91. {
  92. get { return color; }
  93. set
  94. {
  95. if( value == color)
  96. return;
  97. color = value;
  98. }
  99. }
  100. protected float width;
  101. // width property of PenExt
  102. public float Width
  103. {
  104. get { return width; }
  105. set
  106. {
  107. if( value == width)
  108. return;
  109. width = value;
  110. }
  111. }
  112. protected DashStyle dashStyle;
  113. //dash styple property of PenExt
  114. public DashStyle DashStyle
  115. {
  116. get { return dashStyle; }
  117. set
  118. {
  119. if(value == dashStyle)
  120. return;
  121. if(dashStyle == DashStyle.Custom)
  122. return;
  123. dashStyle = value;
  124. }
  125. }
  126. }
  127. }