ColorExt.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // ***********************************************************************
  2. // Assembly : HZH_Controls
  3. // Created : 2019-09-30
  4. //
  5. // ***********************************************************************
  6. // <copyright file="ColorExt.cs">
  7. // Copyright by Huang Zhenghui(黄正辉) All, QQ group:568015492 QQ:623128629 Email:623128629@qq.com
  8. // </copyright>
  9. //
  10. // Blog: https://www.cnblogs.com/bfyx
  11. // GitHub:https://github.com/kwwwvagaa/NetWinformControl
  12. // gitee:https://gitee.com/kwwwvagaa/net_winform_custom_control.git
  13. //
  14. // If you use this code, please keep this note.
  15. // ***********************************************************************
  16. using System;
  17. using System.Collections.Generic;
  18. using System.Drawing;
  19. using System.Linq;
  20. using System.Text;
  21. namespace HZH_Controls
  22. {
  23. /// <summary>
  24. /// Class ColorExt.
  25. /// </summary>
  26. public static class ColorExt
  27. {
  28. #region 重置内置的颜色 English:Reset color
  29. /// <summary>
  30. /// Resets the color.
  31. /// </summary>
  32. /// <param name="type">The type.</param>
  33. /// <param name="light">The light.</param>
  34. /// <param name="medium">The medium.</param>
  35. /// <param name="dark">The dark.</param>
  36. public static void ResetColor(
  37. this BasisColors type,
  38. Color light,
  39. Color medium,
  40. Color dark)
  41. {
  42. BasisColors.Light = light;
  43. BasisColors.Medium = medium;
  44. BasisColors.Dark = dark;
  45. }
  46. /// <summary>
  47. /// Resets the color.
  48. /// </summary>
  49. /// <param name="type">The type.</param>
  50. /// <param name="green">The green.</param>
  51. /// <param name="blue">The blue.</param>
  52. /// <param name="red">The red.</param>
  53. /// <param name="yellow">The yellow.</param>
  54. public static void ResetColor(
  55. this BorderColors type,
  56. Color green,
  57. Color blue,
  58. Color red,
  59. Color yellow)
  60. {
  61. BorderColors.Green = green;
  62. BorderColors.Blue = blue;
  63. BorderColors.Red = red;
  64. BorderColors.Yellow = yellow;
  65. }
  66. /// <summary>
  67. /// Resets the color.
  68. /// </summary>
  69. /// <param name="type">The type.</param>
  70. /// <param name="orange">The orange.</param>
  71. /// <param name="lightGreen">The light green.</param>
  72. /// <param name="green">The green.</param>
  73. /// <param name="blue">The blue.</param>
  74. /// <param name="blueGreen">The blue green.</param>
  75. /// <param name="lightViolet">The light violet.</param>
  76. /// <param name="violet">The violet.</param>
  77. /// <param name="gray">The gray.</param>
  78. public static void ResetColor(
  79. this GradientColors type,
  80. Color[] orange,
  81. Color[] lightGreen,
  82. Color[] green,
  83. Color[] blue,
  84. Color[] blueGreen,
  85. Color[] lightViolet,
  86. Color[] violet,
  87. Color[] gray
  88. )
  89. {
  90. if (orange != null && orange.Length == 2)
  91. GradientColors.Orange = orange;
  92. if (orange != null && orange.Length == 2)
  93. GradientColors.LightGreen = lightGreen;
  94. if (orange != null && orange.Length == 2)
  95. GradientColors.Green = green;
  96. if (orange != null && orange.Length == 2)
  97. GradientColors.Blue = blue;
  98. if (orange != null && orange.Length == 2)
  99. GradientColors.BlueGreen = blueGreen;
  100. if (orange != null && orange.Length == 2)
  101. GradientColors.LightViolet = lightViolet;
  102. if (orange != null && orange.Length == 2)
  103. GradientColors.Violet = violet;
  104. if (orange != null && orange.Length == 2)
  105. GradientColors.Gray = gray;
  106. }
  107. /// <summary>
  108. /// Resets the color.
  109. /// </summary>
  110. /// <param name="type">The type.</param>
  111. /// <param name="moreLight">The more light.</param>
  112. /// <param name="light">The light.</param>
  113. /// <param name="dark">The dark.</param>
  114. /// <param name="moreDark">The more dark.</param>
  115. public static void ResetColor(
  116. this LineColors type,
  117. Color moreLight,
  118. Color light,
  119. Color dark,
  120. Color moreDark)
  121. {
  122. LineColors.MoreLight = moreLight;
  123. LineColors.Light = light;
  124. LineColors.Dark = dark;
  125. LineColors.MoreDark = moreDark;
  126. }
  127. /// <summary>
  128. /// Resets the color.
  129. /// </summary>
  130. /// <param name="type">The type.</param>
  131. /// <param name="primary">The primary.</param>
  132. /// <param name="success">The success.</param>
  133. /// <param name="warning">The warning.</param>
  134. /// <param name="danger">The danger.</param>
  135. /// <param name="info">The information.</param>
  136. public static void ResetColor(
  137. this StatusColors type,
  138. Color primary,
  139. Color success,
  140. Color warning,
  141. Color danger,
  142. Color info
  143. )
  144. {
  145. StatusColors.Primary = primary;
  146. StatusColors.Success = success;
  147. StatusColors.Warning = warning;
  148. StatusColors.Danger = danger;
  149. StatusColors.Info = info;
  150. }
  151. /// <summary>
  152. /// Resets the color.
  153. /// </summary>
  154. /// <param name="type">The type.</param>
  155. /// <param name="green">The green.</param>
  156. /// <param name="blue">The blue.</param>
  157. /// <param name="red">The red.</param>
  158. /// <param name="yellow">The yellow.</param>
  159. /// <param name="gray">The gray.</param>
  160. public static void ResetColor(
  161. this TableColors type,
  162. Color green,
  163. Color blue,
  164. Color red,
  165. Color yellow,
  166. Color gray
  167. )
  168. {
  169. TableColors.Green = green;
  170. TableColors.Blue = blue;
  171. TableColors.Red = red;
  172. TableColors.Yellow = yellow;
  173. TableColors.Gray = gray;
  174. }
  175. /// <summary>
  176. /// Resets the color.
  177. /// </summary>
  178. /// <param name="type">The type.</param>
  179. /// <param name="moreLight">The more light.</param>
  180. /// <param name="light">The light.</param>
  181. /// <param name="dark">The dark.</param>
  182. /// <param name="moreDark">The more dark.</param>
  183. public static void ResetColor(
  184. this TextColors type,
  185. Color moreLight,
  186. Color light,
  187. Color dark,
  188. Color moreDark)
  189. {
  190. TextColors.MoreLight = moreLight;
  191. TextColors.Light = light;
  192. TextColors.Dark = dark;
  193. TextColors.MoreDark = moreDark;
  194. }
  195. #endregion
  196. #region 获取一个内置颜色 English:Get a built-in color
  197. /// <summary>
  198. /// 功能描述:获取一个内置颜色 English:Get a built-in color
  199. /// 作  者:HZH
  200. /// 创建日期:2019-09-30 11:08:04
  201. /// 任务编号:POS
  202. /// </summary>
  203. /// <typeparam name="T"></typeparam>
  204. /// <param name="t">t</param>
  205. /// <returns>颜色列表</returns>
  206. public static Color[] GetInternalColor<T>(T t)
  207. {
  208. Type type = null;
  209. if (t is BasisColorsTypes)
  210. {
  211. type = typeof(BasisColors);
  212. }
  213. else if (t is BorderColorsTypes)
  214. {
  215. type = typeof(BorderColors);
  216. }
  217. else if (t is GradientColorsTypes)
  218. {
  219. type = typeof(GradientColors);
  220. }
  221. else if (t is LineColorsTypes)
  222. {
  223. type = typeof(LineColors);
  224. }
  225. else if (t is StatusColorsTypes)
  226. {
  227. type = typeof(StatusColors);
  228. }
  229. else if (t is TableColorsTypes)
  230. {
  231. type = typeof(TableColors);
  232. }
  233. else if (t is TextColorsTypes)
  234. {
  235. type = typeof(TextColors);
  236. }
  237. if (type == null)
  238. return new Color[] { Color.Empty };
  239. else
  240. {
  241. string strName = t.ToString();
  242. var pi = type.GetProperty(strName);
  243. if (pi == null)
  244. return new Color[] { Color.Empty };
  245. else
  246. {
  247. var c = pi.GetValue(null, null);
  248. if (c == null)
  249. return new Color[] { Color.Empty };
  250. else if (c is Color[])
  251. return (Color[])c;
  252. else
  253. return new Color[] { (Color)c };
  254. }
  255. }
  256. }
  257. #endregion
  258. }
  259. }