SkinVScrollBar.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using LYFZ.OtherExpansion.Imaging;
  2. using LYFZ.OtherExpansion.SkinClass;
  3. using System;
  4. using System.Drawing;
  5. using System.Windows.Forms;
  6. namespace LYFZ.OtherExpansion.SkinControl
  7. {
  8. public class SkinVScrollBar : VScrollBar, IScrollBarPaint
  9. {
  10. private ScrollBarManager _manager;
  11. private Color _base = Color.FromArgb(171, 230, 247);
  12. private Color _backNormal = Color.FromArgb(235, 249, 253);
  13. private Color _backHover = Color.FromArgb(121, 216, 243);
  14. private Color _backPressed = Color.FromArgb(70, 202, 239);
  15. private Color _border = Color.FromArgb(89, 210, 249);
  16. private Color _innerBorder = Color.FromArgb(200, 250, 250, 250);
  17. private Color _fore = Color.FromArgb(48, 135, 192);
  18. public Color Base
  19. {
  20. get
  21. {
  22. return this._base;
  23. }
  24. set
  25. {
  26. if (this._base != value)
  27. {
  28. this._base = value;
  29. base.Invalidate();
  30. }
  31. }
  32. }
  33. public Color BackNormal
  34. {
  35. get
  36. {
  37. return this._backNormal;
  38. }
  39. set
  40. {
  41. if (this._backNormal != value)
  42. {
  43. this._backNormal = value;
  44. base.Invalidate();
  45. }
  46. }
  47. }
  48. public Color BackHover
  49. {
  50. get
  51. {
  52. return this._backHover;
  53. }
  54. set
  55. {
  56. if (this._backHover != value)
  57. {
  58. this._backHover = value;
  59. base.Invalidate();
  60. }
  61. }
  62. }
  63. public Color BackPressed
  64. {
  65. get
  66. {
  67. return this._backPressed;
  68. }
  69. set
  70. {
  71. if (this._backPressed != value)
  72. {
  73. this._backPressed = value;
  74. base.Invalidate();
  75. }
  76. }
  77. }
  78. public Color Border
  79. {
  80. get
  81. {
  82. return this._border;
  83. }
  84. set
  85. {
  86. if (this._border != value)
  87. {
  88. this._border = value;
  89. base.Invalidate();
  90. }
  91. }
  92. }
  93. public Color InnerBorder
  94. {
  95. get
  96. {
  97. return this._innerBorder;
  98. }
  99. set
  100. {
  101. if (this._innerBorder != value)
  102. {
  103. this._innerBorder = value;
  104. base.Invalidate();
  105. }
  106. }
  107. }
  108. public Color Fore
  109. {
  110. get
  111. {
  112. return this._fore;
  113. }
  114. set
  115. {
  116. if (this._fore != value)
  117. {
  118. this._fore = value;
  119. base.Invalidate();
  120. }
  121. }
  122. }
  123. protected override void OnHandleCreated(EventArgs e)
  124. {
  125. base.OnHandleCreated(e);
  126. if (this._manager != null)
  127. {
  128. this._manager.Dispose();
  129. }
  130. this._manager = new ScrollBarManager(this);
  131. }
  132. protected override void Dispose(bool disposing)
  133. {
  134. if (disposing && this._manager != null)
  135. {
  136. this._manager.Dispose();
  137. this._manager = null;
  138. }
  139. base.Dispose(disposing);
  140. }
  141. protected internal virtual void OnPaintScrollBarTrack(PaintScrollBarTrackEventArgs e)
  142. {
  143. Graphics g = e.Graphics;
  144. Rectangle rect = e.TrackRectangle;
  145. Color baseColor = this.GetGray(this.Base);
  146. ControlPaintEx.DrawScrollBarTrack(g, rect, baseColor, Color.White, e.Orientation);
  147. }
  148. protected internal virtual void OnPaintScrollBarArrow(PaintScrollBarArrowEventArgs e)
  149. {
  150. Graphics g = e.Graphics;
  151. Rectangle rect = e.ArrowRectangle;
  152. ControlState controlState = e.ControlState;
  153. ArrowDirection direction = e.ArrowDirection;
  154. Orientation arg_22_0 = e.Orientation;
  155. bool bEnabled = e.Enabled;
  156. Color backColor = this.BackNormal;
  157. Color baseColor = this.Base;
  158. Color borderColor = this.Border;
  159. Color innerBorderColor = this.InnerBorder;
  160. Color foreColor = this.Fore;
  161. bool changeColor = false;
  162. if (bEnabled)
  163. {
  164. switch (controlState)
  165. {
  166. case ControlState.Hover:
  167. baseColor = this.BackHover;
  168. break;
  169. case ControlState.Pressed:
  170. baseColor = this.BackPressed;
  171. changeColor = true;
  172. break;
  173. default:
  174. baseColor = this.Base;
  175. break;
  176. }
  177. }
  178. else
  179. {
  180. backColor = this.GetGray(backColor);
  181. baseColor = this.GetGray(this.Base);
  182. borderColor = this.GetGray(borderColor);
  183. foreColor = this.GetGray(foreColor);
  184. }
  185. using (new SmoothingModeGraphics(g))
  186. {
  187. ControlPaintEx.DrawScrollBarArraw(g, rect, baseColor, backColor, borderColor, innerBorderColor, foreColor, e.Orientation, direction, changeColor);
  188. }
  189. }
  190. protected internal virtual void OnPaintScrollBarThumb(PaintScrollBarThumbEventArgs e)
  191. {
  192. if (!e.Enabled)
  193. {
  194. return;
  195. }
  196. Graphics g = e.Graphics;
  197. Rectangle rect = e.ThumbRectangle;
  198. ControlState controlState = e.ControlState;
  199. Color backColor = this.BackNormal;
  200. Color baseColor = this.Base;
  201. Color borderColor = this.Border;
  202. Color innerBorderColor = this.InnerBorder;
  203. bool changeColor = false;
  204. switch (controlState)
  205. {
  206. case ControlState.Hover:
  207. baseColor = this.BackHover;
  208. break;
  209. case ControlState.Pressed:
  210. baseColor = this.BackPressed;
  211. changeColor = true;
  212. break;
  213. default:
  214. baseColor = this.Base;
  215. break;
  216. }
  217. using (new SmoothingModeGraphics(g))
  218. {
  219. ControlPaintEx.DrawScrollBarThumb(g, rect, baseColor, backColor, borderColor, innerBorderColor, e.Orientation, changeColor);
  220. }
  221. }
  222. private Color GetGray(Color color)
  223. {
  224. return ColorConverterEx.RgbToGray(new RGB(color)).Color;
  225. }
  226. void IScrollBarPaint.OnPaintScrollBarArrow(PaintScrollBarArrowEventArgs e)
  227. {
  228. this.OnPaintScrollBarArrow(e);
  229. }
  230. void IScrollBarPaint.OnPaintScrollBarThumb(PaintScrollBarThumbEventArgs e)
  231. {
  232. this.OnPaintScrollBarThumb(e);
  233. }
  234. void IScrollBarPaint.OnPaintScrollBarTrack(PaintScrollBarTrackEventArgs e)
  235. {
  236. this.OnPaintScrollBarTrack(e);
  237. }
  238. }
  239. }