ControlBeautify.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. using Microsoft.VisualBasic.CompilerServices;
  2. using System;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.Windows.Forms;
  7. namespace BaseLibRWFile
  8. {
  9. public partial class ControlBeautify : Component
  10. {
  11. }
  12. public partial class TXbutton : Button
  13. {
  14. public bool status = false;
  15. private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
  16. {
  17. try
  18. {
  19. int span = 2;
  20. //抗锯齿
  21. g.SmoothingMode = SmoothingMode.AntiAlias;
  22. //渐变填充
  23. LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical);
  24. //画尖角
  25. if (cusp)
  26. {
  27. span = 10;
  28. PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10);
  29. PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30);
  30. PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20);
  31. PointF[] ptsArray = { p1, p2, p3 };
  32. g.FillPolygon(myLinearGradientBrush, ptsArray);
  33. }
  34. //填充
  35. g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height - 1, _radius));
  36. }
  37. catch
  38. {
  39. }
  40. }
  41. public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
  42. {
  43. //四边圆角
  44. GraphicsPath gp = new GraphicsPath();
  45. gp.AddArc(x, y, radius, radius, 180, 90);
  46. gp.AddArc(width - radius, y, radius, radius, 270, 90);
  47. gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
  48. gp.AddArc(x, height - radius, radius, radius, 90, 90);
  49. gp.CloseAllFigures();
  50. return gp;
  51. }
  52. public string name = null; //名称
  53. public string name_move = null;
  54. public int font_size = 9; //字体的大小
  55. public Color TXcolor_start; //渐变色的颜色,start开始,end结束
  56. public Color TXcolor_end;
  57. public Color TXcolor_start_move;
  58. public Color TXcolor_end_move;
  59. public Image TX_image = null;
  60. protected override void OnPaint(PaintEventArgs e)
  61. {
  62. base.OnPaint(e);
  63. base.OnPaintBackground(e);
  64. StringFormat strFormat = new StringFormat();
  65. strFormat.Alignment=StringAlignment.Center;
  66. strFormat.LineAlignment = StringAlignment.Center;
  67. Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
  68. //System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
  69. //path.AddEllipse(0, 0, this.Width, this.Height);
  70. //this.Region = new Region(path);
  71. //this.FlatStyle = FlatStyle.Flat;
  72. //this.FlatAppearance.BorderSize = 0;
  73. //this.Text = null;
  74. //font_size = 10;
  75. this.FlatAppearance.MouseOverBackColor = Color.Transparent;
  76. this.FlatAppearance.MouseDownBackColor = Color.Transparent;
  77. if (status == false)
  78. {
  79. if (TXcolor_start.IsEmpty)
  80. {
  81. Draw(e.ClipRectangle, e.Graphics, 25, false, Color.FromArgb(0xEA, 0xEA, 0xEB), Color.FromArgb(0xEA, 0xEA, 0xEB));
  82. }
  83. else
  84. {
  85. Draw(e.ClipRectangle, e.Graphics, 25, false, TXcolor_start, TXcolor_start);
  86. }
  87. if (name != null)
  88. {
  89. //e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(this.Width / 2 - name.Length * (font_size / 2), this.Height / 2 - FontHeight));
  90. e.Graphics.DrawString(name, new Font("宋体", font_size, FontStyle.Regular), new SolidBrush(Color.Black), rect,strFormat);
  91. }
  92. if (TX_image != null)
  93. {
  94. e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height);
  95. }
  96. this.Cursor = Cursors.Arrow;
  97. }
  98. else
  99. {
  100. if (TXcolor_start_move.IsEmpty)
  101. {
  102. Draw(e.ClipRectangle, e.Graphics, 25, false, Color.FromArgb(0xAE, 0xDA, 0x97), Color.FromArgb(0xAE, 0xDA, 0x97));
  103. }
  104. else
  105. {
  106. Draw(e.ClipRectangle, e.Graphics, 25, false, TXcolor_start_move, TXcolor_start_move);
  107. }
  108. if (name != null)
  109. {
  110. //e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(this.Width / 2 - name.Length * (font_size / 2), this.Height / 2 - FontHeight));
  111. e.Graphics.DrawString(name, new Font("宋体", font_size, FontStyle.Regular), new SolidBrush(Color.Black), rect, strFormat);
  112. }
  113. if (TX_image != null)
  114. {
  115. e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height);
  116. }
  117. this.Cursor = Cursors.Arrow;
  118. }
  119. }
  120. //protected override void OnPaintBackground(PaintEventArgs e)
  121. //{
  122. // base.OnPaintBackground(e);
  123. // Draw(e.ClipRectangle, e.Graphics, 12, false, Color.Gray, Color.Green);
  124. //}
  125. //protected override void OnMouseEnter(EventArgs e)
  126. //{
  127. // base.OnMouseEnter(e);
  128. // status = true;
  129. // //Draw(e.ClipRectangle, e.Graphics, 25, false, Color.Gray, Color.Green);
  130. //}
  131. //protected override void OnMouseLeave(EventArgs e)
  132. //{
  133. // base.OnMouseLeave(e);
  134. // status = false;
  135. // //Draw(e.ClipRectangle, e.Graphics, 12, false, Color.Gray, Color.Green);
  136. //}
  137. //protected override void OnMouseDown(MouseEventArgs mevent)
  138. //{
  139. // base.OnMouseDown(mevent);
  140. // status = true;
  141. //}
  142. }
  143. public partial class TXlabel : Label
  144. {
  145. public bool status = false;
  146. private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
  147. {
  148. try
  149. {
  150. int span = 2;
  151. //抗锯齿
  152. g.SmoothingMode = SmoothingMode.AntiAlias;
  153. //渐变填充
  154. LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical);
  155. //画尖角
  156. if (cusp)
  157. {
  158. span = 10;
  159. PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10);
  160. PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30);
  161. PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20);
  162. PointF[] ptsArray = { p1, p2, p3 };
  163. g.FillPolygon(myLinearGradientBrush, ptsArray);
  164. }
  165. //填充
  166. g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height - 1, _radius));
  167. }
  168. catch
  169. {
  170. }
  171. }
  172. public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
  173. {
  174. //四边圆角
  175. GraphicsPath gp = new GraphicsPath();
  176. gp.AddArc(x, y, radius, radius, 180, 90);
  177. gp.AddArc(width - radius, y, radius, radius, 270, 90);
  178. gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
  179. gp.AddArc(x, height - radius, radius, radius, 90, 90);
  180. gp.CloseAllFigures();
  181. return gp;
  182. }
  183. public string name = null; //名称
  184. public string name_move = null;
  185. public int font_size = 12; //字体的大小
  186. public Color TXcolor_start; //渐变色的颜色,start开始,end结束
  187. public Color TXcolor_end;
  188. public Color TXcolor_start_move;
  189. public Color TXcolor_end_move;
  190. public Image TX_image = null;
  191. protected override void OnPaint(PaintEventArgs e)
  192. {
  193. base.OnPaint(e);
  194. base.OnPaintBackground(e);
  195. StringFormat strFormat = new StringFormat();
  196. strFormat.Alignment = StringAlignment.Center;
  197. strFormat.LineAlignment = StringAlignment.Center;
  198. Rectangle rect = new Rectangle(0, 0, this.Width, this.Height);
  199. name = this.Text;
  200. font_size = Convert.ToInt32(this.Font.Size);
  201. if (status == false)
  202. {
  203. if (TXcolor_start.IsEmpty)
  204. {
  205. Draw(e.ClipRectangle, e.Graphics, 12, false, Color.FromArgb(0xAE, 0xDA, 0x97), Color.FromArgb(0xAE, 0xDA, 0x97));
  206. }
  207. else
  208. {
  209. Draw(e.ClipRectangle, e.Graphics, 12, false, TXcolor_start, TXcolor_start);
  210. }
  211. if (name != null)
  212. {
  213. //e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(this.Width / 2 - name.Length * (font_size / 2), this.Height / 2 - FontHeight));
  214. e.Graphics.DrawString(name, new Font("宋体", font_size, FontStyle.Regular), new SolidBrush(Color.Black), rect, strFormat);
  215. }
  216. if (TX_image != null)
  217. {
  218. e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height);
  219. }
  220. this.Cursor = Cursors.Arrow;
  221. }
  222. else
  223. {
  224. if (TXcolor_start_move.IsEmpty)
  225. {
  226. Draw(e.ClipRectangle, e.Graphics, 12, false, Color.FromArgb(0xAE, 0xDA, 0x97), Color.FromArgb(0xAE, 0xDA, 0x97));
  227. }
  228. else
  229. {
  230. Draw(e.ClipRectangle, e.Graphics, 12, false, TXcolor_start_move, TXcolor_start_move);
  231. }
  232. if (name != null)
  233. {
  234. //e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(this.Width / 2 - name.Length * (font_size / 2), this.Height / 2 - FontHeight));
  235. e.Graphics.DrawString(name, new Font("宋体", font_size, FontStyle.Regular), new SolidBrush(Color.Black), rect, strFormat);
  236. }
  237. if (TX_image != null)
  238. {
  239. e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height);
  240. }
  241. this.Cursor = Cursors.Arrow;
  242. }
  243. }
  244. //protected override void OnPaintBackground(PaintEventArgs e)
  245. //{
  246. // //base.OnPaintBackground(e);
  247. // //Draw(e.ClipRectangle, e.Graphics, 18, false, Color.Gray, Color.Green);
  248. //}
  249. //protected override void OnMouseEnter(EventArgs e)
  250. //{
  251. // base.OnMouseEnter(e);
  252. // //if (!this.Enabled)
  253. // //{
  254. // // return;
  255. // //}
  256. // //this.m_OldBkColor = this.BackColor;
  257. // //this.IsOnEnter = true;
  258. // //this.IsOnLeave = false;
  259. // //this.Invalidate();
  260. //}
  261. //protected override void OnMouseLeave(EventArgs e)
  262. //{
  263. // base.OnMouseLeave(e);
  264. //}
  265. //protected override void OnMouseDown(MouseEventArgs mevent)
  266. //{
  267. // base.OnMouseDown(mevent);
  268. // status = true;
  269. //}
  270. }
  271. public partial class TXpanel : Panel
  272. {
  273. bool status = false;
  274. private void Draw(Rectangle rectangle, Graphics g, int _radius, bool cusp, Color begin_color, Color end_color)
  275. {
  276. try
  277. {
  278. int span = 2;
  279. //抗锯齿
  280. g.SmoothingMode = SmoothingMode.AntiAlias;
  281. //渐变填充
  282. LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush(rectangle, begin_color, end_color, LinearGradientMode.Vertical);
  283. //画尖角
  284. if (cusp)
  285. {
  286. span = 10;
  287. PointF p1 = new PointF(rectangle.Width - 12, rectangle.Y + 10);
  288. PointF p2 = new PointF(rectangle.Width - 12, rectangle.Y + 30);
  289. PointF p3 = new PointF(rectangle.Width, rectangle.Y + 20);
  290. PointF[] ptsArray = { p1, p2, p3 };
  291. g.FillPolygon(myLinearGradientBrush, ptsArray);
  292. }
  293. //填充
  294. g.FillPath(myLinearGradientBrush, DrawRoundRect(rectangle.X, rectangle.Y, rectangle.Width - span, rectangle.Height - 1, _radius));
  295. }
  296. catch
  297. {
  298. }
  299. }
  300. public static GraphicsPath DrawRoundRect(int x, int y, int width, int height, int radius)
  301. {
  302. //四边圆角
  303. GraphicsPath gp = new GraphicsPath();
  304. gp.AddArc(x, y, radius, radius, 180, 90);
  305. gp.AddArc(width - radius, y, radius, radius, 270, 90);
  306. gp.AddArc(width - radius, height - radius, radius, radius, 0, 90);
  307. gp.AddArc(x, height - radius, radius, radius, 90, 90);
  308. gp.CloseAllFigures();
  309. return gp;
  310. }
  311. public string name = null; //名称
  312. public string name_move = null;
  313. public int font_size = 12; //字体的大小
  314. public Color TXcolor_start; //渐变色的颜色,start开始,end结束
  315. public Color TXcolor_end;
  316. public Color TXcolor_start_move;
  317. public Color TXcolor_end_move;
  318. public Image TX_image = null;
  319. protected override void OnPaint(PaintEventArgs e)
  320. {
  321. base.OnPaint(e);
  322. if (status == false)
  323. {
  324. if (TXcolor_start.IsEmpty)
  325. {
  326. //Draw(e.ClipRectangle, e.Graphics, 12, false, Color.FromArgb(0xEA, 0xEA, 0xEB), Color.FromArgb(0xEA, 0xEA, 0xEB));
  327. Draw(e.ClipRectangle, e.Graphics, 20, false, SystemColors.Control, SystemColors.Control);
  328. }
  329. else
  330. {
  331. Draw(e.ClipRectangle, e.Graphics, 20, false, TXcolor_start, TXcolor_start);
  332. }
  333. e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(font_size + font_size / 2, this.Height / 2 - FontHeight));
  334. if (TX_image != null)
  335. {
  336. e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height);
  337. }
  338. this.Cursor = Cursors.Arrow;
  339. }
  340. else
  341. {
  342. if (TXcolor_start_move.IsEmpty)
  343. {
  344. Draw(e.ClipRectangle, e.Graphics, 20, false, SystemColors.Control, SystemColors.Control);
  345. }
  346. else
  347. {
  348. Draw(e.ClipRectangle, e.Graphics, 20, false, TXcolor_start_move, TXcolor_start_move);
  349. }
  350. e.Graphics.DrawString(name, new Font("微软雅黑", font_size, FontStyle.Regular), new SolidBrush(Color.Black), new PointF(font_size + font_size / 2, this.Height / 2 - FontHeight));
  351. if (TX_image != null)
  352. {
  353. e.Graphics.DrawImage(TX_image, 0, 0, this.Width, this.Height);
  354. }
  355. this.Cursor = Cursors.Arrow;
  356. }
  357. }
  358. //protected override void OnPaintBackground(PaintEventArgs e)
  359. //{
  360. // //base.OnPaintBackground(e);
  361. // //Draw(e.ClipRectangle, e.Graphics, 18, false, Color.Gray, Color.Green);
  362. //}
  363. //protected override void OnMouseEnter(EventArgs e)
  364. //{
  365. // base.OnMouseEnter(e);
  366. // status = true;
  367. //}
  368. //protected override void OnMouseLeave(EventArgs e)
  369. //{
  370. // base.OnMouseLeave(e);
  371. // status = false;
  372. //}
  373. //protected override void OnMouseDown(MouseEventArgs mevent)
  374. //{
  375. // base.OnMouseDown(mevent);
  376. //}
  377. }
  378. public partial class TXbutton_circular : Button
  379. {
  380. protected override void OnPaint(PaintEventArgs e)
  381. {
  382. base.OnPaint(e);
  383. e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
  384. GraphicsPath path = new GraphicsPath();
  385. path.AddEllipse(0, 0, this.Width, this.Height);
  386. this.FlatAppearance.BorderSize = 0;
  387. this.Region = new Region(path);
  388. }
  389. }
  390. public class TXDraw : Panel
  391. {
  392. Color Draw_Color = Color.FromArgb(30, 255, 50);
  393. public int Percentage = 0;
  394. public int Percentage_current = 0;
  395. protected override void OnPaint(PaintEventArgs e)
  396. {
  397. base.OnPaint(e);
  398. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
  399. // path.AddEllipse(0, 0, this.Width, this.Height);
  400. Rectangle ret = new Rectangle(0, 0, this.Width, this.Height);
  401. path.AddRectangle(ret);
  402. this.Region = new Region(path);
  403. Graphics ex = this.CreateGraphics();
  404. Rectangle retc = new Rectangle(10, 10, 180, 180);
  405. Rectangle retd = new Rectangle(35, 35, 130, 130);
  406. Rectangle rete = new Rectangle(40, 40, 120, 120);
  407. Rectangle retf = new Rectangle(65, 65, 70, 70);
  408. Rectangle retg = new Rectangle(70, 70, 60, 60);
  409. System.Drawing.Font strname_ok_ng = new System.Drawing.Font("黑体", 15, FontStyle.Bold);
  410. System.Drawing.Font strname = new System.Drawing.Font("黑体", 10, FontStyle.Bold);
  411. StringFormat ss = new StringFormat(StringFormatFlags.DirectionVertical);
  412. ex.DrawArc(new Pen(Draw_Color), retc, 180, 180);
  413. ex.DrawArc(new Pen(Draw_Color), retd, 180, 180);
  414. ex.FillPie(new SolidBrush(Draw_Color), retc, 180, 180);
  415. ex.FillPie(new SolidBrush(Color.Red), retc, 180, Percentage); //百分比100%
  416. ex.FillPie(Brushes.White, retd, 180, 180);
  417. ex.DrawArc(new Pen(Draw_Color), rete, 180, 180);
  418. ex.DrawArc(new Pen(Draw_Color), retf, 180, 180);
  419. ex.FillPie(new SolidBrush(Draw_Color), rete, 180, 180);
  420. ex.FillPie(new SolidBrush(Color.Red), rete, 180, Percentage_current); //百分比100%
  421. ex.FillPie(Brushes.White, retf, 180, 180);
  422. ex.DrawArc(new Pen(Color.Red), retg, 180, 180);
  423. ex.FillPie(Brushes.Red, retg, 360, 360);
  424. ex.DrawString("OK", strname_ok_ng, Brushes.White, 90, 90, StringFormat.GenericTypographic);
  425. ex.DrawString(System.DateTime.Now.ToString("d"), strname_ok_ng, Brushes.Black, 20, 140, StringFormat.GenericTypographic);
  426. }
  427. }
  428. public class TXDrawA : Panel
  429. {
  430. public int Percentage = 0;
  431. public int Percentage_current = 0;
  432. protected override void OnPaint(PaintEventArgs e)
  433. {
  434. base.OnPaint(e);
  435. System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
  436. //path.AddEllipse(0, 0, this.Width, this.Height);
  437. Rectangle ret = new Rectangle(0, 0, this.Width, this.Height);
  438. path.AddRectangle(ret);
  439. this.Region = new Region(path);
  440. int WidthX = e.ClipRectangle.Width;
  441. int HeightY = e.ClipRectangle.Height;
  442. Graphics ex = this.CreateGraphics();
  443. ex.SmoothingMode = SmoothingMode.AntiAlias;
  444. System.Drawing.Font strname_ok_ng = new System.Drawing.Font("黑体", 15, FontStyle.Bold);
  445. System.Drawing.Font strname = new System.Drawing.Font("黑体", 10, FontStyle.Bold);
  446. StringFormat ss = new StringFormat(StringFormatFlags.DirectionVertical);
  447. Pen myPen = new Pen(this.ForeColor, 30);
  448. ex.DrawArc(myPen, Convert.ToInt32(WidthX * 0.15), Convert.ToInt32(HeightY * 0.2), Convert.ToInt32(WidthX * 0.7), Convert.ToInt32(HeightY * 0.8), 170, 48);
  449. ex.DrawArc(myPen, Convert.ToInt32(WidthX * 0.15), Convert.ToInt32(HeightY * 0.2), Convert.ToInt32(WidthX * 0.7), Convert.ToInt32(HeightY * 0.8), 220, 53);
  450. ex.DrawArc(myPen, Convert.ToInt32(WidthX * 0.15), Convert.ToInt32(HeightY * 0.2), Convert.ToInt32(WidthX * 0.7), Convert.ToInt32(HeightY * 0.8), 275, 48);
  451. ex.DrawArc(myPen, Convert.ToInt32(WidthX * 0.15), Convert.ToInt32(HeightY * 0.2), Convert.ToInt32(WidthX * 0.7), Convert.ToInt32(HeightY * 0.8), 325, 48);
  452. string[] name = AccessibleName.Split(',');
  453. int X1 = int.Parse(name[0]);
  454. int X2 = int.Parse(name[1]);
  455. double k = 0, b = 0;
  456. Calculate(X1, X2, -100, 100, ref k, ref b);
  457. double A = (k * int.Parse(this.Tag.ToString()) + b);
  458. int Value;
  459. if (A >= 0)
  460. {
  461. Value = (int)A;
  462. }
  463. else
  464. {
  465. A = -A;
  466. Value = (int)A;
  467. Value = -Value;
  468. }
  469. //表中心点
  470. Point centerPoint = new Point(Convert.ToInt32(WidthX * 0.7) - Convert.ToInt32(WidthX * 0.4) / 2, Convert.ToInt32(HeightY * 0.8) - Convert.ToInt32(HeightY * 0.4) / 2);
  471. Point secPoint = new Point((int)(centerPoint.X + (Math.Sin(Value * Math.PI / 180)) * (Convert.ToInt32(HeightY * 0.99) - Convert.ToInt32(HeightY * 0.01)) / 2),
  472. (int)(centerPoint.Y - (Math.Cos(Value * Math.PI / 180)) * (Convert.ToInt32(HeightY * 0.99) - Convert.ToInt32(HeightY * 0.01)) / 2));
  473. myPen = new Pen(Color.FromArgb(239, 144, 0), 5);
  474. ex.DrawLine(myPen, centerPoint, secPoint);
  475. e.Graphics.DrawString(this.Tag.ToString(), this.Font, new SolidBrush(Color.Black), Convert.ToInt32((Convert.ToInt32(WidthX * 0.7) - Convert.ToInt32(WidthX * 0.2)) - (double)ex.MeasureString(this.Tag.ToString(), this.Font).ToSize().Width / 2.0), Convert.ToInt32(HeightY * 0.8) - Convert.ToInt32(HeightY * 0.35) / 2);
  476. e.Graphics.DrawString(name[0], this.Font, new SolidBrush(Color.Black), Convert.ToInt32(WidthX * 0.15 - (double)ex.MeasureString(name[0], this.Font).ToSize().Width / 2.0), Convert.ToInt32(HeightY * 0.7));
  477. e.Graphics.DrawString(name[1], this.Font, new SolidBrush(Color.Black), Convert.ToInt32(WidthX * 0.85 - (double)ex.MeasureString(name[1], this.Font).ToSize().Width / 2.0), Convert.ToInt32(HeightY * 0.7));
  478. e.Graphics.DrawString(name[3], this.Font, new SolidBrush(Color.Black), Convert.ToInt32(WidthX * 0.5 - (double)ex.MeasureString(name[3], this.Font).ToSize().Width / 2.0), Convert.ToInt32(HeightY * 0.85));
  479. }
  480. private const int _decimaldigits = 2;//小数位数保留2位
  481. private static void Calculate(float x1, float x2, float y1, float y2, ref double kvalue, ref double bvalue)//求方程y=kx+b 系数 k ,b
  482. {
  483. float coefficient = 1;//系数值
  484. try
  485. {
  486. if ((x1 == 0) || (x2 == 0) || (x1 == x2))
  487. {
  488. if (x1 == 0)
  489. {
  490. x1 = 1;
  491. }
  492. if (x2 == 0)
  493. {
  494. x2 = 1;
  495. }
  496. }
  497. //; //排除为零的情况以及x1,x2相等时无法运算的情况
  498. //if (y1 == y2) return; //根据具体情况而定,如何这两个值相等,得到的就是一条直线
  499. float temp = 0;
  500. if (x1 >= x2)
  501. {
  502. coefficient = (float)Math.Round((x1 / x2), _decimaldigits);
  503. temp = y2 * coefficient; //将对应的函数乘以系数
  504. bvalue = (double)Math.Round(((temp - y1) / (coefficient - 1)), _decimaldigits);
  505. kvalue = (double)Math.Round(((y1 - bvalue) / x1), _decimaldigits); //求出k值
  506. }
  507. else
  508. {
  509. coefficient = x2 / x1;
  510. temp = y1 * coefficient;
  511. bvalue = (double)Math.Round(((temp - y2) / (coefficient - 1)), _decimaldigits);//求出b值
  512. kvalue = (double)Math.Round(((y2 - bvalue) / x2), _decimaldigits); //求出k值
  513. }
  514. }
  515. catch
  516. {
  517. Console.WriteLine("x系数不能为0或相等");
  518. }
  519. }
  520. }
  521. [OptionText]
  522. public class RoundPanel : Panel
  523. {
  524. private int m_iRoundRadius;
  525. private bool m_bAutoBkColor;
  526. public byte Radius
  527. {
  528. get
  529. {
  530. return checked((byte)this.m_iRoundRadius);
  531. }
  532. set
  533. {
  534. this.m_iRoundRadius = (int)value;
  535. this.Invalidate();
  536. }
  537. }
  538. public bool AutoBkColor
  539. {
  540. get
  541. {
  542. return this.m_bAutoBkColor;
  543. }
  544. set
  545. {
  546. this.m_bAutoBkColor = value;
  547. this.Invalidate();
  548. }
  549. }
  550. public RoundPanel()
  551. {
  552. this.m_iRoundRadius = 15;
  553. this.m_bAutoBkColor = false;
  554. this.ForeColor = Color.Gray;
  555. this.Width = 120;
  556. this.Height = 50;
  557. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  558. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  559. this.SetStyle(ControlStyles.UserPaint, true);
  560. this.SetStyle(ControlStyles.ResizeRedraw, true);
  561. }
  562. private void Check()
  563. {
  564. checked
  565. {
  566. if ((double)this.m_iRoundRadius > (double)this.Width / 2.0 | (double)this.m_iRoundRadius > (double)this.Height / 2.0)
  567. {
  568. if ((double)this.Width / 2.0 > (double)this.Height / 2.0)
  569. {
  570. this.m_iRoundRadius = (int)Math.Round((double)this.Height / 2.0);
  571. }
  572. else
  573. {
  574. this.m_iRoundRadius = (int)Math.Round((double)this.Width / 2.0);
  575. }
  576. }
  577. else if (this.m_iRoundRadius < 0)
  578. {
  579. this.m_iRoundRadius = 0;
  580. }
  581. if (this.Parent.GetType() == typeof(RoundPanel))
  582. {
  583. if (this.m_bAutoBkColor)
  584. {
  585. this.BackColor = this.Parent.ForeColor;
  586. }
  587. }
  588. else if (this.m_bAutoBkColor)
  589. {
  590. this.BackColor = this.Parent.BackColor;
  591. }
  592. }
  593. }
  594. protected override void OnParentBackColorChanged(EventArgs e)
  595. {
  596. if (!(this.Parent.GetType() == typeof(RoundPanel)) && this.m_bAutoBkColor)
  597. {
  598. this.BackColor = this.Parent.BackColor;
  599. }
  600. }
  601. protected override void OnParentForeColorChanged(EventArgs e)
  602. {
  603. if (this.Parent.GetType() == typeof(RoundPanel) && this.m_bAutoBkColor)
  604. {
  605. this.BackColor = this.Parent.ForeColor;
  606. }
  607. }
  608. protected override void OnPaint(PaintEventArgs e)
  609. {
  610. checked
  611. {
  612. try
  613. {
  614. this.Check();
  615. Graphics graphics = e.Graphics;
  616. Rectangle rect = new Rectangle(e.ClipRectangle.Left + this.m_iRoundRadius, e.ClipRectangle.Top, e.ClipRectangle.Right - 2 * this.m_iRoundRadius, e.ClipRectangle.Bottom);
  617. Rectangle rect2 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Top + this.m_iRoundRadius, e.ClipRectangle.Right, e.ClipRectangle.Bottom - 2 * this.m_iRoundRadius);
  618. Rectangle rect3 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Top, 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius);
  619. Rectangle rect4 = new Rectangle(e.ClipRectangle.Right - 1 - 2 * this.m_iRoundRadius, e.ClipRectangle.Top, 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius);
  620. Rectangle rect5 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Bottom - 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius - 1);
  621. Rectangle rect6 = new Rectangle(e.ClipRectangle.Right - 1 - 2 * this.m_iRoundRadius, e.ClipRectangle.Bottom - 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius, 2 * this.m_iRoundRadius - 1);
  622. graphics.Clear(this.BackColor);
  623. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  624. Brush brush = new SolidBrush(this.ForeColor);
  625. graphics.FillRectangle(brush, rect);
  626. graphics.FillRectangle(brush, rect2);
  627. if (this.m_iRoundRadius != 0)
  628. {
  629. graphics.FillPie(brush, rect3, 170f, 120f);
  630. graphics.FillPie(brush, rect4, 260f, 120f);
  631. graphics.FillPie(brush, rect5, 80f, 120f);
  632. graphics.FillPie(brush, rect6, 350f, 120f);
  633. }
  634. brush.Dispose();
  635. }
  636. catch (Exception arg_23F_0)
  637. {
  638. ProjectData.SetProjectError(arg_23F_0);
  639. ProjectData.ClearProjectError();
  640. }
  641. }
  642. }
  643. }
  644. [OptionText]
  645. public class RoundButton : Button
  646. {
  647. private int m_RoundRadius;
  648. private Color m_OldBkColor;
  649. private bool IsClicked;
  650. private bool IsOnEnter;
  651. private bool IsOnLeave;
  652. public byte Radius
  653. {
  654. get
  655. {
  656. return checked((byte)this.m_RoundRadius);
  657. }
  658. set
  659. {
  660. this.m_RoundRadius = (int)value;
  661. this.Invalidate();
  662. }
  663. }
  664. public RoundButton()
  665. {
  666. this.Width = 120;
  667. this.Height = 50;
  668. this.ForeColor = Color.Green;
  669. this.FontHeight = 25;
  670. this.m_RoundRadius = 6;
  671. this.IsClicked = false;
  672. this.IsOnEnter = false;
  673. this.IsOnLeave = false;
  674. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  675. this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
  676. this.SetStyle(ControlStyles.UserPaint, true);
  677. this.SetStyle(ControlStyles.ResizeRedraw, true);
  678. }
  679. private void Check()
  680. {
  681. checked
  682. {
  683. if ((double)this.m_RoundRadius > (double)this.Width / 2.0 | (double)this.m_RoundRadius > (double)this.Height / 2.0)
  684. {
  685. if ((double)this.Width / 2.0 > (double)this.Height / 2.0)
  686. {
  687. this.m_RoundRadius = (int)Math.Round((double)this.Height / 2.0);
  688. }
  689. else
  690. {
  691. this.m_RoundRadius = (int)Math.Round((double)this.Width / 2.0);
  692. }
  693. }
  694. else if (this.m_RoundRadius < 0)
  695. {
  696. this.m_RoundRadius = 0;
  697. }
  698. }
  699. }
  700. protected override void OnParentBackColorChanged(EventArgs e)
  701. {
  702. this.Invalidate();
  703. }
  704. protected override void OnPaint(PaintEventArgs e)
  705. {
  706. checked
  707. {
  708. try
  709. {
  710. this.Check();
  711. Graphics graphics = e.Graphics;
  712. Rectangle rect = new Rectangle(e.ClipRectangle.Left + this.m_RoundRadius, e.ClipRectangle.Top, e.ClipRectangle.Right - 2 * this.m_RoundRadius, e.ClipRectangle.Bottom);
  713. Rectangle rect2 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Top + this.m_RoundRadius, e.ClipRectangle.Right, e.ClipRectangle.Bottom - 2 * this.m_RoundRadius);
  714. Rectangle rect3 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Top, 2 * this.m_RoundRadius, 2 * this.m_RoundRadius);
  715. Rectangle rect4 = new Rectangle(e.ClipRectangle.Right - 1 - 2 * this.m_RoundRadius, e.ClipRectangle.Top, 2 * this.m_RoundRadius, 2 * this.m_RoundRadius);
  716. Rectangle rect5 = new Rectangle(e.ClipRectangle.Left, e.ClipRectangle.Bottom - 2 * this.m_RoundRadius, 2 * this.m_RoundRadius, 2 * this.m_RoundRadius - 1);
  717. Rectangle rect6 = new Rectangle(e.ClipRectangle.Right - 1 - 2 * this.m_RoundRadius, e.ClipRectangle.Bottom - 2 * this.m_RoundRadius, 2 * this.m_RoundRadius, 2 * this.m_RoundRadius - 1);
  718. if (Operators.CompareString(this.Parent.GetType().Name, typeof(RoundPanel).Name, true) == 0)
  719. {
  720. graphics.Clear(this.Parent.ForeColor);
  721. }
  722. else
  723. {
  724. graphics.Clear(this.Parent.BackColor);
  725. }
  726. graphics.SmoothingMode = SmoothingMode.AntiAlias;
  727. Color color = Color.WhiteSmoke;
  728. if (this.IsOnEnter)
  729. {
  730. color = Color.LightGreen;
  731. }
  732. else if (this.IsOnLeave & !this.IsClicked)
  733. {
  734. color = this.m_OldBkColor;
  735. }
  736. else if (this.IsClicked)
  737. {
  738. color = this.BackColor;
  739. }
  740. else
  741. {
  742. color = this.BackColor;
  743. }
  744. Brush brush = new SolidBrush(color);
  745. graphics.FillRectangle(brush, rect);
  746. graphics.FillRectangle(brush, rect2);
  747. if (this.m_RoundRadius != 0)
  748. {
  749. graphics.FillPie(brush, rect3, 0f, 360f);
  750. graphics.FillPie(brush, rect4, 0f, 360f);
  751. graphics.FillPie(brush, rect5, 0f, 360f);
  752. graphics.FillPie(brush, rect6, 0f, 360f);
  753. }
  754. PointF point = unchecked(new PointF((float)((double)this.Width / 2.0 - (double)graphics.MeasureString(this.Text, this.Font).ToSize().Width / 2.0), (float)((double)this.Height / 2.0 - (double)graphics.MeasureString(this.Text, this.Font).ToSize().Height / 2.0)));
  755. Brush brush2 = new SolidBrush(this.ForeColor);
  756. graphics.DrawString(this.Text, this.Font, brush2, point);
  757. brush2.Dispose();
  758. Image image = this.Image;
  759. Point point2 = new Point((int)Math.Round(unchecked((double)e.ClipRectangle.Width / 2.0 - (double)this.Image.Width / 2.0)), (int)Math.Round(unchecked((double)e.ClipRectangle.Height / 2.0 - (double)this.Image.Height / 2.0)));
  760. graphics.DrawImage(this.Image, point2);
  761. brush.Dispose();
  762. }
  763. catch (Exception arg_409_0)
  764. {
  765. ProjectData.SetProjectError(arg_409_0);
  766. ProjectData.ClearProjectError();
  767. }
  768. }
  769. }
  770. protected override void OnBackColorChanged(EventArgs e)
  771. {
  772. this.IsOnEnter = false;
  773. this.m_OldBkColor = this.BackColor;
  774. this.Invalidate();
  775. }
  776. protected override void OnEnabledChanged(EventArgs e)
  777. {
  778. this.Invalidate();
  779. }
  780. protected override void OnMouseEnter(EventArgs e)
  781. {
  782. if (!this.Enabled)
  783. {
  784. return;
  785. }
  786. this.m_OldBkColor = this.BackColor;
  787. this.IsOnEnter = true;
  788. this.IsOnLeave = false;
  789. this.Invalidate();
  790. }
  791. protected override void OnMouseLeave(EventArgs e)
  792. {
  793. this.IsOnEnter = false;
  794. this.IsOnLeave = true;
  795. this.Invalidate();
  796. }
  797. protected override void OnClick(EventArgs e)
  798. {
  799. base.OnClick(e);
  800. this.IsClicked = true;
  801. this.IsOnEnter = false;
  802. this.Invalidate();
  803. }
  804. }
  805. }