Advertisement
MaximeSony

Thème Perplex #C

Jun 28th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 21.66 KB | None | 0 0
  1. Voir : http://prntscr.com/bm1qxi
  2. La source du thème Perplex
  3.  
  4.  
  5. using System;
  6. using System.ComponentModel;
  7. using System.Drawing;
  8. using System.Drawing.Drawing2D;
  9. using System.Windows.Forms;
  10. public enum MouseState : byte
  11. {
  12. None = 0,
  13. Over = 1,
  14. Down = 2,
  15. Block = 3,
  16. }
  17. public static class Draw
  18. {
  19. public static GraphicsPath RoundRect(Rectangle rect, int Curve)
  20. {
  21. GraphicsPath P = new GraphicsPath();
  22. int ArcRectWidth = Curve * 2;
  23. P.AddArc(new Rectangle(rect.X, rect.Y, ArcRectWidth, ArcRectWidth), -180, 90);
  24. P.AddArc(new Rectangle(rect.Width - ArcRectWidth + rect.X, rect.Y, ArcRectWidth, ArcRectWidth), -90, 90);
  25. P.AddArc(new Rectangle(rect.Width - ArcRectWidth + rect.X, rect.Height - ArcRectWidth + rect.Y, ArcRectWidth, ArcRectWidth), 0, 90);
  26. P.AddArc(new Rectangle(rect.X, rect.Height - ArcRectWidth + rect.Y, ArcRectWidth, ArcRectWidth), 90, 90);
  27. P.AddLine(new Point(rect.X, rect.Height - ArcRectWidth + rect.Y), new Point(rect.X, Curve + rect.Y));
  28. return P;
  29. }
  30. public static GraphicsPath RoundRect(int X, int Y, int Width, int Height, int Curve)
  31. {
  32. return RoundRect(new Rectangle(X, Y, Width, Height), Curve);
  33. }
  34. }
  35. public class PerplexTheme : ContainerControl
  36. {
  37. public PerplexTheme()
  38. {
  39. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  40. SetStyle(ControlStyles.UserPaint, true);
  41. BackColor = Color.FromArgb(25, 25, 25);
  42. DoubleBuffered = true;
  43. }
  44. protected override void OnPaint(PaintEventArgs e)
  45. {
  46. Bitmap B = new Bitmap(Width, Height);
  47. Graphics G = Graphics.FromImage(B);
  48. Rectangle TopLeft = new Rectangle(0, 0, Width - 125, 28);
  49. Rectangle TopRight = new Rectangle(Width - 82, 0, 81, 28);
  50. Rectangle Body = new Rectangle(10, 10, Width - 21, Height - 16);
  51. Rectangle Body2 = new Rectangle(5, 5, Width - 11, Height - 6);
  52. base.OnPaint(e);
  53. LinearGradientBrush BodyBrush = new LinearGradientBrush(Body2, Color.FromArgb(25, 25, 25), Color.FromArgb(30, 35, 48), 90);
  54. LinearGradientBrush BodyBrush2 = new LinearGradientBrush(Body, Color.FromArgb(46, 46, 46), Color.FromArgb(50, 55, 58), 120);
  55. LinearGradientBrush gloss = new LinearGradientBrush(new Rectangle(0, 0, Width - 128, 28 / 2), Color.FromArgb(240, Color.FromArgb(26, 26, 26)), Color.FromArgb(5, 255, 255, 255), 90);
  56. LinearGradientBrush gloss2 = new LinearGradientBrush(new Rectangle(Width - 82, 0, Width - 205, 28 / 2), Color.FromArgb(240, Color.FromArgb(26, 26, 26)), Color.FromArgb(5, 255, 255, 255), 90);
  57. LinearGradientBrush mainbrush = new LinearGradientBrush(TopLeft, Color.FromArgb(26, 26, 26), Color.FromArgb(30, 30, 30), 90);
  58. LinearGradientBrush mainbrush2 = new LinearGradientBrush(TopRight, Color.FromArgb(26, 26, 26), Color.FromArgb(30, 30, 30), 90);
  59. Pen P1 = new Pen(Color.FromArgb(174, 195, 30), 2);
  60. Font drawFont = new Font("Tahoma", 10, FontStyle.Bold);
  61.  
  62. G.Clear(Color.Fuchsia);
  63. G.FillPath(BodyBrush, Draw.RoundRect(Body2, 3));
  64. G.DrawPath(Pens.Black, Draw.RoundRect(Body2, 3));
  65.  
  66. G.FillPath(BodyBrush2, Draw.RoundRect(Body, 3));
  67. G.DrawPath(Pens.Black, Draw.RoundRect(Body, 3));
  68.  
  69. G.FillPath(mainbrush, Draw.RoundRect(TopLeft, 3));
  70. G.FillPath(gloss, Draw.RoundRect(TopLeft, 3));
  71. G.DrawPath(Pens.Black, Draw.RoundRect(TopLeft, 3));
  72.  
  73. G.FillPath(mainbrush, Draw.RoundRect(TopRight, 3));
  74. G.FillPath(gloss2, Draw.RoundRect(TopRight, 3));
  75. G.DrawPath(Pens.Black, Draw.RoundRect(TopRight, 3));
  76.  
  77. G.DrawLine(P1, 14, 9, 14, 22);
  78. G.DrawLine(P1, 17, 6, 17, 25);
  79. G.DrawLine(P1, 20, 9, 20, 22);
  80. G.DrawLine(P1, 11, 12, 11, 19);
  81. G.DrawLine(P1, 23, 12, 23, 19);
  82. G.DrawLine(P1, 8, 14, 8, 17);
  83. G.DrawLine(P1, 26, 14, 26, 17);
  84. G.DrawString(Text, drawFont, new SolidBrush(Color.WhiteSmoke), new Rectangle(32, 1, Width - 1, 27), new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center });
  85. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  86. G.Dispose();
  87. B.Dispose();
  88. }
  89. private Point MouseP = new Point(0, 0);
  90. private bool cap = false;
  91. private int moveheight = 29;
  92. protected override void OnMouseDown(MouseEventArgs e)
  93. {
  94. base.OnMouseDown(e);
  95. if (e.Button == MouseButtons.Left && new Rectangle(0, 0, Width, moveheight).Contains(e.Location))
  96. {
  97. cap = true;
  98. MouseP = e.Location;
  99. }
  100. }
  101. protected override void OnMouseUp(MouseEventArgs e)
  102. {
  103. base.OnMouseUp(e);
  104. cap = false;
  105. }
  106. protected override void OnMouseMove(MouseEventArgs e)
  107. {
  108. base.OnMouseMove(e);
  109. if (cap)
  110. {
  111. Point p = new Point();
  112. p.X = MousePosition.X - MouseP.X;
  113. p.Y = MousePosition.Y - MouseP.Y;
  114. Parent.Location = p;
  115. }
  116. }
  117. protected override void OnCreateControl()
  118. {
  119. base.OnCreateControl();
  120. ParentForm.FormBorderStyle = FormBorderStyle.None;
  121. ParentForm.TransparencyKey = Color.Fuchsia;
  122. Dock = DockStyle.Fill;
  123. }
  124. }
  125. public class PerplexButton : Control
  126. {
  127. MouseState State = MouseState.None;
  128. protected override void OnMouseDown(MouseEventArgs e)
  129. {
  130. base.OnMouseDown(e);
  131. State = MouseState.Down;
  132. Invalidate();
  133. }
  134. protected override void OnMouseUp(MouseEventArgs e)
  135. {
  136. base.OnMouseUp(e);
  137. State = MouseState.Over;
  138. Invalidate();
  139. }
  140. protected override void OnMouseEnter(EventArgs e)
  141. {
  142. base.OnMouseEnter(e);
  143. State = MouseState.Over;
  144. Invalidate();
  145. }
  146. protected override void OnMouseLeave(EventArgs e)
  147. {
  148. base.OnMouseLeave(e);
  149. State = MouseState.None;
  150. Invalidate();
  151. }
  152. public PerplexButton()
  153. {
  154. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  155. SetStyle(ControlStyles.UserPaint, true);
  156. BackColor = Color.Transparent;
  157. ForeColor = Color.FromArgb(205, 205, 205);
  158. DoubleBuffered = true;
  159. }
  160.  
  161. protected override void OnPaint(PaintEventArgs e)
  162. {
  163. Bitmap B = new Bitmap(Width, Height);
  164. Graphics G = Graphics.FromImage(B);
  165. Rectangle ClientRectangle = new Rectangle(0, 0, Width - 1, Height - 1);
  166. base.OnPaint(e);
  167. G.Clear(BackColor);
  168. Font drawFont = new Font("Tahoma", 8, FontStyle.Bold);
  169. G.SmoothingMode = SmoothingMode.HighQuality;
  170. Rectangle R1 = new Rectangle(0, 0, Width - 125, 35 / 2);
  171. Rectangle R2 = new Rectangle(5, Height - 10, Width - 11, 5);
  172. Rectangle R3 = new Rectangle(6, Height - 9, Width - 13, 3);
  173. Rectangle R4 = new Rectangle(1, 1, Width - 3, Height - 3);
  174. Rectangle R5 = new Rectangle(1, 0, Width - 1, Height - 1);
  175. Rectangle R6 = new Rectangle(0, -1, Width - 1, Height - 1);
  176. LinearGradientBrush lgb = new LinearGradientBrush(ClientRectangle, Color.FromArgb(66, 67, 70), Color.FromArgb(43, 44, 48), 90);
  177. LinearGradientBrush botbar = new LinearGradientBrush(R2, Color.FromArgb(44, 45, 49), Color.FromArgb(45, 46, 50), 90);
  178. LinearGradientBrush fill = new LinearGradientBrush(R3, Color.FromArgb(174, 195, 30), Color.FromArgb(141, 153, 16), 90);
  179. LinearGradientBrush gloss = null;
  180. Pen o = new Pen(Color.FromArgb(50, 50, 50), 1);
  181. StringFormat format = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
  182. if (State == MouseState.Over)
  183. gloss = new LinearGradientBrush(R1, Color.FromArgb(15, Color.FromArgb(26, 26, 26)), Color.FromArgb(1, 255, 255, 255), 90);
  184. else if (State == MouseState.Down)
  185. gloss = new LinearGradientBrush(R1, Color.FromArgb(100, Color.FromArgb(26, 26, 26)), Color.FromArgb(1, 255, 255, 255), 90);
  186. else
  187. gloss = new LinearGradientBrush(R1, Color.FromArgb(75, Color.FromArgb(26, 26, 26)), Color.FromArgb(3, 255, 255, 255), 90);
  188.  
  189. G.FillPath(lgb, Draw.RoundRect(ClientRectangle, 2));
  190. G.FillPath(gloss, Draw.RoundRect(ClientRectangle, 2));
  191. G.FillPath(botbar, Draw.RoundRect(R2, 1));
  192. G.FillPath(fill, Draw.RoundRect(R3, 1));
  193. G.DrawPath(o, Draw.RoundRect(ClientRectangle, 2));
  194. G.DrawPath(Pens.Black, Draw.RoundRect(R4, 2));
  195. G.DrawString(Text, drawFont, new SolidBrush(Color.FromArgb(5, 5, 5)), R5, format);
  196. G.DrawString(Text, drawFont, new SolidBrush(Color.FromArgb(205, 205, 205)), R6, format);
  197.  
  198. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  199. G.Dispose();
  200. B.Dispose();
  201. }
  202. }
  203. public class PerplexControlBox : Control
  204. {
  205. MouseState State = MouseState.None;
  206. Rectangle MinBtn = new Rectangle(0, 0, 20, 20);
  207. Rectangle MaxBtn = new Rectangle(25, 0, 20, 20);
  208. int x = 0;
  209.  
  210. protected override void OnMouseDown(MouseEventArgs e)
  211. {
  212. base.OnMouseDown(e);
  213. if (e.Location.X > 0 && e.Location.X < 20)
  214. FindForm().WindowState = FormWindowState.Minimized;
  215. else if (e.Location.X > 25 && e.Location.X < 45)
  216. FindForm().Close();
  217. State = MouseState.Down;
  218. Invalidate();
  219. }
  220. protected override void OnMouseUp(MouseEventArgs e)
  221. {
  222. base.OnMouseUp(e);
  223. State = MouseState.Over;
  224. Invalidate();
  225. }
  226. protected override void OnMouseEnter(EventArgs e)
  227. {
  228. base.OnMouseEnter(e);
  229. State = MouseState.Over;
  230. Invalidate();
  231. }
  232. protected override void OnMouseLeave(EventArgs e)
  233. {
  234. base.OnMouseLeave(e);
  235. State = MouseState.None;
  236. Invalidate();
  237. }
  238. public PerplexControlBox()
  239. {
  240. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  241. SetStyle(ControlStyles.UserPaint, true);
  242. BackColor = Color.Transparent;
  243. ForeColor = Color.FromArgb(205, 205, 205);
  244. DoubleBuffered = true;
  245. }
  246. protected override void OnPaint(PaintEventArgs e)
  247. {
  248. Bitmap B = new Bitmap(Width, Height);
  249. Graphics G = Graphics.FromImage(B);
  250. base.OnPaint(e);
  251. G.Clear(BackColor);
  252. G.SmoothingMode = SmoothingMode.HighQuality;
  253.  
  254. LinearGradientBrush mlgb = null;
  255. Font mf = new Font("Marlett", 9);
  256. SolidBrush mfb = new SolidBrush(Color.FromArgb(174, 195, 30));
  257. Pen P1 = new Pen(Color.FromArgb(21, 21, 21), 1);
  258. Color C1 = Color.FromArgb(66, 67, 70);
  259. Color C2 = Color.FromArgb(43, 44, 48);
  260. GraphicsPath GP1 = Draw.RoundRect(MinBtn, 4);
  261. GraphicsPath GP2 = Draw.RoundRect(MaxBtn, 4);
  262. switch (State)
  263. {
  264. case MouseState.None:
  265. mlgb = new LinearGradientBrush(MinBtn, C1, C2, 90);
  266. G.FillPath(mlgb, GP1);
  267. G.DrawPath(P1, GP1);
  268. G.DrawString("0", mf, mfb, 4, 4);
  269.  
  270. G.FillPath(mlgb, GP2);
  271. G.DrawPath(P1, GP2);
  272. G.DrawString("r", mf, mfb, 28, 4);
  273. break;
  274. case MouseState.Over:
  275. if (x > 0 && x < 20)
  276. {
  277. mlgb = new LinearGradientBrush(MinBtn, Color.FromArgb(100, C1), Color.FromArgb(100, C2), 90);
  278. G.FillPath(mlgb, GP1);
  279. G.DrawPath(P1, GP1);
  280. G.DrawString("0", mf, mfb, 4, 4);
  281.  
  282. mlgb = new LinearGradientBrush(MaxBtn, C1, C2, 90);
  283. G.FillPath(mlgb, Draw.RoundRect(MaxBtn, 4));
  284. G.DrawPath(P1, GP2);
  285. G.DrawString("r", mf, mfb, 4, 4);
  286. }
  287. else if (x > 25 && x < 45)
  288. {
  289. mlgb = new LinearGradientBrush(MinBtn, C1, C2, 90);
  290. G.FillPath(mlgb, GP1);
  291. G.DrawPath(P1, GP1);
  292. G.DrawString("0", mf, mfb, 4, 4);
  293. mlgb = new LinearGradientBrush(MaxBtn, Color.FromArgb(100, C1), Color.FromArgb(100, C2), 90);
  294. G.FillPath(mlgb, GP2);
  295. G.DrawPath(P1, GP2);
  296. G.DrawString("r", mf, mfb, 28, 4);
  297. }
  298. else
  299. {
  300. mlgb = new LinearGradientBrush(MinBtn, C1, C2, 90);
  301. G.FillPath(mlgb, GP1);
  302. G.DrawPath(P1, GP1);
  303. G.DrawString("0", mf, mfb, 4, 4);
  304.  
  305. LinearGradientBrush lgb = new LinearGradientBrush(MaxBtn, C1, C2, 90);
  306. G.FillPath(lgb, GP2);
  307. G.DrawPath(P1, GP2);
  308. G.DrawString("r", mf, mfb, 28, 4);
  309. }
  310. break;
  311. case MouseState.Down:
  312. mlgb = new LinearGradientBrush(MinBtn, C1, C2, 90);
  313. G.FillPath(mlgb, GP1);
  314. G.DrawPath(P1, GP1);
  315. G.DrawString("0", mf, mfb, 4, 4);
  316.  
  317. mlgb = new LinearGradientBrush(MaxBtn, C1, C2, 90);
  318. G.FillPath(mlgb, GP2);
  319. G.DrawPath(P1, GP2);
  320. G.DrawString("r", mf, mfb, 28, 4);
  321. break;
  322. default:
  323. mlgb = new LinearGradientBrush(MinBtn, C1, C2, 90);
  324. G.FillPath(mlgb, GP1);
  325. G.DrawPath(P1, GP1);
  326. G.DrawString("0", mf, mfb, 4, 4);
  327.  
  328. mlgb = new LinearGradientBrush(MaxBtn, C1, C2, 90);
  329. G.FillPath(mlgb, GP2);
  330. G.DrawPath(P1, GP2);
  331. G.DrawString("r", mf, mfb, 28, 4);
  332. break;
  333. }
  334. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  335. G.Dispose();
  336. B.Dispose();
  337. }
  338. }
  339. public class PerplexGroupBox : ContainerControl
  340. {
  341. public PerplexGroupBox()
  342. {
  343. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  344. BackColor = Color.Transparent;
  345. DoubleBuffered = true;
  346. }
  347. protected override void OnPaint(PaintEventArgs e)
  348. {
  349. Bitmap B = new Bitmap(Width, Height);
  350. Graphics G = Graphics.FromImage(B);
  351. Rectangle Body = new Rectangle(4, 25, Width - 9, Height - 30);
  352. Rectangle Body2 = new Rectangle(0, 0, Width - 1, Height - 1);
  353. base.OnPaint(e);
  354. G.Clear(Color.Transparent);
  355. G.SmoothingMode = SmoothingMode.HighQuality;
  356. G.CompositingQuality = CompositingQuality.HighQuality;
  357.  
  358. Pen P1 = new Pen(Color.Black);
  359. LinearGradientBrush BodyBrush = new LinearGradientBrush(Body2, Color.FromArgb(26, 26, 26), Color.FromArgb(30, 30, 30), 90);
  360. LinearGradientBrush BodyBrush2 = new LinearGradientBrush(Body, Color.FromArgb(46, 46, 46), Color.FromArgb(50, 55, 58), 120);
  361. Font drawFont = new Font("Tahoma", 9, FontStyle.Bold);
  362. G.FillPath(BodyBrush, Draw.RoundRect(Body2, 3));
  363. G.DrawPath(P1, Draw.RoundRect(Body2, 3));
  364.  
  365. G.FillPath(BodyBrush2, Draw.RoundRect(Body, 3));
  366. G.DrawPath(P1, Draw.RoundRect(Body, 3));
  367.  
  368. G.DrawString(Text, drawFont, new SolidBrush(Color.WhiteSmoke), 67, 14, new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  369. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  370. G.Dispose();
  371. B.Dispose();
  372. }
  373. }
  374. public class PerplexProgressBar : Control
  375. {
  376. private int _Maximum = 100;
  377.  
  378. public int Maximum
  379. {
  380. get { return _Maximum; }
  381. set
  382. {
  383. _Maximum = value;
  384. Invalidate();
  385. }
  386. }
  387. private int _Value = 0;
  388. public int Value
  389. {
  390. get
  391. {
  392. if (_Value == 0)
  393. return 0;
  394. else return _Value;
  395. }
  396. set
  397. {
  398. _Value = value;
  399. if (_Value > _Maximum)
  400. _Value = _Maximum;
  401. Invalidate();
  402. }
  403. }
  404. private bool _ShowPercentage = false;
  405. public bool ShowPercentage
  406. {
  407. get { return _ShowPercentage; }
  408. set
  409. {
  410. _ShowPercentage = value;
  411. Invalidate();
  412. }
  413. }
  414.  
  415. public PerplexProgressBar()
  416. : base()
  417. {
  418. DoubleBuffered = true;
  419. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  420. SetStyle(ControlStyles.UserPaint, true);
  421. BackColor = Color.Transparent;
  422. }
  423.  
  424. protected override void OnPaint(PaintEventArgs e)
  425. {
  426. Bitmap B = new Bitmap(Width, Height);
  427. Graphics G = Graphics.FromImage(B);
  428.  
  429. G.SmoothingMode = SmoothingMode.HighQuality;
  430.  
  431. double val = (double)_Value / _Maximum;
  432. int intValue = Convert.ToInt32(val * Width);
  433. G.Clear(BackColor);
  434. Color C1 = Color.FromArgb(174, 195, 30);
  435. Color C2 = Color.FromArgb(141, 153, 16);
  436. Rectangle R1 = new Rectangle(0, 0, Width - 1, Height - 1);
  437. Rectangle R2 = new Rectangle(0, 0, intValue - 1, Height - 1);
  438. Rectangle R3 = new Rectangle(0, 0, intValue - 1, Height - 2);
  439. GraphicsPath GP1 = Draw.RoundRect(R1, 1);
  440. GraphicsPath GP2 = Draw.RoundRect(R2, 2);
  441. GraphicsPath GP3 = Draw.RoundRect(R3, 1);
  442. LinearGradientBrush gB = new LinearGradientBrush(R1, Color.FromArgb(26, 26, 26), Color.FromArgb(30, 30, 30), 90);
  443. LinearGradientBrush g1 = new LinearGradientBrush(new Rectangle(2, 2, intValue - 1, Height - 2), C1, C2, 90);
  444. HatchBrush h1 = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Color.FromArgb(50, C1), Color.FromArgb(25, C2));
  445. Pen P1 = new Pen(Color.Black);
  446.  
  447. G.FillPath(gB, GP1);
  448. G.FillPath(g1, GP3);
  449. G.FillPath(h1, GP3);
  450. G.DrawPath(P1, GP1);
  451. G.DrawPath(new Pen(Color.FromArgb(150, 97, 94, 90)), GP2);
  452. G.DrawPath(P1, GP2);
  453.  
  454. if (_ShowPercentage)
  455. G.DrawString(Convert.ToString(string.Concat(Value, "%")), Font, Brushes.White, R1, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  456.  
  457. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  458. G.Dispose();
  459. B.Dispose();
  460. }
  461. }
  462. [DefaultEvent("CheckedChanged")]
  463. public class PerplexCheckBox : Control
  464. {
  465. MouseState State = MouseState.None;
  466. protected override void OnMouseDown(MouseEventArgs e)
  467. {
  468. base.OnMouseDown(e);
  469. State = MouseState.Down;
  470. Invalidate();
  471. }
  472. protected override void OnMouseUp(MouseEventArgs e)
  473. {
  474. base.OnMouseUp(e);
  475. State = MouseState.Over;
  476. Invalidate();
  477. }
  478. protected override void OnMouseEnter(EventArgs e)
  479. {
  480. base.OnMouseEnter(e);
  481. State = MouseState.Over;
  482. Invalidate();
  483. }
  484. protected override void OnMouseLeave(EventArgs e)
  485. {
  486. base.OnMouseLeave(e);
  487. State = MouseState.None;
  488. Invalidate();
  489. }
  490. protected override void OnSizeChanged(EventArgs e)
  491. {
  492. base.OnSizeChanged(e);
  493. Height = 16;
  494. }
  495. protected override void OnTextChanged(EventArgs e)
  496. {
  497. base.OnTextChanged(e);
  498. Invalidate();
  499. }
  500. protected override void OnClick(EventArgs e)
  501. {
  502. _Checked = !_Checked;
  503. if (CheckedChanged != null)
  504. CheckedChanged(this, EventArgs.Empty);
  505. base.OnClick(e);
  506. }
  507. private bool _Checked = false;
  508. public bool Checked
  509. {
  510. get { return _Checked; }
  511. set
  512. {
  513. _Checked = value;
  514. if (CheckedChanged != null)
  515. CheckedChanged(this, EventArgs.Empty);
  516. Invalidate();
  517. }
  518. }
  519. public PerplexCheckBox()
  520. {
  521. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  522. SetStyle(ControlStyles.UserPaint, true);
  523. BackColor = Color.Transparent;
  524. ForeColor = Color.Black;
  525. Size = new Size(145, 16);
  526. DoubleBuffered = true;
  527. }
  528. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  529. {
  530. Bitmap B = new Bitmap(Width, Height);
  531. Graphics G = Graphics.FromImage(B);
  532. G.SmoothingMode = SmoothingMode.HighQuality;
  533. G.CompositingQuality = CompositingQuality.HighQuality;
  534. Rectangle checkBoxRectangle = new Rectangle(0, 0, Height - 1, Height - 1);
  535. LinearGradientBrush bodyGrad = new LinearGradientBrush(checkBoxRectangle, Color.FromArgb(174, 195, 30), Color.FromArgb(141, 153, 16), 90);
  536. SolidBrush nb = new SolidBrush(Color.FromArgb(205, 205, 205));
  537. StringFormat format = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center };
  538. Font drawFont = new Font("Tahoma", 9, FontStyle.Bold);
  539. G.Clear(BackColor);
  540. G.FillRectangle(bodyGrad, bodyGrad.Rectangle);
  541. G.DrawRectangle(new Pen(Color.Black), checkBoxRectangle);
  542. G.DrawString(Text, drawFont, Brushes.Black, new Point(17, 9), format);
  543. G.DrawString(Text, drawFont, nb, new Point(16, 8), format);
  544.  
  545. if (_Checked)
  546. {
  547. Rectangle chkPoly = new Rectangle(checkBoxRectangle.X + checkBoxRectangle.Width / 4, checkBoxRectangle.Y + checkBoxRectangle.Height / 4, checkBoxRectangle.Width / 2, checkBoxRectangle.Height / 2);
  548. Point[] p = new Point[] {new Point(chkPoly.X, chkPoly.Y + chkPoly.Height /2),
  549. new Point(chkPoly.X + chkPoly.Width / 2, chkPoly.Y + chkPoly.Height),
  550. new Point(chkPoly.X + chkPoly.Width, chkPoly.Y)};
  551. Pen P1 = new Pen(Color.FromArgb(12, 12, 12), 2);
  552. for (int i = 0; i <= p.Length - 2; i++)
  553. G.DrawLine(P1, p, p[i + 1]);
  554. }
  555. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  556. G.Dispose();
  557. B.Dispose();
  558. }
  559.  
  560. public event EventHandler CheckedChanged;
  561. }
  562. [DefaultEvent("CheckedChanged")]
  563. public class PerplexRadioButton : Control
  564. {
  565. MouseState State = MouseState.None;
  566. protected override void OnMouseDown(MouseEventArgs e)
  567. {
  568. base.OnMouseDown(e);
  569. State = MouseState.Down;
  570. Invalidate();
  571. }
  572. protected override void OnMouseUp(MouseEventArgs e)
  573. {
  574. base.OnMouseUp(e);
  575. State = MouseState.Over;
  576. Invalidate();
  577. }
  578. protected override void OnMouseEnter(EventArgs e)
  579. {
  580. base.OnMouseEnter(e);
  581. State = MouseState.Over;
  582. Invalidate();
  583. }
  584. protected override void OnMouseLeave(EventArgs e)
  585. {
  586. base.OnMouseLeave(e);
  587. State = MouseState.None;
  588. Invalidate();
  589. }
  590. protected override void OnSizeChanged(EventArgs e)
  591. {
  592. base.OnSizeChanged(e);
  593. Height = 16;
  594. }
  595. protected override void OnTextChanged(EventArgs e)
  596. {
  597. base.OnTextChanged(e);
  598. Invalidate();
  599. }
  600. protected override void OnClick(EventArgs e)
  601. {
  602. Checked = !Checked;
  603. base.OnClick(e);
  604. }
  605. private bool _Checked = false;
  606. public bool Checked
  607. {
  608. get { return _Checked; }
  609. set
  610. {
  611. _Checked = value;
  612. InvalidateControls();
  613. if (CheckedChanged != null)
  614. CheckedChanged(this, EventArgs.Empty);
  615. Invalidate();
  616. }
  617. }
  618. protected override void OnCreateControl()
  619. {
  620. base.OnCreateControl();
  621. InvalidateControls();
  622. }
  623. private void InvalidateControls()
  624. {
  625. if (!IsHandleCreated || !_Checked) return;
  626. foreach (Control C in Parent.Controls)
  627. if (C is PerplexRadioButton && C != this)
  628. ((PerplexRadioButton)C).Checked = false;
  629. }
  630. public PerplexRadioButton()
  631. {
  632. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  633. SetStyle(ControlStyles.UserPaint, true);
  634. BackColor = Color.Transparent;
  635. ForeColor = Color.Black;
  636. Size = new Size(150, 16);
  637. DoubleBuffered = true;
  638. }
  639. protected override void OnPaint(PaintEventArgs e)
  640. {
  641. Bitmap B = new Bitmap(Width, Height);
  642. Graphics G = Graphics.FromImage(B);
  643. G.Clear(BackColor);
  644. Rectangle radioBtnRectangle = new Rectangle(0, 0, Height - 1, Height - 1);
  645. Rectangle R1 = new Rectangle(4, 4, Height - 9, Height - 9);
  646. StringFormat format = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Near };
  647. LinearGradientBrush bgGrad = new LinearGradientBrush(radioBtnRectangle, Color.FromArgb(174, 195, 30), Color.FromArgb(141, 153, 16), 90);
  648. Color C1 = Color.FromArgb(250, 15, 15, 15);
  649. SolidBrush nb = new SolidBrush(Color.FromArgb(205, 205, 205));
  650. G.SmoothingMode = SmoothingMode.HighQuality;
  651. G.CompositingQuality = CompositingQuality.HighQuality;
  652. Font drawFont = new Font("Tahoma", 10, FontStyle.Bold);
  653.  
  654. G.FillEllipse(bgGrad, radioBtnRectangle);
  655. G.DrawEllipse(new Pen(Color.Black), radioBtnRectangle);
  656.  
  657. if (Checked)
  658. {
  659. LinearGradientBrush chkGrad = new LinearGradientBrush(R1, C1, C1, 90);
  660. G.FillEllipse(chkGrad, R1);
  661. }
  662.  
  663. G.DrawString(Text, drawFont, Brushes.Black, new Point(17, 2), format);
  664. G.DrawString(Text, drawFont, nb, new Point(16, 1), format);
  665.  
  666. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  667. G.Dispose();
  668. B.Dispose();
  669. }
  670. public event EventHandler CheckedChanged;
  671. }
  672. public class PerplexLabel : Control
  673. {
  674. public PerplexLabel()
  675. {
  676. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  677. SetStyle(ControlStyles.UserPaint, true);
  678. BackColor = Color.Transparent;
  679. ForeColor = Color.FromArgb(205, 205, 205);
  680. DoubleBuffered = true;
  681. }
  682. protected override void OnPaint(PaintEventArgs e)
  683. {
  684. Bitmap B = new Bitmap(Width, Height);
  685. Graphics G = Graphics.FromImage(B);
  686. Rectangle ClientRectangle = new Rectangle(0, 0, Width - 1, Height - 1);
  687. base.OnPaint(e);
  688. G.Clear(BackColor);
  689. Font drawFont = new Font("Tahoma", 9, FontStyle.Bold);
  690. StringFormat format = new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center };
  691. G.CompositingQuality = CompositingQuality.HighQuality;
  692. G.SmoothingMode = SmoothingMode.HighQuality;
  693. G.DrawString(Text, drawFont, new SolidBrush(Color.FromArgb(5, 5, 5)), new Rectangle(1, 0, Width - 1, Height - 1), format);
  694. G.DrawString(Text, drawFont, new SolidBrush(Color.FromArgb(205, 205, 205)), new Rectangle(0, -1, Width - 1, Height - 1), format);
  695. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  696. G.Dispose();
  697. B.Dispose();
  698. }
  699. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement