Advertisement
Astekk

Foxtheme

Dec 17th, 2014
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.17 KB | None | 0 0
  1.  
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Drawing;
  9. using System.Drawing.Drawing2D;
  10.  
  11. /// <summary>
  12. /// Created by DoggyCollin
  13. /// HF link: http://www.hackforums.net/member.php?action=profile&uid=1278211
  14. /// </summary>
  15.  
  16. internal static class FoxSettings
  17. {
  18. public static Pen BorderColor = new Pen(Color.FromArgb(49, 49, 49));
  19. public static SolidBrush TextColor = new SolidBrush(Color.FromArgb(249, 249, 249));
  20. public static SolidBrush TextColorDark = new SolidBrush(Color.FromArgb(66, 66, 66));
  21. public static SolidBrush FillheaderColor = new SolidBrush(Color.FromArgb(237, 237, 237));
  22. public static SolidBrush FillbodyColor = new SolidBrush(Color.FromArgb(250, 250, 250));
  23.  
  24. public static SolidBrush UpColor = new SolidBrush(Color.FromArgb(255, 136, 83)); // Orange(255, 136, 83), Green(116, 214, 36), Blue(90, 160, 220), Red(232, 67, 67)
  25. public static SolidBrush DownColor = new SolidBrush(Color.FromArgb(UpColor.Color.R - 33, UpColor.Color.G - 33, UpColor.Color.B - 33));
  26.  
  27. public static Font TextFont = new Font("Verdana", 8.0F);
  28. }
  29.  
  30. internal class FoxTheme : Control
  31. {
  32. /// <summary>
  33. /// Gets or sets the visibility of the icon copied from the parent control.
  34. /// </summary>
  35. public bool ShowIcon { get { return _showIcon; } set { _showIcon = value; Invalidate(); } }
  36. private bool _showIcon;
  37.  
  38. private Graphics G;
  39.  
  40. private Pen borderColor;
  41. private SolidBrush textColor;
  42. private SolidBrush fillheaderColor;
  43. private SolidBrush fillbodyColor;
  44.  
  45. public FoxTheme()
  46. {
  47. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true);
  48. borderColor = FoxSettings.BorderColor;
  49. textColor = FoxSettings.TextColor;
  50. fillheaderColor = FoxSettings.FillheaderColor;
  51. fillbodyColor = FoxSettings.FillbodyColor;
  52.  
  53. //Set defaults
  54. Font = FoxSettings.TextFont;
  55. ForeColor = textColor.Color;
  56. }
  57.  
  58. protected override void OnHandleCreated(EventArgs e)
  59. {
  60. Dock = DockStyle.Fill;
  61. if (Parent is Form)
  62. {
  63. Form tempWith1 = (Form)Parent;
  64. tempWith1.FormBorderStyle = 0;
  65. tempWith1.TransparencyKey = Color.Fuchsia;
  66. tempWith1.BackColor = fillheaderColor.Color;
  67. }
  68. base.OnHandleCreated(e);
  69. }
  70.  
  71. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  72. {
  73. if (new Rectangle(Parent.Location.X, Parent.Location.Y, Width, 22).IntersectsWith(new Rectangle(MousePosition.X, MousePosition.Y, 1, 1)))
  74. {
  75. Capture = false;
  76. Message M = Message.Create(Parent.Handle, 161, new IntPtr(2), IntPtr.Zero);
  77. DefWndProc(ref M);
  78. }
  79. base.OnMouseDown(e);
  80. }
  81.  
  82. protected override void OnPaintBackground(PaintEventArgs pevent) { }
  83.  
  84. protected override void OnPaint(PaintEventArgs e)
  85. {
  86. var B = new Bitmap(Width, Height);
  87. using (var G = Graphics.FromImage(B))
  88. {
  89. G.DrawPath(new Pen(fillheaderColor.Color), RoundedRectangle.Create(0, 0, Width, Height, 4));
  90. G.FillPath(fillheaderColor, RoundedRectangle.Create(0, 0, Width, Height, 4));
  91.  
  92. G.DrawString(Text, Font, new SolidBrush(Color.FromArgb(66, 66, 66)), new Point(5, 5));
  93.  
  94. G.DrawPath(new Pen(fillbodyColor.Color), RoundedRectangle.Create(6, 22, Width - 13, Height - 28, 4));
  95. G.FillPath(fillbodyColor, RoundedRectangle.Create(6, 22, Width - 13, Height - 28, 4));
  96.  
  97. G.DrawPath(new Pen(Color.LightGray), RoundedRectangle.Create(0, 0, Width - 1, Height - 1, 4));
  98.  
  99. G.FillRectangle(new SolidBrush(Color.Fuchsia), new Rectangle(0, 0, 2, 2));
  100. G.FillRectangle(new SolidBrush(Color.Fuchsia), new Rectangle(Width - 2, 0, 2, 2));
  101. G.FillRectangle(new SolidBrush(Color.Fuchsia), new Rectangle(Width - 2, Height - 2, 2, 2));
  102. G.FillRectangle(new SolidBrush(Color.Fuchsia), new Rectangle(0, Height - 2, 2, 2));
  103.  
  104. B.SetPixel(1, 1, fillheaderColor.Color);
  105. B.SetPixel(Width - 2, 1, fillheaderColor.Color);
  106. B.SetPixel(Width - 2, Height - 2, fillheaderColor.Color);
  107. B.SetPixel(1, Height - 2, fillheaderColor.Color);
  108.  
  109. e.Graphics.DrawImage(B, 0, 0);
  110. }
  111.  
  112. B.Dispose();
  113. }
  114. }
  115.  
  116. internal class FoxButton : Control
  117. {
  118. private Graphics G;
  119. private bool isMouseDown;
  120.  
  121. private Pen borderColor;
  122. private SolidBrush textColor;
  123. private SolidBrush fillColor;
  124. private SolidBrush downColor;
  125.  
  126. private StringFormat stringformat;
  127. private Font textFont;
  128.  
  129. public FoxButton()
  130. {
  131. borderColor = FoxSettings.BorderColor;
  132. textColor = FoxSettings.TextColor;
  133. fillColor = FoxSettings.UpColor;
  134. downColor = FoxSettings.DownColor;
  135.  
  136. stringformat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
  137. textFont = FoxSettings.TextFont;
  138.  
  139. //Set defaults
  140. Font = FoxSettings.TextFont;
  141. ForeColor = textColor.Color;
  142. }
  143.  
  144. protected override void OnMouseDown(MouseEventArgs e)
  145. {
  146. isMouseDown = true;
  147. Invalidate();
  148. }
  149.  
  150. protected override void OnMouseUp(MouseEventArgs e)
  151. {
  152. isMouseDown = false;
  153. Invalidate();
  154. }
  155.  
  156. protected override void OnPaint(PaintEventArgs e)
  157. {
  158. G = e.Graphics;
  159. G.Clear(BackColor);
  160. G.SmoothingMode = SmoothingMode.HighQuality;
  161.  
  162. SolidBrush currentBrush;
  163.  
  164. if (isMouseDown)
  165. currentBrush = downColor;
  166. else
  167. currentBrush = fillColor;
  168.  
  169. LinearGradientBrush linGrBrush = GraphicsHelper.CreateGradient(Width, Height, currentBrush);
  170.  
  171. G.DrawPath(new Pen(currentBrush), RoundedRectangle.Create(0, 0, Width, Height, 4));
  172. G.FillPath(linGrBrush, RoundedRectangle.Create(0, 0, Width, Height, 4));
  173. G.DrawString(Text, textFont, textColor, new Point(Width / 2, Height / 2), stringformat);
  174. }
  175. }
  176.  
  177. internal class FoxSystemButton : Control
  178. {
  179. private Graphics G;
  180. private bool isMouseDown;
  181.  
  182. private Pen borderColor;
  183. private SolidBrush textColor;
  184. private SolidBrush fillColor;
  185. private SolidBrush downColor;
  186. public SolidBrush upColor;
  187.  
  188. private StringFormat stringformat;
  189. private Font textFont;
  190.  
  191. public enum BType
  192. {
  193. Close,
  194. Minimize
  195. }
  196.  
  197. public BType ButtonType { get; set; }
  198.  
  199. public FoxSystemButton()
  200. {
  201. borderColor = FoxSettings.BorderColor;
  202. textColor = FoxSettings.TextColor;
  203. fillColor = FoxSettings.FillheaderColor;
  204. downColor = FoxSettings.DownColor;
  205. upColor = FoxSettings.UpColor;
  206.  
  207. stringformat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
  208. textFont = FoxSettings.TextFont;
  209.  
  210. //Set defaults
  211. Font = FoxSettings.TextFont;
  212. ForeColor = textColor.Color;
  213. ButtonType = BType.Close;
  214. Size = new Size(14, 14);
  215. }
  216.  
  217. protected override void OnMouseDown(MouseEventArgs e)
  218. {
  219. isMouseDown = true;
  220. Invalidate();
  221. }
  222.  
  223. protected override void OnMouseUp(MouseEventArgs e)
  224. {
  225. isMouseDown = false;
  226. Invalidate();
  227.  
  228. var form = FindForm();
  229.  
  230. if (this.ClientRectangle.Contains(e.Location))
  231. {
  232. if (ButtonType == BType.Close)
  233. form.Close();
  234. else if (ButtonType == BType.Minimize)
  235. form.WindowState = FormWindowState.Minimized;
  236. }
  237. }
  238.  
  239. protected override void OnPaint(PaintEventArgs e)
  240. {
  241. G = e.Graphics;
  242. G.Clear(BackColor);
  243. G.SmoothingMode = SmoothingMode.HighQuality;
  244.  
  245. SolidBrush currentBrush;
  246.  
  247. if (isMouseDown)
  248. currentBrush = downColor;
  249. else
  250. currentBrush = upColor;
  251.  
  252. G.DrawRectangle(new Pen(fillColor.Color), new Rectangle(0, 0, 14, 14));
  253. G.FillRectangle(fillColor, new Rectangle(0, 0, 14, 14));
  254.  
  255. if (ButtonType == BType.Close)
  256. {
  257. G.DrawLine(new Pen(currentBrush, 1.6f), 2, 2, 10, 10);
  258. G.DrawLine(new Pen(currentBrush, 1.6f), 10, 2, 2, 10);
  259. }
  260. else if (ButtonType == BType.Minimize)
  261. {
  262. G.DrawLine(new Pen(currentBrush, 2f), 2, 10, 10, 10);
  263. }
  264. }
  265.  
  266. public static void DrawRoundedRectangle(Graphics g, Rectangle r, int d, Pen p)
  267. {
  268. System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
  269.  
  270. gp.AddArc(r.X, r.Y, d, d, 180, 90);
  271. gp.AddArc(r.X + r.Width - d, r.Y, d, d, 270, 90);
  272. gp.AddArc(r.X + r.Width - d, r.Y + r.Height - d, d, d, 0, 90);
  273. gp.AddArc(r.X, r.Y + r.Height - d, d, d, 90, 90);
  274. gp.AddLine(r.X, r.Y + r.Height - d, r.X, r.Y + d / 2);
  275.  
  276. g.DrawPath(p, gp);
  277. }
  278. }
  279.  
  280. internal class FoxProgressBar : Control
  281. {
  282. /// <summary>
  283. /// Value in percentage.
  284. /// </summary>
  285. public float Value { get { return _value; } set { _value = value; Invalidate(); } }
  286. private float _value;
  287.  
  288. /// <summary>
  289. /// Sets or gets the visibility setting for the percentage value.
  290. /// </summary>
  291. public bool ShowPercentage { get; set; }
  292.  
  293. private Graphics G;
  294.  
  295. private Pen borderColor;
  296. private SolidBrush textColor;
  297. private SolidBrush fillColor;
  298. private SolidBrush bodyColor;
  299. private SolidBrush downColor;
  300. private SolidBrush upColor;
  301.  
  302. private StringFormat stringformat;
  303. private Font textFont;
  304.  
  305. public FoxProgressBar()
  306. {
  307. this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  308.  
  309. borderColor = FoxSettings.BorderColor;
  310. textColor = FoxSettings.TextColor;
  311. fillColor = FoxSettings.FillheaderColor;
  312. bodyColor = FoxSettings.FillbodyColor;
  313. downColor = FoxSettings.DownColor;
  314. upColor = FoxSettings.UpColor;
  315.  
  316. stringformat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
  317. textFont = FoxSettings.TextFont;
  318. ShowPercentage = true;
  319.  
  320. //Set defaults
  321. Font = FoxSettings.TextFont;
  322. ForeColor = textColor.Color;
  323. }
  324.  
  325. protected override void OnPaint(PaintEventArgs e)
  326. {
  327. G = e.Graphics;
  328. G.Clear(bodyColor.Color);
  329. G.SmoothingMode = SmoothingMode.HighQuality;
  330.  
  331. float percent = ((float)Width / 100) * Value;
  332.  
  333. LinearGradientBrush linGrBrush = GraphicsHelper.CreateGradient(Width, Height, upColor);
  334.  
  335. G.FillPath(fillColor, RoundedRectangle.Create(0, 0, Width - 1, Height - 1, 4));
  336.  
  337. if ((int)percent <= 0)
  338. G.FillPath(fillColor, RoundedRectangle.Create(0, 1, (int)percent, Height - 2, 4));
  339. else
  340. G.FillPath(linGrBrush, RoundedRectangle.Create(0, 1, (int)percent, Height - 2, 4));
  341.  
  342. G.DrawPath(new Pen(Color.LightGray), RoundedRectangle.Create(0, 0, Width - 1, Height - 1, 4));
  343.  
  344.  
  345. var myColor = Value > 50 ? textColor.Color : Color.FromArgb(textColor.Color.ToArgb() ^ 0xffffff);
  346. if (ShowPercentage)
  347. G.DrawString(string.Format("{0}%", Value), textFont, new SolidBrush(myColor), new Point((Width + 2) / 2, (Height + 2) / 2), stringformat);
  348. }
  349. }
  350.  
  351. internal class FoxTabControl : TabControl
  352. {
  353. private Pen borderColor;
  354. private SolidBrush textColor;
  355. private SolidBrush fillColor;
  356. private SolidBrush downColor;
  357. private SolidBrush upColor;
  358. private SolidBrush fillbodyColor;
  359.  
  360. private Font textFont;
  361.  
  362. public FoxTabControl()
  363. {
  364. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  365. DoubleBuffered = true;
  366. SizeMode = TabSizeMode.Fixed;
  367.  
  368. this.TabItemWidth = 120;
  369. this.TabItemHeight = 30;
  370. this.Alignment = TabAlignment.Left;
  371. ItemSize = new Size(TabItemHeight, TabItemWidth);
  372.  
  373. borderColor = FoxSettings.BorderColor;
  374. textColor = FoxSettings.TextColor;
  375. fillColor = FoxSettings.FillheaderColor;
  376. downColor = FoxSettings.DownColor;
  377. upColor = FoxSettings.UpColor;
  378. fillbodyColor = FoxSettings.FillbodyColor;
  379.  
  380. textFont = FoxSettings.TextFont;
  381.  
  382. //Set defaults
  383. Font = FoxSettings.TextFont;
  384. ForeColor = textColor.Color;
  385. }
  386.  
  387. protected override void OnPaint(PaintEventArgs e)
  388. {
  389. Bitmap B = new Bitmap(Width, Height);
  390.  
  391. if (Alignment == TabAlignment.Top)
  392. DrawTopTabControl(Graphics.FromImage(B));
  393. else if (Alignment == TabAlignment.Right)
  394. DrawRightTabControl(Graphics.FromImage(B));
  395. else if (Alignment == TabAlignment.Bottom)
  396. DrawBottomTabControl(Graphics.FromImage(B));
  397. else if (Alignment == TabAlignment.Left)
  398. DrawLeftTabControl(Graphics.FromImage(B));
  399.  
  400. e.Graphics.DrawImage((Image)B.Clone(), 0, 4);
  401. B.Dispose();
  402. }
  403.  
  404. private void DrawTopTabControl(Graphics G)
  405. {
  406. G.Clear(fillbodyColor.Color);
  407.  
  408. for (int i = 0; i <= TabCount - 1; i++)
  409. {
  410. Rectangle x2 = new Rectangle(new Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), new Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1));
  411.  
  412. G.FillRectangle(textColor, new Rectangle(new Point(x2.Location.X, x2.Location.Y), new Size(GetTabRect(i).Size.Width, GetTabRect(i).Size.Height)));
  413. if (i == SelectedIndex)
  414. {
  415. G.FillPath(upColor, RoundedRectangle.Create(new Rectangle(new Point(x2.Location.X, GetTabRect(i).Size.Height - 5), new Size(GetTabRect(i).Size.Width, 5)), 2));
  416. G.DrawPath(new Pen(upColor.Color), RoundedRectangle.Create(new Rectangle(new Point(x2.Location.X, GetTabRect(i).Size.Height - 5), new Size(GetTabRect(i).Size.Width, 3)), 2));
  417. }
  418.  
  419. G.DrawString(TabPages[i].Text, Font, FoxSettings.TextColorDark, new Rectangle(x2.Location.X, x2.Location.Y, x2.Width, x2.Height), new StringFormat
  420. {
  421. LineAlignment = StringAlignment.Center,
  422. Alignment = StringAlignment.Center
  423. });
  424. }
  425.  
  426. G.Dispose();
  427. }
  428.  
  429. private void DrawRightTabControl(Graphics G)
  430. {
  431. G.Clear(fillbodyColor.Color);
  432.  
  433. for (int i = 0; i <= TabCount - 1; i++)
  434. {
  435. Rectangle x2 = new Rectangle(new Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), new Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1));
  436.  
  437. G.FillRectangle(textColor, new Rectangle(new Point(x2.Location.X, x2.Location.Y), new Size(GetTabRect(i).Size.Width, GetTabRect(i).Size.Height)));
  438. if (i == SelectedIndex)
  439. {
  440. G.FillPath(upColor, RoundedRectangle.Create(new Rectangle(new Point(x2.Location.X, x2.Location.Y), new Size(5, GetTabRect(i).Size.Height)), 2));
  441. G.DrawPath(new Pen(upColor.Color), RoundedRectangle.Create(new Rectangle(new Point(x2.Location.X, x2.Location.Y), new Size(3, GetTabRect(i).Size.Height)), 2));
  442. }
  443.  
  444. G.DrawString(TabPages[i].Text, Font, new SolidBrush(Color.FromArgb(66, 66, 66)), new Rectangle(x2.Location.X + 10, x2.Location.Y, x2.Width, x2.Height), new StringFormat
  445. {
  446. LineAlignment = StringAlignment.Center,
  447. Alignment = StringAlignment.Near
  448. });
  449. }
  450.  
  451. G.Dispose();
  452. }
  453.  
  454. private void DrawBottomTabControl(Graphics G)
  455. {
  456. G.Clear(fillbodyColor.Color);
  457.  
  458. for (int i = 0; i <= TabCount - 1; i++)
  459. {
  460. Rectangle x2 = new Rectangle(new Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), new Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1));
  461.  
  462. G.FillRectangle(textColor, new Rectangle(new Point(x2.Location.X, x2.Location.Y), new Size(GetTabRect(i).Size.Width, GetTabRect(i).Size.Height)));
  463. if (i == SelectedIndex)
  464. {
  465. G.FillPath(upColor, RoundedRectangle.Create(new Rectangle(new Point(x2.Location.X, x2.Location.Y - 5), new Size(GetTabRect(i).Size.Width, 5)), 2));
  466. G.DrawPath(new Pen(upColor.Color), RoundedRectangle.Create(new Rectangle(new Point(x2.Location.X, x2.Location.Y - 5), new Size(GetTabRect(i).Size.Width, 3)), 2));
  467. }
  468.  
  469. G.DrawString(TabPages[i].Text, Font, new SolidBrush(Color.FromArgb(66, 66, 66)), new Rectangle(x2.Location.X, x2.Location.Y, x2.Width, x2.Height), new StringFormat
  470. {
  471. LineAlignment = StringAlignment.Center,
  472. Alignment = StringAlignment.Center
  473. });
  474. }
  475.  
  476. G.Dispose();
  477. }
  478.  
  479. private void DrawLeftTabControl(Graphics G)
  480. {
  481. G.Clear(fillbodyColor.Color);
  482.  
  483. for (int i = 0; i <= TabCount - 1; i++)
  484. {
  485. Rectangle x2 = new Rectangle(new Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), new Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1));
  486.  
  487. G.FillRectangle(textColor, new Rectangle(new Point(x2.Location.X, x2.Location.Y), new Size(GetTabRect(i).Size.Width, GetTabRect(i).Size.Height)));
  488. if (i == SelectedIndex)
  489. {
  490. G.FillPath(upColor, RoundedRectangle.Create(new Rectangle(new Point(GetTabRect(i).Size.Width - 5, x2.Location.Y), new Size(5, GetTabRect(i).Size.Height)), 2));
  491. G.DrawPath(new Pen(upColor.Color), RoundedRectangle.Create(new Rectangle(new Point(GetTabRect(i).Size.Width - 5, x2.Location.Y), new Size(3, GetTabRect(i).Size.Height)), 2));
  492. }
  493.  
  494. G.DrawString(TabPages[i].Text, Font, new SolidBrush(Color.FromArgb(66, 66, 66)), new Rectangle(x2.Location.X, x2.Location.Y, x2.Width - 20, x2.Height), new StringFormat
  495. {
  496. LineAlignment = StringAlignment.Center,
  497. Alignment = StringAlignment.Far
  498. });
  499. }
  500.  
  501. G.Dispose();
  502. }
  503.  
  504. private int tabItemWidth;
  505. public int TabItemWidth { get { return tabItemWidth; } set { tabItemWidth = value; RefreshItemSize(); } }
  506.  
  507. private int tabItemHeight;
  508. public int TabItemHeight { get { return tabItemHeight; } set { tabItemHeight = value; RefreshItemSize(); } }
  509.  
  510. public void RefreshItemSize()
  511. {
  512. if (Alignment == TabAlignment.Top || Alignment == TabAlignment.Bottom)
  513. ItemSize = new Size(TabItemWidth, TabItemHeight);
  514. else if (Alignment == TabAlignment.Left || Alignment == TabAlignment.Right)
  515. ItemSize = new Size(TabItemHeight, TabItemWidth);
  516.  
  517. Invalidate();
  518. }
  519.  
  520. public override Color BackColor
  521. {
  522. get
  523. {
  524. return fillbodyColor.Color;
  525. }
  526. set
  527. {
  528. base.BackColor = value;
  529. }
  530. }
  531.  
  532. public TabAlignment TabItemAlignment
  533. {
  534. get
  535. {
  536. return base.Alignment;
  537. }
  538. set
  539. {
  540. base.Alignment = value;
  541. RefreshItemSize();
  542. }
  543. }
  544.  
  545. protected override void OnControlAdded(ControlEventArgs e)
  546. {
  547. e.Control.BackColor = fillbodyColor.Color;
  548. e.Control.Invalidate();
  549. }
  550.  
  551. }
  552.  
  553. internal class FoxCheckBox : Control
  554. {
  555. public bool Checked { get; set; }
  556. public CheckStyleType CheckStyle { get; set; }
  557.  
  558. private Graphics G;
  559.  
  560. private Pen borderColor;
  561. private SolidBrush textColor;
  562. private SolidBrush fillColor;
  563. private SolidBrush downColor;
  564. private SolidBrush upColor;
  565.  
  566. private StringFormat stringformat;
  567. private Font textFont;
  568.  
  569. public FoxCheckBox()
  570. {
  571. borderColor = new Pen(Color.LightGray);
  572. textColor = FoxSettings.TextColorDark;
  573. fillColor = FoxSettings.FillheaderColor;
  574. downColor = FoxSettings.DownColor;
  575. upColor = FoxSettings.UpColor;
  576.  
  577. stringformat = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center };
  578. textFont = FoxSettings.TextFont;
  579.  
  580. //Set defaults
  581. Font = FoxSettings.TextFont;
  582. ForeColor = textColor.Color;
  583. Checked = true;
  584. CheckStyle = CheckStyleType.Square;
  585. }
  586.  
  587. protected override void OnPaint(PaintEventArgs e)
  588. {
  589. G = e.Graphics;
  590.  
  591. switch (CheckStyle)
  592. {
  593. case CheckStyleType.Square:
  594. G.DrawRectangle(borderColor, new Rectangle(0, 0, 12, 12));
  595. G.DrawString(Text, textFont, textColor, 14, 0);
  596.  
  597. if (Checked)
  598. G.FillRectangle(GraphicsHelper.CreateGradient(2, 9, upColor), new Rectangle(2, 2, 9, 9));
  599. break;
  600. case CheckStyleType.Round:
  601. G.DrawEllipse(borderColor, new Rectangle(0, 0, 13, 13));
  602. G.DrawString(Text, textFont, textColor, 14, 0);
  603.  
  604. if (Checked)
  605. G.FillEllipse(GraphicsHelper.CreateGradient(2, 9, upColor), new Rectangle(2, 2, 9, 9));
  606. break;
  607. case CheckStyleType.Checkmark:
  608. G.DrawRectangle(borderColor, new Rectangle(0, 0, 12, 12));
  609. G.DrawString(Text, textFont, textColor, 14, 0);
  610.  
  611. if (Checked)
  612. {
  613. G.DrawString("\u221A", new Font("serif", 6, FontStyle.Bold), upColor, 3, 3);
  614. //G.DrawLine(new Pen(downColor.Color, 2), 3, 5, 7, 9);
  615. //G.DrawLine(new Pen(downColor.Color, 2), 6, 9, 9, 3);
  616. }
  617. break;
  618. default:
  619. break;
  620. }
  621. }
  622.  
  623. protected override void OnMouseClick(MouseEventArgs e)
  624. {
  625. Checked = !Checked;
  626. Invalidate();
  627. }
  628.  
  629. public enum CheckStyleType
  630. {
  631. Square = 0,
  632. Round = 1,
  633. Checkmark = 2
  634. }
  635. }
  636.  
  637. internal class FoxChartControl : Control
  638. {
  639. private Pen borderColor;
  640. private SolidBrush textColor;
  641. private SolidBrush fillheaderColor;
  642. private SolidBrush fillbodyColor;
  643.  
  644. private Color colorStripes;
  645. private Color colorValues;
  646. private Color colorText;
  647.  
  648. public float[] Values { get; set; }
  649.  
  650. public float? ValueMin { get; set; }
  651. public float? ValueMax { get; set; }
  652. public float ValueStripes { get; set; }
  653.  
  654. public float SizeStripes { get; set; }
  655. public float SizeValues { get; set; }
  656.  
  657. public Font FontText { get; set; }
  658.  
  659. public FoxChartControl()
  660. {
  661. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true);
  662. borderColor = FoxSettings.BorderColor;
  663. textColor = FoxSettings.TextColor;
  664. fillheaderColor = FoxSettings.FillheaderColor;
  665. fillbodyColor = FoxSettings.FillbodyColor;
  666.  
  667. //Set defaults
  668. Font = FoxSettings.TextFont;
  669. ForeColor = textColor.Color;
  670. BackColor = fillbodyColor.Color;
  671.  
  672. Values = new float[] { };
  673.  
  674. ValueMax = null;
  675. ValueMin = null;
  676. ValueStripes = 10;
  677.  
  678. SizeStripes = 1;
  679. SizeValues = 4;
  680.  
  681. colorStripes = Color.LightGray;
  682. colorValues = FoxSettings.UpColor.Color;
  683. colorText = Color.Black;
  684.  
  685. FontText = FoxSettings.TextFont;
  686. }
  687.  
  688. protected override void OnPaint(PaintEventArgs e)
  689. {
  690. var G = e.Graphics;
  691.  
  692. float max = ValueMax ?? (Values.Count() > 0 ? Values.Max() : 0);
  693. float min = ValueMin ?? (Values.Count() > 0 ? Values.Min() : 0);
  694.  
  695. float averagegeCount = (max - min) / ValueStripes;
  696. float currentCount = max;
  697.  
  698. G.SmoothingMode = SmoothingMode.HighQuality;
  699.  
  700. float startWidthPosition = ValueMax == null
  701. ? GraphicsHelper.GetTextWidthInPixels(Values.Select(a => a.ToString()).OrderByDescending(a => a.Length).FirstOrDefault(), FontText)
  702. : GraphicsHelper.GetTextWidthInPixels(ValueMax.ToString(), FontText);
  703.  
  704. float chartHeight = Height - 17;
  705. float itemHeight = 10;
  706.  
  707. G.FillPath(fillheaderColor, RoundedRectangle.Create(0, 0, Width - 1, Height - 1, 4));
  708.  
  709. for (int i = 0; i <= ValueStripes; i++)
  710. {
  711. G.DrawLine(new Pen(ColorStripes, SizeStripes), startWidthPosition, itemHeight, Width, itemHeight);
  712. G.DrawString((Math.Floor(currentCount)).ToString(), FontText, new SolidBrush(ColorText), 0, itemHeight - 7);
  713. itemHeight += chartHeight / ValueStripes;
  714. currentCount -= averagegeCount;
  715. }
  716.  
  717. float lastItemHeight = (chartHeight - (chartHeight / (max - min) * (Values.FirstOrDefault() - min))) + 10;
  718. float lastItemWidth = startWidthPosition;
  719. float itemWidth = startWidthPosition;
  720.  
  721. foreach (var value in Values)
  722. {
  723. var valueMin = value - min;
  724.  
  725. var item = chartHeight - (chartHeight / (max - min) * valueMin);
  726. item = item == chartHeight ? chartHeight + 10 : item + 10;
  727.  
  728. var currentBrush = FoxSettings.UpColor;
  729. G.DrawLine(new Pen(currentBrush.Color, SizeValues), lastItemWidth, lastItemHeight, itemWidth, item);
  730. G.FillEllipse(currentBrush, itemWidth - (SizeValues / 2), item - (SizeValues / 2), SizeValues, SizeValues);
  731.  
  732. lastItemHeight = item;
  733. lastItemWidth = itemWidth;
  734. itemWidth += Width / Values.Count();
  735. }
  736. }
  737.  
  738. public Color ColorStripes
  739. {
  740. get
  741. {
  742. return this.colorStripes;
  743. }
  744. set
  745. {
  746. this.colorStripes = value;
  747. }
  748. }
  749.  
  750. public Color ColorValues
  751. {
  752. get
  753. {
  754. return this.colorValues;
  755. }
  756. set
  757. {
  758. this.colorValues = value;
  759. }
  760. }
  761.  
  762. public Color ColorText
  763. {
  764. get
  765. {
  766. return this.colorText;
  767. }
  768. set
  769. {
  770. this.colorText = value;
  771. }
  772. }
  773. }
  774.  
  775. internal class FoxLabel : Control
  776. {
  777. private SolidBrush textColor;
  778. private Font textFont;
  779.  
  780. public FoxLabel()
  781. {
  782. textColor = FoxSettings.TextColorDark;
  783. textFont = FoxSettings.TextFont;
  784.  
  785. //Set defaults
  786. Font = FoxSettings.TextFont;
  787. ForeColor = textColor.Color;
  788. }
  789.  
  790. protected override void OnPaint(PaintEventArgs e)
  791. {
  792. var G = e.Graphics;
  793. G.DrawString(Text, textFont, textColor, 0, 0);
  794. }
  795. }
  796.  
  797.  
  798. public abstract class RoundedRectangle
  799. {
  800. public enum RectangleCorners
  801. {
  802. None = 0, TopLeft = 1, TopRight = 2, BottomLeft = 4, BottomRight = 8,
  803. All = TopLeft | TopRight | BottomLeft | BottomRight
  804. }
  805.  
  806. public static GraphicsPath Create(int x, int y, int width, int height,
  807. int radius, RectangleCorners corners)
  808. {
  809. int xw = x + width;
  810. int yh = y + height;
  811. int xwr = xw - radius;
  812. int yhr = yh - radius;
  813. int xr = x + radius;
  814. int yr = y + radius;
  815. int r2 = radius * 2;
  816. int xwr2 = xw - r2 - 1;
  817. int yhr2 = yh - r2 - 1;
  818.  
  819. GraphicsPath p = new GraphicsPath();
  820. p.StartFigure();
  821.  
  822. //Top Left Corner
  823. if ((RectangleCorners.TopLeft & corners) == RectangleCorners.TopLeft)
  824. {
  825. p.AddArc(x, y, r2, r2, 180, 90);
  826. }
  827. else
  828. {
  829. p.AddLine(x, yr, x, y);
  830. p.AddLine(x, y, xr, y);
  831. }
  832.  
  833. //Top Edge
  834. p.AddLine(xr, y, xwr, y);
  835.  
  836. //Top Right Corner
  837. if ((RectangleCorners.TopRight & corners) == RectangleCorners.TopRight)
  838. {
  839. p.AddArc(xwr2, y, r2, r2, 270, 90);
  840. }
  841. else
  842. {
  843. p.AddLine(xwr, y, xw, y);
  844. p.AddLine(xw, y, xw, yr);
  845. }
  846.  
  847. //Right Edge
  848. p.AddLine(xw, yr, xw, yhr);
  849.  
  850. //Bottom Right Corner
  851. if ((RectangleCorners.BottomRight & corners) == RectangleCorners.BottomRight)
  852. {
  853. p.AddArc(xwr2, yhr2, r2, r2, 0, 90);
  854. }
  855. else
  856. {
  857. p.AddLine(xw, yhr, xw, yh);
  858. p.AddLine(xw, yh, xwr, yh);
  859. }
  860.  
  861. //Bottom Edge
  862. p.AddLine(xwr, yh, xr, yh);
  863.  
  864. //Bottom Left Corner
  865. if ((RectangleCorners.BottomLeft & corners) == RectangleCorners.BottomLeft)
  866. {
  867. p.AddArc(x, yhr2, r2, r2, 90, 90);
  868. }
  869. else
  870. {
  871. p.AddLine(xr, yh, x, yh);
  872. p.AddLine(x, yh, x, yhr);
  873. }
  874.  
  875. //Left Edge
  876. p.AddLine(x, yhr, x, yr);
  877.  
  878. p.CloseFigure();
  879. return p;
  880. }
  881.  
  882. public static GraphicsPath Create(Rectangle rect, int radius, RectangleCorners c)
  883. { return Create(rect.X, rect.Y, rect.Width, rect.Height, radius, c); }
  884.  
  885. public static GraphicsPath Create(int x, int y, int width, int height, int radius)
  886. { return Create(x, y, width, height, radius, RectangleCorners.All); }
  887.  
  888. public static GraphicsPath Create(Rectangle rect, int radius)
  889. { return Create(rect.X, rect.Y, rect.Width, rect.Height, radius); }
  890.  
  891. public static GraphicsPath Create(int x, int y, int width, int height)
  892. { return Create(x, y, width, height, 5); }
  893.  
  894. public static GraphicsPath Create(Rectangle rect)
  895. { return Create(rect.X, rect.Y, rect.Width, rect.Height); }
  896. }
  897.  
  898. public static class GraphicsHelper
  899. {
  900. public static float GetTextWidthInPixels(string text, Font font)
  901. {
  902. var size = TextRenderer.MeasureText(text, font);
  903. return size.Width;
  904. }
  905.  
  906. public static LinearGradientBrush CreateGradient(float width, float height, SolidBrush brush)
  907. {
  908. var linGrBrush = new LinearGradientBrush(
  909. new RectangleF(width, height, width, height),
  910. Color.FromArgb(255, brush.Color.R - 33, brush.Color.G - 33, brush.Color.B - 33),
  911. brush.Color, 90F);
  912.  
  913. float[] relativeIntensities = { 0.0f, 0.5f, 1.0f };
  914. float[] relativePositions = { 0.0f, 0.2f, 1.0f };
  915.  
  916. Blend blend = new Blend();
  917. blend.Factors = relativeIntensities;
  918. blend.Positions = relativePositions;
  919. linGrBrush.Blend = blend;
  920.  
  921. return linGrBrush;
  922. }
  923. }
  924.  
  925. // Created by DoggyCollin
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement