Ambiance Theme C#


SUBMITTED BY: Guest

DATE: Sept. 11, 2014, 5:13 a.m.

FORMAT: C#

SIZE: 115.6 kB

HITS: 882

  1. #region Imports
  2. using System;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. #endregion
  10. #region RoundRectangle
  11. static class RoundRectangle
  12. {
  13. public static GraphicsPath RoundRect(Rectangle Rectangle, int Curve)
  14. {
  15. GraphicsPath P = new GraphicsPath();
  16. int ArcRectangleWidth = Curve * 2;
  17. P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90);
  18. P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90);
  19. P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90);
  20. P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90);
  21. P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
  22. return P;
  23. }
  24. public static GraphicsPath RoundRect(int X, int Y, int Width, int Height, int Curve)
  25. {
  26. Rectangle Rectangle = new Rectangle(X, Y, Width, Height);
  27. GraphicsPath P = new GraphicsPath();
  28. int ArcRectangleWidth = Curve * 2;
  29. P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90);
  30. P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90);
  31. P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90);
  32. P.AddArc(new Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90);
  33. P.AddLine(new Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), new Point(Rectangle.X, Curve + Rectangle.Y));
  34. return P;
  35. }
  36. public static GraphicsPath RoundedTopRect(Rectangle Rectangle, int Curve)
  37. {
  38. GraphicsPath P = new GraphicsPath();
  39. int ArcRectangleWidth = Curve * 2;
  40. P.AddArc(new Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90);
  41. P.AddArc(new Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90);
  42. P.AddLine(new Point(Rectangle.X + Rectangle.Width, Rectangle.Y + ArcRectangleWidth), new Point(Rectangle.X + Rectangle.Width, Rectangle.Y + Rectangle.Height - 1));
  43. P.AddLine(new Point(Rectangle.X, Rectangle.Height - 1 + Rectangle.Y), new Point(Rectangle.X, Rectangle.Y + Curve));
  44. return P;
  45. }
  46. }
  47. #endregion
  48. //|------DO-NOT-REMOVE------|
  49. //
  50. // Creator: HazelDev
  51. // Site : HazelDev.co.nr
  52. // Created: 20.Aug.2014
  53. // Changed: 8.Sep.2014
  54. // Version: 1.0.0
  55. //
  56. //|------DO-NOT-REMOVE------|
  57. #region ThemeContainer
  58. public class Ambiance_ThemeContainer : ContainerControl
  59. {
  60. #region Enums
  61. public enum MouseState
  62. {
  63. None = 0,
  64. Over = 1,
  65. Down = 2,
  66. Block = 3
  67. }
  68. #endregion
  69. #region Variables
  70. private Rectangle HeaderRect;
  71. protected MouseState State;
  72. private int MoveHeight;
  73. private Point MouseP = new Point(0, 0);
  74. private bool Cap = false;
  75. private bool HasShown;
  76. #endregion
  77. #region Properties
  78. private bool _Sizable = true;
  79. public bool Sizable
  80. {
  81. get
  82. {
  83. return _Sizable;
  84. }
  85. set
  86. {
  87. _Sizable = value;
  88. }
  89. }
  90. private bool _SmartBounds = true;
  91. public bool SmartBounds
  92. {
  93. get
  94. {
  95. return _SmartBounds;
  96. }
  97. set
  98. {
  99. _SmartBounds = value;
  100. }
  101. }
  102. private bool _RoundCorners = true;
  103. public bool RoundCorners
  104. {
  105. get
  106. {
  107. return _RoundCorners;
  108. }
  109. set
  110. {
  111. _RoundCorners = value;
  112. Invalidate();
  113. }
  114. }
  115. private bool _IsParentForm;
  116. protected bool IsParentForm
  117. {
  118. get
  119. {
  120. return _IsParentForm;
  121. }
  122. }
  123. protected bool IsParentMdi
  124. {
  125. get
  126. {
  127. if (Parent == null)
  128. {
  129. return false;
  130. }
  131. return Parent.Parent != null;
  132. }
  133. }
  134. private bool _ControlMode;
  135. protected bool ControlMode
  136. {
  137. get
  138. {
  139. return _ControlMode;
  140. }
  141. set
  142. {
  143. _ControlMode = value;
  144. Invalidate();
  145. }
  146. }
  147. private FormStartPosition _StartPosition;
  148. public FormStartPosition StartPosition
  149. {
  150. get
  151. {
  152. if (_IsParentForm && !_ControlMode)
  153. {
  154. return ParentForm.StartPosition;
  155. }
  156. else
  157. {
  158. return _StartPosition;
  159. }
  160. }
  161. set
  162. {
  163. _StartPosition = value;
  164. if (_IsParentForm && !_ControlMode)
  165. {
  166. ParentForm.StartPosition = value;
  167. }
  168. }
  169. }
  170. #endregion
  171. #region EventArgs
  172. protected sealed override void OnParentChanged(EventArgs e)
  173. {
  174. base.OnParentChanged(e);
  175. if (Parent == null)
  176. {
  177. return;
  178. }
  179. _IsParentForm = Parent is Form;
  180. if (!_ControlMode)
  181. {
  182. InitializeMessages();
  183. if (_IsParentForm)
  184. {
  185. this.ParentForm.FormBorderStyle = FormBorderStyle.None;
  186. this.ParentForm.TransparencyKey = Color.Fuchsia;
  187. if (!DesignMode)
  188. {
  189. ParentForm.Shown += FormShown;
  190. }
  191. }
  192. Parent.BackColor = BackColor;
  193. Parent.MinimumSize = new Size(261, 65);
  194. }
  195. }
  196. protected sealed override void OnSizeChanged(EventArgs e)
  197. {
  198. base.OnSizeChanged(e);
  199. if (!_ControlMode)
  200. {
  201. HeaderRect = new Rectangle(0, 0, Width - 14, MoveHeight - 7);
  202. }
  203. Invalidate();
  204. }
  205. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  206. {
  207. base.OnMouseDown(e);
  208. if (e.Button == MouseButtons.Left)
  209. {
  210. SetState(MouseState.Down);
  211. }
  212. if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized || _ControlMode))
  213. {
  214. if (HeaderRect.Contains(e.Location))
  215. {
  216. Capture = false;
  217. WM_LMBUTTONDOWN = true;
  218. DefWndProc(ref Messages[0]);
  219. }
  220. else if (_Sizable && !(Previous == 0))
  221. {
  222. Capture = false;
  223. WM_LMBUTTONDOWN = true;
  224. DefWndProc(ref Messages[Previous]);
  225. }
  226. }
  227. }
  228. protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
  229. {
  230. base.OnMouseUp(e);
  231. Cap = false;
  232. }
  233. protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
  234. {
  235. base.OnMouseMove(e);
  236. if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized))
  237. {
  238. if (_Sizable && !_ControlMode)
  239. {
  240. InvalidateMouse();
  241. }
  242. }
  243. if (Cap)
  244. {
  245. Parent.Location = (System.Drawing.Point)((object)(System.Convert.ToDouble(MousePosition) - System.Convert.ToDouble(MouseP)));
  246. }
  247. }
  248. protected override void OnInvalidated(System.Windows.Forms.InvalidateEventArgs e)
  249. {
  250. base.OnInvalidated(e);
  251. ParentForm.Text = Text;
  252. }
  253. protected override void OnPaintBackground(PaintEventArgs e)
  254. {
  255. base.OnPaintBackground(e);
  256. }
  257. protected override void OnTextChanged(System.EventArgs e)
  258. {
  259. base.OnTextChanged(e);
  260. Invalidate();
  261. }
  262. private void FormShown(object sender, EventArgs e)
  263. {
  264. if (_ControlMode || HasShown)
  265. {
  266. return;
  267. }
  268. if (_StartPosition == FormStartPosition.CenterParent || _StartPosition == FormStartPosition.CenterScreen)
  269. {
  270. Rectangle SB = Screen.PrimaryScreen.Bounds;
  271. Rectangle CB = ParentForm.Bounds;
  272. ParentForm.Location = new Point(SB.Width / 2 - CB.Width / 2, SB.Height / 2 - CB.Width / 2);
  273. }
  274. HasShown = true;
  275. }
  276. #endregion
  277. #region Mouse & Size
  278. private void SetState(MouseState current)
  279. {
  280. State = current;
  281. Invalidate();
  282. }
  283. private Point GetIndexPoint;
  284. private bool B1x;
  285. private bool B2x;
  286. private bool B3;
  287. private bool B4;
  288. private int GetIndex()
  289. {
  290. GetIndexPoint = PointToClient(MousePosition);
  291. B1x = GetIndexPoint.X < 7;
  292. B2x = GetIndexPoint.X > Width - 7;
  293. B3 = GetIndexPoint.Y < 7;
  294. B4 = GetIndexPoint.Y > Height - 7;
  295. if (B1x && B3)
  296. {
  297. return 4;
  298. }
  299. if (B1x && B4)
  300. {
  301. return 7;
  302. }
  303. if (B2x && B3)
  304. {
  305. return 5;
  306. }
  307. if (B2x && B4)
  308. {
  309. return 8;
  310. }
  311. if (B1x)
  312. {
  313. return 1;
  314. }
  315. if (B2x)
  316. {
  317. return 2;
  318. }
  319. if (B3)
  320. {
  321. return 3;
  322. }
  323. if (B4)
  324. {
  325. return 6;
  326. }
  327. return 0;
  328. }
  329. private int Current;
  330. private int Previous;
  331. private void InvalidateMouse()
  332. {
  333. Current = GetIndex();
  334. if (Current == Previous)
  335. {
  336. return;
  337. }
  338. Previous = Current;
  339. switch (Previous)
  340. {
  341. case 0:
  342. Cursor = Cursors.Default;
  343. break;
  344. case 6:
  345. Cursor = Cursors.SizeNS;
  346. break;
  347. case 8:
  348. Cursor = Cursors.SizeNWSE;
  349. break;
  350. case 7:
  351. Cursor = Cursors.SizeNESW;
  352. break;
  353. }
  354. }
  355. private Message[] Messages = new Message[9];
  356. private void InitializeMessages()
  357. {
  358. Messages[0] = Message.Create(Parent.Handle, 161, new IntPtr(2), IntPtr.Zero);
  359. for (int I = 1; I <= 8; I++)
  360. {
  361. Messages[I] = Message.Create(Parent.Handle, 161, new IntPtr(I + 9), IntPtr.Zero);
  362. }
  363. }
  364. private void CorrectBounds(Rectangle bounds)
  365. {
  366. if (Parent.Width > bounds.Width)
  367. {
  368. Parent.Width = bounds.Width;
  369. }
  370. if (Parent.Height > bounds.Height)
  371. {
  372. Parent.Height = bounds.Height;
  373. }
  374. int X = Parent.Location.X;
  375. int Y = Parent.Location.Y;
  376. if (X < bounds.X)
  377. {
  378. X = bounds.X;
  379. }
  380. if (Y < bounds.Y)
  381. {
  382. Y = bounds.Y;
  383. }
  384. int Width = bounds.X + bounds.Width;
  385. int Height = bounds.Y + bounds.Height;
  386. if (X + Parent.Width > Width)
  387. {
  388. X = Width - Parent.Width;
  389. }
  390. if (Y + Parent.Height > Height)
  391. {
  392. Y = Height - Parent.Height;
  393. }
  394. Parent.Location = new Point(X, Y);
  395. }
  396. private bool WM_LMBUTTONDOWN;
  397. protected override void WndProc(ref Message m)
  398. {
  399. base.WndProc(ref m);
  400. if (WM_LMBUTTONDOWN && m.Msg == 513)
  401. {
  402. WM_LMBUTTONDOWN = false;
  403. SetState(MouseState.Over);
  404. if (!_SmartBounds)
  405. {
  406. return;
  407. }
  408. if (IsParentMdi)
  409. {
  410. CorrectBounds(new Rectangle(Point.Empty, Parent.Parent.Size));
  411. }
  412. else
  413. {
  414. CorrectBounds(Screen.FromControl(Parent).WorkingArea);
  415. }
  416. }
  417. }
  418. #endregion
  419. protected override void CreateHandle()
  420. {
  421. base.CreateHandle();
  422. }
  423. public Ambiance_ThemeContainer()
  424. {
  425. SetStyle((ControlStyles)(139270), true);
  426. BackColor = Color.FromArgb(244, 241, 243);
  427. Padding = new Padding(20, 56, 20, 16);
  428. DoubleBuffered = true;
  429. Dock = DockStyle.Fill;
  430. MoveHeight = 48;
  431. Font = new Font("Segoe UI", 9);
  432. }
  433. protected override void OnPaint(PaintEventArgs e)
  434. {
  435. base.OnPaint(e);
  436. Graphics G = e.Graphics;
  437. G.Clear(Color.FromArgb(69, 68, 63));
  438. G.DrawRectangle(new Pen(Color.FromArgb(38, 38, 38)), new Rectangle(0, 0, Width - 1, Height - 1));
  439. // Use [Color.FromArgb(87, 86, 81), Color.FromArgb(60, 59, 55)] for a darker taste
  440. // And replace each (60, 59, 55) with (69, 68, 63)
  441. G.FillRectangle(new LinearGradientBrush(new Point(0, 0), new Point(0, 36), Color.FromArgb(87, 85, 77), Color.FromArgb(69, 68, 63)), new Rectangle(1, 1, Width - 2, 36));
  442. G.FillRectangle(new LinearGradientBrush(new Point(0, 0), new Point(0, Height), Color.FromArgb(69, 68, 63), Color.FromArgb(69, 68, 63)), new Rectangle(1, 36, Width - 2, Height - 46));
  443. G.DrawRectangle(new Pen(Color.FromArgb(38, 38, 38)), new Rectangle(9, 47, Width - 19, Height - 55));
  444. G.FillRectangle(new SolidBrush(Color.FromArgb(244, 241, 243)), new Rectangle(10, 48, Width - 20, Height - 56));
  445. if (_RoundCorners == true)
  446. {
  447. // Draw Left upper corner
  448. G.FillRectangle(Brushes.Fuchsia, 0, 0, 1, 1);
  449. G.FillRectangle(Brushes.Fuchsia, 1, 0, 1, 1);
  450. G.FillRectangle(Brushes.Fuchsia, 2, 0, 1, 1);
  451. G.FillRectangle(Brushes.Fuchsia, 3, 0, 1, 1);
  452. G.FillRectangle(Brushes.Fuchsia, 0, 1, 1, 1);
  453. G.FillRectangle(Brushes.Fuchsia, 0, 2, 1, 1);
  454. G.FillRectangle(Brushes.Fuchsia, 0, 3, 1, 1);
  455. G.FillRectangle(Brushes.Fuchsia, 1, 1, 1, 1);
  456. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), 1, 3, 1, 1);
  457. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), 1, 2, 1, 1);
  458. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), 2, 1, 1, 1);
  459. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), 3, 1, 1, 1);
  460. // Draw right upper corner
  461. G.FillRectangle(Brushes.Fuchsia, Width - 1, 0, 1, 1);
  462. G.FillRectangle(Brushes.Fuchsia, Width - 2, 0, 1, 1);
  463. G.FillRectangle(Brushes.Fuchsia, Width - 3, 0, 1, 1);
  464. G.FillRectangle(Brushes.Fuchsia, Width - 4, 0, 1, 1);
  465. G.FillRectangle(Brushes.Fuchsia, Width - 1, 1, 1, 1);
  466. G.FillRectangle(Brushes.Fuchsia, Width - 1, 2, 1, 1);
  467. G.FillRectangle(Brushes.Fuchsia, Width - 1, 3, 1, 1);
  468. G.FillRectangle(Brushes.Fuchsia, Width - 2, 1, 1, 1);
  469. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), Width - 2, 3, 1, 1);
  470. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), Width - 2, 2, 1, 1);
  471. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), Width - 3, 1, 1, 1);
  472. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), Width - 4, 1, 1, 1);
  473. // Draw Left bottom corner
  474. G.FillRectangle(Brushes.Fuchsia, 0, Height - 1, 1, 1);
  475. G.FillRectangle(Brushes.Fuchsia, 0, Height - 2, 1, 1);
  476. G.FillRectangle(Brushes.Fuchsia, 0, Height - 3, 1, 1);
  477. G.FillRectangle(Brushes.Fuchsia, 0, Height - 4, 1, 1);
  478. G.FillRectangle(Brushes.Fuchsia, 1, Height - 1, 1, 1);
  479. G.FillRectangle(Brushes.Fuchsia, 2, Height - 1, 1, 1);
  480. G.FillRectangle(Brushes.Fuchsia, 3, Height - 1, 1, 1);
  481. G.FillRectangle(Brushes.Fuchsia, 1, Height - 1, 1, 1);
  482. G.FillRectangle(Brushes.Fuchsia, 1, Height - 2, 1, 1);
  483. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), 1, Height - 3, 1, 1);
  484. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), 1, Height - 4, 1, 1);
  485. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), 3, Height - 2, 1, 1);
  486. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), 2, Height - 2, 1, 1);
  487. // Draw right bottom corner
  488. G.FillRectangle(Brushes.Fuchsia, Width - 1, Height, 1, 1);
  489. G.FillRectangle(Brushes.Fuchsia, Width - 2, Height, 1, 1);
  490. G.FillRectangle(Brushes.Fuchsia, Width - 3, Height, 1, 1);
  491. G.FillRectangle(Brushes.Fuchsia, Width - 4, Height, 1, 1);
  492. G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 1, 1, 1);
  493. G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 2, 1, 1);
  494. G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 3, 1, 1);
  495. G.FillRectangle(Brushes.Fuchsia, Width - 2, Height - 1, 1, 1);
  496. G.FillRectangle(Brushes.Fuchsia, Width - 3, Height - 1, 1, 1);
  497. G.FillRectangle(Brushes.Fuchsia, Width - 4, Height - 1, 1, 1);
  498. G.FillRectangle(Brushes.Fuchsia, Width - 1, Height - 4, 1, 1);
  499. G.FillRectangle(Brushes.Fuchsia, Width - 2, Height - 2, 1, 1);
  500. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), Width - 2, Height - 3, 1, 1);
  501. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), Width - 2, Height - 4, 1, 1);
  502. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), Width - 4, Height - 2, 1, 1);
  503. G.FillRectangle(new SolidBrush(Color.FromArgb(38, 38, 38)), Width - 3, Height - 2, 1, 1);
  504. }
  505. G.DrawString(Text, new Font("Tahoma", 12, FontStyle.Bold), new SolidBrush(Color.FromArgb(223, 219, 210)), new Rectangle(0, 14, Width - 1, Height), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Near });
  506. }
  507. }
  508. #endregion
  509. #region ControlBox
  510. public class Ambiance_ControlBox : Control
  511. {
  512. #region Enums
  513. public enum MouseState
  514. {
  515. None = 0,
  516. Over = 1,
  517. Down = 2
  518. }
  519. #endregion
  520. #region MouseStates
  521. MouseState State = MouseState.None;
  522. int X;
  523. Rectangle CloseBtn = new Rectangle(3, 2, 17, 17);
  524. Rectangle MinBtn = new Rectangle(23, 2, 17, 17);
  525. Rectangle MaxBtn = new Rectangle(43, 2, 17, 17);
  526. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  527. {
  528. base.OnMouseDown(e);
  529. State = MouseState.Down;
  530. Invalidate();
  531. }
  532. protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
  533. {
  534. base.OnMouseUp(e);
  535. if (X > 3 && X < 20)
  536. {
  537. FindForm().Close();
  538. }
  539. else if (X > 23 && X < 40)
  540. {
  541. FindForm().WindowState = FormWindowState.Minimized;
  542. }
  543. else if (X > 43 && X < 60)
  544. {
  545. if (_EnableMaximize == true)
  546. {
  547. if (FindForm().WindowState == FormWindowState.Maximized)
  548. {
  549. FindForm().WindowState = FormWindowState.Minimized;
  550. FindForm().WindowState = FormWindowState.Normal;
  551. }
  552. else
  553. {
  554. FindForm().WindowState = FormWindowState.Minimized;
  555. FindForm().WindowState = FormWindowState.Maximized;
  556. }
  557. }
  558. }
  559. State = MouseState.Over;
  560. Invalidate();
  561. }
  562. protected override void OnMouseEnter(System.EventArgs e)
  563. {
  564. base.OnMouseEnter(e);
  565. State = MouseState.Over;
  566. Invalidate();
  567. }
  568. protected override void OnMouseLeave(System.EventArgs e)
  569. {
  570. base.OnMouseLeave(e);
  571. State = MouseState.None;
  572. Invalidate();
  573. }
  574. protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
  575. {
  576. base.OnMouseMove(e);
  577. X = e.Location.X;
  578. Invalidate();
  579. }
  580. #endregion
  581. #region Properties
  582. bool _EnableMaximize = true;
  583. public bool EnableMaximize
  584. {
  585. get
  586. {
  587. return _EnableMaximize;
  588. }
  589. set
  590. {
  591. _EnableMaximize = value;
  592. if (_EnableMaximize == true)
  593. {
  594. this.Size = new Size(64, 22);
  595. }
  596. else
  597. {
  598. this.Size = new Size(44, 22);
  599. }
  600. Invalidate();
  601. }
  602. }
  603. #endregion
  604. public Ambiance_ControlBox()
  605. {
  606. SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer), true);
  607. DoubleBuffered = true;
  608. BackColor = Color.Transparent;
  609. Font = new Font("Marlett", 7);
  610. Anchor = (System.Windows.Forms.AnchorStyles)(AnchorStyles.Top | AnchorStyles.Left);
  611. }
  612. protected override void OnResize(EventArgs e)
  613. {
  614. base.OnResize(e);
  615. if (_EnableMaximize == true)
  616. {
  617. this.Size = new Size(64, 22);
  618. }
  619. else
  620. {
  621. this.Size = new Size(44, 22);
  622. }
  623. }
  624. protected override void OnCreateControl()
  625. {
  626. base.OnCreateControl();
  627. // Auto-decide control location on the theme container
  628. Location = new Point(5, 13);
  629. }
  630. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  631. {
  632. Bitmap B = new Bitmap(Width, Height);
  633. Graphics G = Graphics.FromImage(B);
  634. base.OnPaint(e);
  635. G.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
  636. LinearGradientBrush LGBClose = new LinearGradientBrush(CloseBtn, Color.FromArgb(242, 132, 99), Color.FromArgb(224, 82, 33), 90);
  637. G.FillEllipse(LGBClose, CloseBtn);
  638. G.DrawEllipse(new Pen(Color.FromArgb(57, 56, 53)), CloseBtn);
  639. G.DrawString("r", new Font("Marlett", 7), new SolidBrush(Color.FromArgb(52, 50, 46)), new Rectangle((int)6.5, 8, 0, 0));
  640. LinearGradientBrush LGBMinimize = new LinearGradientBrush(MinBtn, Color.FromArgb(130, 129, 123), Color.FromArgb(103, 102, 96), 90);
  641. G.FillEllipse(LGBMinimize, MinBtn);
  642. G.DrawEllipse(new Pen(Color.FromArgb(57, 56, 53)), MinBtn);
  643. G.DrawString("0", new Font("Marlett", 7), new SolidBrush(Color.FromArgb(52, 50, 46)), new Rectangle(26, (int)4.4, 0, 0));
  644. if (_EnableMaximize == true)
  645. {
  646. LinearGradientBrush LGBMaximize = new LinearGradientBrush(MaxBtn, Color.FromArgb(130, 129, 123), Color.FromArgb(103, 102, 96), 90);
  647. G.FillEllipse(LGBMaximize, MaxBtn);
  648. G.DrawEllipse(new Pen(Color.FromArgb(57, 56, 53)), MaxBtn);
  649. G.DrawString("1", new Font("Marlett", 7), new SolidBrush(Color.FromArgb(52, 50, 46)), new Rectangle(46, 7, 0, 0));
  650. }
  651. switch (State)
  652. {
  653. case MouseState.None:
  654. LinearGradientBrush xLGBClose_1 = new LinearGradientBrush(CloseBtn, Color.FromArgb(242, 132, 99), Color.FromArgb(224, 82, 33), 90);
  655. G.FillEllipse(xLGBClose_1, CloseBtn);
  656. G.DrawEllipse(new Pen(Color.FromArgb(57, 56, 53)), CloseBtn);
  657. G.DrawString("r", new Font("Marlett", 7), new SolidBrush(Color.FromArgb(52, 50, 46)), new Rectangle((int)6.5, 8, 0, 0));
  658. LinearGradientBrush xLGBMinimize_1 = new LinearGradientBrush(MinBtn, Color.FromArgb(130, 129, 123), Color.FromArgb(103, 102, 96), 90);
  659. G.FillEllipse(xLGBMinimize_1, MinBtn);
  660. G.DrawEllipse(new Pen(Color.FromArgb(57, 56, 53)), MinBtn);
  661. G.DrawString("0", new Font("Marlett", 7), new SolidBrush(Color.FromArgb(52, 50, 46)), new Rectangle(26, (int)4.4, 0, 0));
  662. if (_EnableMaximize == true)
  663. {
  664. LinearGradientBrush xLGBMaximize = new LinearGradientBrush(MaxBtn, Color.FromArgb(130, 129, 123), Color.FromArgb(103, 102, 96), 90);
  665. G.FillEllipse(xLGBMaximize, MaxBtn);
  666. G.DrawEllipse(new Pen(Color.FromArgb(57, 56, 53)), MaxBtn);
  667. G.DrawString("1", new Font("Marlett", 7), new SolidBrush(Color.FromArgb(52, 50, 46)), new Rectangle(46, 7, 0, 0));
  668. }
  669. break;
  670. case MouseState.Over:
  671. if (X > 3 && X < 20)
  672. {
  673. LinearGradientBrush xLGBClose = new LinearGradientBrush(CloseBtn, Color.FromArgb(248, 152, 124), Color.FromArgb(231, 92, 45), 90);
  674. G.FillEllipse(xLGBClose, CloseBtn);
  675. G.DrawEllipse(new Pen(Color.FromArgb(57, 56, 53)), CloseBtn);
  676. G.DrawString("r", new Font("Marlett", 7), new SolidBrush(Color.FromArgb(52, 50, 46)), new Rectangle((int)6.5, 8, 0, 0));
  677. }
  678. else if (X > 23 && X < 40)
  679. {
  680. LinearGradientBrush xLGBMinimize = new LinearGradientBrush(MinBtn, Color.FromArgb(196, 196, 196), Color.FromArgb(173, 173, 173), 90);
  681. G.FillEllipse(xLGBMinimize, MinBtn);
  682. G.DrawEllipse(new Pen(Color.FromArgb(57, 56, 53)), MinBtn);
  683. G.DrawString("0", new Font("Marlett", 7), new SolidBrush(Color.FromArgb(52, 50, 46)), new Rectangle(26, (int)4.4, 0, 0));
  684. }
  685. else if (X > 43 && X < 60)
  686. {
  687. if (_EnableMaximize == true)
  688. {
  689. LinearGradientBrush xLGBMaximize = new LinearGradientBrush(MaxBtn, Color.FromArgb(196, 196, 196), Color.FromArgb(173, 173, 173), 90);
  690. G.FillEllipse(xLGBMaximize, MaxBtn);
  691. G.DrawEllipse(new Pen(Color.FromArgb(57, 56, 53)), MaxBtn);
  692. G.DrawString("1", new Font("Marlett", 7), new SolidBrush(Color.FromArgb(52, 50, 46)), new Rectangle(46, 7, 0, 0));
  693. }
  694. }
  695. break;
  696. }
  697. e.Graphics.DrawImage((Image)(B.Clone()), 0, 0);
  698. G.Dispose();
  699. B.Dispose();
  700. }
  701. }
  702. #endregion
  703. #region Button 1
  704. class Ambiance_Button_1 : Control
  705. {
  706. #region Variables
  707. private int MouseState;
  708. private GraphicsPath Shape;
  709. private LinearGradientBrush InactiveGB;
  710. private LinearGradientBrush PressedGB;
  711. private LinearGradientBrush PressedContourGB;
  712. private Rectangle R1;
  713. private Pen P1;
  714. private Pen P3;
  715. private Image _Image;
  716. private Size _ImageSize;
  717. private StringAlignment _TextAlignment = StringAlignment.Center;
  718. private Color _TextColor = Color.FromArgb(150, 150, 150);
  719. private ContentAlignment _ImageAlign = ContentAlignment.MiddleLeft;
  720. #endregion
  721. #region Image Designer
  722. private static PointF ImageLocation(StringFormat SF, SizeF Area, SizeF ImageArea)
  723. {
  724. PointF MyPoint = default(PointF);
  725. switch (SF.Alignment)
  726. {
  727. case StringAlignment.Center:
  728. MyPoint.X = Convert.ToSingle((Area.Width - ImageArea.Width) / 2);
  729. break;
  730. case StringAlignment.Near:
  731. MyPoint.X = 2;
  732. break;
  733. case StringAlignment.Far:
  734. MyPoint.X = Area.Width - ImageArea.Width - 2;
  735. break;
  736. }
  737. switch (SF.LineAlignment)
  738. {
  739. case StringAlignment.Center:
  740. MyPoint.Y = Convert.ToSingle((Area.Height - ImageArea.Height) / 2);
  741. break;
  742. case StringAlignment.Near:
  743. MyPoint.Y = 2;
  744. break;
  745. case StringAlignment.Far:
  746. MyPoint.Y = Area.Height - ImageArea.Height - 2;
  747. break;
  748. }
  749. return MyPoint;
  750. }
  751. private StringFormat GetStringFormat(ContentAlignment _ContentAlignment)
  752. {
  753. StringFormat SF = new StringFormat();
  754. switch (_ContentAlignment)
  755. {
  756. case ContentAlignment.MiddleCenter:
  757. SF.LineAlignment = StringAlignment.Center;
  758. SF.Alignment = StringAlignment.Center;
  759. break;
  760. case ContentAlignment.MiddleLeft:
  761. SF.LineAlignment = StringAlignment.Center;
  762. SF.Alignment = StringAlignment.Near;
  763. break;
  764. case ContentAlignment.MiddleRight:
  765. SF.LineAlignment = StringAlignment.Center;
  766. SF.Alignment = StringAlignment.Far;
  767. break;
  768. case ContentAlignment.TopCenter:
  769. SF.LineAlignment = StringAlignment.Near;
  770. SF.Alignment = StringAlignment.Center;
  771. break;
  772. case ContentAlignment.TopLeft:
  773. SF.LineAlignment = StringAlignment.Near;
  774. SF.Alignment = StringAlignment.Near;
  775. break;
  776. case ContentAlignment.TopRight:
  777. SF.LineAlignment = StringAlignment.Near;
  778. SF.Alignment = StringAlignment.Far;
  779. break;
  780. case ContentAlignment.BottomCenter:
  781. SF.LineAlignment = StringAlignment.Far;
  782. SF.Alignment = StringAlignment.Center;
  783. break;
  784. case ContentAlignment.BottomLeft:
  785. SF.LineAlignment = StringAlignment.Far;
  786. SF.Alignment = StringAlignment.Near;
  787. break;
  788. case ContentAlignment.BottomRight:
  789. SF.LineAlignment = StringAlignment.Far;
  790. SF.Alignment = StringAlignment.Far;
  791. break;
  792. }
  793. return SF;
  794. }
  795. #endregion
  796. #region Properties
  797. public Image Image
  798. {
  799. get { return _Image; }
  800. set
  801. {
  802. if (value == null)
  803. {
  804. _ImageSize = Size.Empty;
  805. }
  806. else
  807. {
  808. _ImageSize = value.Size;
  809. }
  810. _Image = value;
  811. Invalidate();
  812. }
  813. }
  814. protected Size ImageSize
  815. {
  816. get { return _ImageSize; }
  817. }
  818. public ContentAlignment ImageAlign
  819. {
  820. get { return _ImageAlign; }
  821. set
  822. {
  823. _ImageAlign = value;
  824. Invalidate();
  825. }
  826. }
  827. public StringAlignment TextAlignment
  828. {
  829. get { return this._TextAlignment; }
  830. set
  831. {
  832. this._TextAlignment = value;
  833. this.Invalidate();
  834. }
  835. }
  836. public override Color ForeColor
  837. {
  838. get { return this._TextColor; }
  839. set
  840. {
  841. this._TextColor = value;
  842. this.Invalidate();
  843. }
  844. }
  845. #endregion
  846. #region EventArgs
  847. protected override void OnMouseUp(MouseEventArgs e)
  848. {
  849. MouseState = 0;
  850. Invalidate();
  851. base.OnMouseUp(e);
  852. }
  853. protected override void OnMouseDown(MouseEventArgs e)
  854. {
  855. MouseState = 1;
  856. Focus();
  857. Invalidate();
  858. base.OnMouseDown(e);
  859. }
  860. protected override void OnMouseLeave(EventArgs e)
  861. {
  862. MouseState = 0;
  863. Invalidate();
  864. base.OnMouseLeave(e);
  865. }
  866. protected override void OnTextChanged(System.EventArgs e)
  867. {
  868. Invalidate();
  869. base.OnTextChanged(e);
  870. }
  871. #endregion
  872. public Ambiance_Button_1()
  873. {
  874. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
  875. BackColor = Color.Transparent;
  876. DoubleBuffered = true;
  877. Font = new Font("Segoe UI", 12);
  878. ForeColor = Color.FromArgb(76, 76, 76);
  879. Size = new Size(177, 30);
  880. _TextAlignment = StringAlignment.Center;
  881. P1 = new Pen(Color.FromArgb(180, 180, 180));
  882. // P1 = Border color
  883. }
  884. protected override void OnResize(System.EventArgs e)
  885. {
  886. if (Width > 0 && Height > 0)
  887. {
  888. Shape = new GraphicsPath();
  889. R1 = new Rectangle(0, 0, Width, Height);
  890. InactiveGB = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), Color.FromArgb(253, 252, 252), Color.FromArgb(239, 237, 236), 90f);
  891. PressedGB = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), Color.FromArgb(226, 226, 226), Color.FromArgb(237, 237, 237), 90f);
  892. PressedContourGB = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), Color.FromArgb(167, 167, 167), Color.FromArgb(167, 167, 167), 90f);
  893. P3 = new Pen(PressedContourGB);
  894. }
  895. var MyDrawer = Shape;
  896. MyDrawer.AddArc(0, 0, 10, 10, 180, 90);
  897. MyDrawer.AddArc(Width - 11, 0, 10, 10, -90, 90);
  898. MyDrawer.AddArc(Width - 11, Height - 11, 10, 10, 0, 90);
  899. MyDrawer.AddArc(0, Height - 11, 10, 10, 90, 90);
  900. MyDrawer.CloseAllFigures();
  901. Invalidate();
  902. base.OnResize(e);
  903. }
  904. protected override void OnPaint(PaintEventArgs e)
  905. {
  906. var G = e.Graphics;
  907. G.SmoothingMode = SmoothingMode.HighQuality;
  908. PointF ipt = ImageLocation(GetStringFormat(ImageAlign), Size, ImageSize);
  909. switch (MouseState)
  910. {
  911. case 0:
  912. //Inactive
  913. G.FillPath(InactiveGB, Shape);
  914. // Fill button body with InactiveGB color gradient
  915. G.DrawPath(P1, Shape);
  916. // Draw button border [InactiveGB]
  917. if ((Image == null))
  918. {
  919. G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat
  920. {
  921. Alignment = _TextAlignment,
  922. LineAlignment = StringAlignment.Center
  923. });
  924. }
  925. else
  926. {
  927. G.DrawImage(_Image, ipt.X, ipt.Y, ImageSize.Width, ImageSize.Height);
  928. G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat
  929. {
  930. Alignment = _TextAlignment,
  931. LineAlignment = StringAlignment.Center
  932. });
  933. }
  934. break;
  935. case 1:
  936. //Pressed
  937. G.FillPath(PressedGB, Shape);
  938. // Fill button body with PressedGB color gradient
  939. G.DrawPath(P3, Shape);
  940. // Draw button border [PressedGB]
  941. if ((Image == null))
  942. {
  943. G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat
  944. {
  945. Alignment = _TextAlignment,
  946. LineAlignment = StringAlignment.Center
  947. });
  948. }
  949. else
  950. {
  951. G.DrawImage(_Image, ipt.X, ipt.Y, ImageSize.Width, ImageSize.Height);
  952. G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat
  953. {
  954. Alignment = _TextAlignment,
  955. LineAlignment = StringAlignment.Center
  956. });
  957. }
  958. break;
  959. }
  960. base.OnPaint(e);
  961. }
  962. }
  963. #endregion
  964. #region Button 2
  965. class Ambiance_Button_2 : Control
  966. {
  967. #region Variables
  968. private int MouseState;
  969. private GraphicsPath Shape;
  970. private LinearGradientBrush InactiveGB;
  971. private LinearGradientBrush PressedGB;
  972. private LinearGradientBrush PressedContourGB;
  973. private Rectangle R1;
  974. private Pen P1;
  975. private Pen P3;
  976. private Image _Image;
  977. private Size _ImageSize;
  978. private StringAlignment _TextAlignment = StringAlignment.Center;
  979. private Color _TextColor = Color.FromArgb(150, 150, 150);
  980. private ContentAlignment _ImageAlign = ContentAlignment.MiddleLeft;
  981. #endregion
  982. #region Image Designer
  983. private static PointF ImageLocation(StringFormat SF, SizeF Area, SizeF ImageArea)
  984. {
  985. PointF MyPoint = default(PointF);
  986. switch (SF.Alignment)
  987. {
  988. case StringAlignment.Center:
  989. MyPoint.X = Convert.ToSingle((Area.Width - ImageArea.Width) / 2);
  990. break;
  991. case StringAlignment.Near:
  992. MyPoint.X = 2;
  993. break;
  994. case StringAlignment.Far:
  995. MyPoint.X = Area.Width - ImageArea.Width - 2;
  996. break;
  997. }
  998. switch (SF.LineAlignment)
  999. {
  1000. case StringAlignment.Center:
  1001. MyPoint.Y = Convert.ToSingle((Area.Height - ImageArea.Height) / 2);
  1002. break;
  1003. case StringAlignment.Near:
  1004. MyPoint.Y = 2;
  1005. break;
  1006. case StringAlignment.Far:
  1007. MyPoint.Y = Area.Height - ImageArea.Height - 2;
  1008. break;
  1009. }
  1010. return MyPoint;
  1011. }
  1012. private StringFormat GetStringFormat(ContentAlignment _ContentAlignment)
  1013. {
  1014. StringFormat SF = new StringFormat();
  1015. switch (_ContentAlignment)
  1016. {
  1017. case ContentAlignment.MiddleCenter:
  1018. SF.LineAlignment = StringAlignment.Center;
  1019. SF.Alignment = StringAlignment.Center;
  1020. break;
  1021. case ContentAlignment.MiddleLeft:
  1022. SF.LineAlignment = StringAlignment.Center;
  1023. SF.Alignment = StringAlignment.Near;
  1024. break;
  1025. case ContentAlignment.MiddleRight:
  1026. SF.LineAlignment = StringAlignment.Center;
  1027. SF.Alignment = StringAlignment.Far;
  1028. break;
  1029. case ContentAlignment.TopCenter:
  1030. SF.LineAlignment = StringAlignment.Near;
  1031. SF.Alignment = StringAlignment.Center;
  1032. break;
  1033. case ContentAlignment.TopLeft:
  1034. SF.LineAlignment = StringAlignment.Near;
  1035. SF.Alignment = StringAlignment.Near;
  1036. break;
  1037. case ContentAlignment.TopRight:
  1038. SF.LineAlignment = StringAlignment.Near;
  1039. SF.Alignment = StringAlignment.Far;
  1040. break;
  1041. case ContentAlignment.BottomCenter:
  1042. SF.LineAlignment = StringAlignment.Far;
  1043. SF.Alignment = StringAlignment.Center;
  1044. break;
  1045. case ContentAlignment.BottomLeft:
  1046. SF.LineAlignment = StringAlignment.Far;
  1047. SF.Alignment = StringAlignment.Near;
  1048. break;
  1049. case ContentAlignment.BottomRight:
  1050. SF.LineAlignment = StringAlignment.Far;
  1051. SF.Alignment = StringAlignment.Far;
  1052. break;
  1053. }
  1054. return SF;
  1055. }
  1056. #endregion
  1057. #region Properties
  1058. public Image Image
  1059. {
  1060. get { return _Image; }
  1061. set
  1062. {
  1063. if (value == null)
  1064. {
  1065. _ImageSize = Size.Empty;
  1066. }
  1067. else
  1068. {
  1069. _ImageSize = value.Size;
  1070. }
  1071. _Image = value;
  1072. Invalidate();
  1073. }
  1074. }
  1075. protected Size ImageSize
  1076. {
  1077. get { return _ImageSize; }
  1078. }
  1079. public ContentAlignment ImageAlign
  1080. {
  1081. get { return _ImageAlign; }
  1082. set
  1083. {
  1084. _ImageAlign = value;
  1085. Invalidate();
  1086. }
  1087. }
  1088. public StringAlignment TextAlignment
  1089. {
  1090. get { return this._TextAlignment; }
  1091. set
  1092. {
  1093. this._TextAlignment = value;
  1094. this.Invalidate();
  1095. }
  1096. }
  1097. public override Color ForeColor
  1098. {
  1099. get { return this._TextColor; }
  1100. set
  1101. {
  1102. this._TextColor = value;
  1103. this.Invalidate();
  1104. }
  1105. }
  1106. #endregion
  1107. #region EventArgs
  1108. protected override void OnMouseUp(MouseEventArgs e)
  1109. {
  1110. MouseState = 0;
  1111. Invalidate();
  1112. base.OnMouseUp(e);
  1113. }
  1114. protected override void OnMouseDown(MouseEventArgs e)
  1115. {
  1116. MouseState = 1;
  1117. Focus();
  1118. Invalidate();
  1119. base.OnMouseDown(e);
  1120. }
  1121. protected override void OnMouseLeave(EventArgs e)
  1122. {
  1123. MouseState = 0;
  1124. Invalidate();
  1125. base.OnMouseLeave(e);
  1126. }
  1127. protected override void OnTextChanged(System.EventArgs e)
  1128. {
  1129. Invalidate();
  1130. base.OnTextChanged(e);
  1131. }
  1132. #endregion
  1133. public Ambiance_Button_2()
  1134. {
  1135. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
  1136. BackColor = Color.Transparent;
  1137. DoubleBuffered = true;
  1138. Font = new Font("Segoe UI", 11f, FontStyle.Bold);
  1139. ForeColor = Color.FromArgb(76, 76, 76);
  1140. Size = new Size(177, 30);
  1141. _TextAlignment = StringAlignment.Center;
  1142. P1 = new Pen(Color.FromArgb(162, 120, 101));
  1143. // P1 = Border color
  1144. }
  1145. protected override void OnResize(System.EventArgs e)
  1146. {
  1147. if (Width > 0 && Height > 0)
  1148. {
  1149. Shape = new GraphicsPath();
  1150. R1 = new Rectangle(0, 0, Width, Height);
  1151. InactiveGB = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), Color.FromArgb(253, 175, 143), Color.FromArgb(244, 146, 106), 90f);
  1152. PressedGB = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), Color.FromArgb(244, 146, 106), Color.FromArgb(244, 146, 106), 90f);
  1153. PressedContourGB = new LinearGradientBrush(new Rectangle(0, 0, Width, Height), Color.FromArgb(162, 120, 101), Color.FromArgb(162, 120, 101), 90f);
  1154. P3 = new Pen(PressedContourGB);
  1155. }
  1156. var MyDrawer = Shape;
  1157. MyDrawer.AddArc(0, 0, 10, 10, 180, 90);
  1158. MyDrawer.AddArc(Width - 11, 0, 10, 10, -90, 90);
  1159. MyDrawer.AddArc(Width - 11, Height - 11, 10, 10, 0, 90);
  1160. MyDrawer.AddArc(0, Height - 11, 10, 10, 90, 90);
  1161. MyDrawer.CloseAllFigures();
  1162. Invalidate();
  1163. base.OnResize(e);
  1164. }
  1165. protected override void OnPaint(PaintEventArgs e)
  1166. {
  1167. var G = e.Graphics;
  1168. G.SmoothingMode = SmoothingMode.HighQuality;
  1169. PointF ipt = ImageLocation(GetStringFormat(ImageAlign), Size, ImageSize);
  1170. switch (MouseState)
  1171. {
  1172. case 0:
  1173. //Inactive
  1174. G.FillPath(InactiveGB, Shape);
  1175. // Fill button body with InactiveGB color gradient
  1176. G.DrawPath(P1, Shape);
  1177. // Draw button border [InactiveGB]
  1178. if ((Image == null))
  1179. {
  1180. G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat
  1181. {
  1182. Alignment = _TextAlignment,
  1183. LineAlignment = StringAlignment.Center
  1184. });
  1185. }
  1186. else
  1187. {
  1188. G.DrawImage(_Image, ipt.X, ipt.Y, ImageSize.Width, ImageSize.Height);
  1189. G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat
  1190. {
  1191. Alignment = _TextAlignment,
  1192. LineAlignment = StringAlignment.Center
  1193. });
  1194. }
  1195. break;
  1196. case 1:
  1197. //Pressed
  1198. G.FillPath(PressedGB, Shape);
  1199. // Fill button body with PressedGB color gradient
  1200. G.DrawPath(P3, Shape);
  1201. // Draw button border [PressedGB]
  1202. if ((Image == null))
  1203. {
  1204. G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat
  1205. {
  1206. Alignment = _TextAlignment,
  1207. LineAlignment = StringAlignment.Center
  1208. });
  1209. }
  1210. else
  1211. {
  1212. G.DrawImage(_Image, ipt.X, ipt.Y, ImageSize.Width, ImageSize.Height);
  1213. G.DrawString(Text, Font, new SolidBrush(ForeColor), R1, new StringFormat
  1214. {
  1215. Alignment = _TextAlignment,
  1216. LineAlignment = StringAlignment.Center
  1217. });
  1218. }
  1219. break;
  1220. }
  1221. base.OnPaint(e);
  1222. }
  1223. }
  1224. #endregion
  1225. #region Label
  1226. class Ambiance_Label : Label
  1227. {
  1228. public Ambiance_Label()
  1229. {
  1230. Font = new Font("Segoe UI", 11);
  1231. ForeColor = Color.FromArgb(76, 76, 77);
  1232. BackColor = Color.Transparent;
  1233. }
  1234. }
  1235. #endregion
  1236. #region Link Label
  1237. class Ambiance_LinkLabel : LinkLabel
  1238. {
  1239. public Ambiance_LinkLabel()
  1240. {
  1241. Font = new Font("Segoe UI", 11, FontStyle.Regular);
  1242. BackColor = Color.Transparent;
  1243. LinkColor = Color.FromArgb(240, 119, 70);
  1244. ActiveLinkColor = Color.FromArgb(221, 72, 20);
  1245. VisitedLinkColor = Color.FromArgb(240, 119, 70);
  1246. LinkBehavior = System.Windows.Forms.LinkBehavior.AlwaysUnderline;
  1247. }
  1248. }
  1249. #endregion
  1250. #region Header Label
  1251. class Ambiance_HeaderLabel : Label
  1252. {
  1253. public Ambiance_HeaderLabel()
  1254. {
  1255. Font = new Font("Segoe UI", 11, FontStyle.Bold);
  1256. ForeColor = Color.FromArgb(76, 76, 77);
  1257. BackColor = Color.Transparent;
  1258. }
  1259. }
  1260. #endregion
  1261. #region Separator
  1262. public class Ambiance_Separator : Control
  1263. {
  1264. public Ambiance_Separator()
  1265. {
  1266. SetStyle(ControlStyles.ResizeRedraw, true);
  1267. this.Size = new Size(120, 10);
  1268. }
  1269. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  1270. {
  1271. base.OnPaint(e);
  1272. e.Graphics.DrawLine(new Pen(Color.FromArgb(224, 222, 220)), 0, 5, Width, 5);
  1273. e.Graphics.DrawLine(new Pen(Color.FromArgb(250, 249, 249)), 0, 6, Width, 6);
  1274. }
  1275. }
  1276. #endregion
  1277. #region ProgressBar
  1278. public class Ambiance_ProgressBar : Control
  1279. {
  1280. #region Enums
  1281. public enum Alignment
  1282. {
  1283. Right,
  1284. Center
  1285. }
  1286. #endregion
  1287. #region Variables
  1288. private int _Minimum;
  1289. private int _Maximum = 100;
  1290. private int _Value = 0;
  1291. private Alignment ALN;
  1292. private bool _DrawHatch;
  1293. private bool _ShowPercentage;
  1294. private GraphicsPath GP1;
  1295. private GraphicsPath GP2;
  1296. private GraphicsPath GP3;
  1297. private Rectangle R1;
  1298. private Rectangle R2;
  1299. private LinearGradientBrush GB1;
  1300. private LinearGradientBrush GB2;
  1301. private int I1;
  1302. #endregion
  1303. #region Properties
  1304. public int Maximum
  1305. {
  1306. get { return _Maximum; }
  1307. set
  1308. {
  1309. if (value < 1)
  1310. value = 1;
  1311. if (value < _Value)
  1312. _Value = value;
  1313. _Maximum = value;
  1314. Invalidate();
  1315. }
  1316. }
  1317. public int Minimum
  1318. {
  1319. get { return _Minimum; }
  1320. set
  1321. {
  1322. _Minimum = value;
  1323. if (value > _Maximum)
  1324. _Maximum = value;
  1325. if (value > _Value)
  1326. _Value = value;
  1327. Invalidate();
  1328. }
  1329. }
  1330. public int Value
  1331. {
  1332. get { return _Value; }
  1333. set
  1334. {
  1335. if (value > _Maximum)
  1336. value = Maximum;
  1337. _Value = value;
  1338. Invalidate();
  1339. }
  1340. }
  1341. public Alignment ValueAlignment
  1342. {
  1343. get { return ALN; }
  1344. set
  1345. {
  1346. ALN = value;
  1347. Invalidate();
  1348. }
  1349. }
  1350. public bool DrawHatch
  1351. {
  1352. get { return _DrawHatch; }
  1353. set
  1354. {
  1355. _DrawHatch = value;
  1356. Invalidate();
  1357. }
  1358. }
  1359. public bool ShowPercentage
  1360. {
  1361. get { return _ShowPercentage; }
  1362. set
  1363. {
  1364. _ShowPercentage = value;
  1365. Invalidate();
  1366. }
  1367. }
  1368. #endregion
  1369. #region EventArgs
  1370. protected override void OnResize(EventArgs e)
  1371. {
  1372. base.OnResize(e);
  1373. this.Height = 20;
  1374. Size minimumSize = new Size(58, 20);
  1375. this.MinimumSize = minimumSize;
  1376. }
  1377. #endregion
  1378. public Ambiance_ProgressBar()
  1379. {
  1380. _Maximum = 100;
  1381. _ShowPercentage = true;
  1382. _DrawHatch = true;
  1383. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  1384. SetStyle(ControlStyles.UserPaint, true);
  1385. BackColor = Color.Transparent;
  1386. DoubleBuffered = true;
  1387. }
  1388. public void Increment(int value)
  1389. {
  1390. this._Value += value;
  1391. Invalidate();
  1392. }
  1393. public void Deincrement(int value)
  1394. {
  1395. this._Value -= value;
  1396. Invalidate();
  1397. }
  1398. protected override void OnPaint(PaintEventArgs e)
  1399. {
  1400. base.OnPaint(e);
  1401. Bitmap B = new Bitmap(Width, Height);
  1402. Graphics G = Graphics.FromImage(B);
  1403. G.Clear(Color.Transparent);
  1404. G.SmoothingMode = SmoothingMode.HighQuality;
  1405. GP1 = RoundRectangle.RoundRect(new Rectangle(0, 0, Width - 1, Height - 1), 4);
  1406. GP2 = RoundRectangle.RoundRect(new Rectangle(1, 1, Width - 3, Height - 3), 4);
  1407. R1 = new Rectangle(0, 2, Width - 1, Height - 1);
  1408. GB1 = new LinearGradientBrush(R1, Color.FromArgb(255, 255, 255), Color.FromArgb(230, 230, 230), 90f);
  1409. // Draw inside background
  1410. G.FillRectangle(new SolidBrush(Color.FromArgb(244, 241, 243)), R1);
  1411. G.SetClip(GP1);
  1412. G.FillPath(new SolidBrush(Color.FromArgb(244, 241, 243)), RoundRectangle.RoundRect(new Rectangle(1, 1, Width - 3, Height / 2 - 2), 4));
  1413. I1 = (int)Math.Round(((double)(this._Value - this._Minimum) / (double)(this._Maximum - this._Minimum)) * (double)(this.Width - 3));
  1414. if (I1 > 1)
  1415. {
  1416. GP3 = RoundRectangle.RoundRect(new Rectangle(1, 1, I1, Height - 3), 4);
  1417. R2 = new Rectangle(1, 1, I1, Height - 3);
  1418. GB2 = new LinearGradientBrush(R2, Color.FromArgb(214, 89, 37), Color.FromArgb(223, 118, 75), 90f);
  1419. // Fill the value with its gradient
  1420. G.FillPath(GB2, GP3);
  1421. // Draw diagonal lines
  1422. if (_DrawHatch == true)
  1423. {
  1424. for (var i = 0; i <= (Width - 1) * _Maximum / _Value; i += 20)
  1425. {
  1426. G.DrawLine(new Pen(new SolidBrush(Color.FromArgb(25, Color.White)), 10.0F), new Point(System.Convert.ToInt32(i), 0), new Point((int)(i - 10), Height));
  1427. }
  1428. }
  1429. G.SetClip(GP3);
  1430. G.SmoothingMode = SmoothingMode.None;
  1431. G.SmoothingMode = SmoothingMode.AntiAlias;
  1432. G.ResetClip();
  1433. }
  1434. // Draw value as a string
  1435. string DrawString = Convert.ToString(Convert.ToInt32(Value)) + "%";
  1436. int textX = (int)(this.Width - G.MeasureString(DrawString, Font).Width - 1);
  1437. int textY = (int)((this.Height / 2) - (System.Convert.ToInt32(G.MeasureString(DrawString, Font).Height / 2) - 2));
  1438. if (_ShowPercentage == true)
  1439. {
  1440. switch (ValueAlignment)
  1441. {
  1442. case Alignment.Right:
  1443. G.DrawString(DrawString, new Font("Segoe UI", 8), Brushes.DimGray, new Point(textX, textY));
  1444. break;
  1445. case Alignment.Center:
  1446. G.DrawString(DrawString, new Font("Segoe UI", 8), Brushes.DimGray, new Rectangle(0, 0, Width, Height + 2), new StringFormat
  1447. {
  1448. Alignment = StringAlignment.Center,
  1449. LineAlignment = StringAlignment.Center
  1450. });
  1451. break;
  1452. }
  1453. }
  1454. // Draw border
  1455. G.DrawPath(new Pen(Color.FromArgb(180, 180, 180)), GP2);
  1456. e.Graphics.DrawImage((Image)(B.Clone()), 0, 0);
  1457. G.Dispose();
  1458. B.Dispose();
  1459. }
  1460. }
  1461. #endregion
  1462. #region Progress Indicator
  1463. class Ambiance_ProgressIndicator : Control
  1464. {
  1465. #region Variables
  1466. private readonly SolidBrush BaseColor = new SolidBrush(Color.FromArgb(76, 76, 76));
  1467. private readonly SolidBrush AnimationColor = new SolidBrush(Color.Gray);
  1468. private readonly Timer AnimationSpeed = new Timer();
  1469. private PointF[] FloatPoint;
  1470. private BufferedGraphics BuffGraphics;
  1471. private int IndicatorIndex;
  1472. private readonly BufferedGraphicsContext GraphicsContext = BufferedGraphicsManager.Current;
  1473. #endregion
  1474. #region Custom Properties
  1475. public Color P_BaseColor
  1476. {
  1477. get { return BaseColor.Color; }
  1478. set { BaseColor.Color = value; }
  1479. }
  1480. public Color P_AnimationColor
  1481. {
  1482. get { return AnimationColor.Color; }
  1483. set { AnimationColor.Color = value; }
  1484. }
  1485. public int P_AnimationSpeed
  1486. {
  1487. get { return AnimationSpeed.Interval; }
  1488. set { AnimationSpeed.Interval = value; }
  1489. }
  1490. #endregion
  1491. #region EventArgs
  1492. protected override void OnSizeChanged(EventArgs e)
  1493. {
  1494. base.OnSizeChanged(e);
  1495. SetStandardSize();
  1496. UpdateGraphics();
  1497. SetPoints();
  1498. }
  1499. protected override void OnEnabledChanged(EventArgs e)
  1500. {
  1501. base.OnEnabledChanged(e);
  1502. AnimationSpeed.Enabled = this.Enabled;
  1503. }
  1504. protected override void OnHandleCreated(EventArgs e)
  1505. {
  1506. base.OnHandleCreated(e);
  1507. AnimationSpeed.Tick += AnimationSpeed_Tick;
  1508. AnimationSpeed.Start();
  1509. }
  1510. private void AnimationSpeed_Tick(object sender, EventArgs e)
  1511. {
  1512. if (IndicatorIndex.Equals(0))
  1513. {
  1514. IndicatorIndex = FloatPoint.Length - 1;
  1515. }
  1516. else
  1517. {
  1518. IndicatorIndex -= 1;
  1519. }
  1520. this.Invalidate(false);
  1521. }
  1522. #endregion
  1523. public Ambiance_ProgressIndicator()
  1524. {
  1525. this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true);
  1526. Size = new Size(80, 80);
  1527. Text = string.Empty;
  1528. MinimumSize = new Size(80, 80);
  1529. SetPoints();
  1530. AnimationSpeed.Interval = 100;
  1531. }
  1532. private void SetStandardSize()
  1533. {
  1534. int _Size = Math.Max(Width, Height);
  1535. Size = new Size(_Size, _Size);
  1536. }
  1537. private void SetPoints()
  1538. {
  1539. Stack<PointF> stack = new Stack<PointF>();
  1540. PointF startingFloatPoint = new PointF(((float)this.Width) / 2f, ((float)this.Height) / 2f);
  1541. for (float i = 0f; i < 360f; i += 45f)
  1542. {
  1543. this.SetValue(startingFloatPoint, (int)Math.Round((double)((((double)this.Width) / 2.0) - 15.0)), (double)i);
  1544. PointF endPoint = this.EndPoint;
  1545. endPoint = new PointF(endPoint.X - 7.5f, endPoint.Y - 7.5f);
  1546. stack.Push(endPoint);
  1547. }
  1548. this.FloatPoint = stack.ToArray();
  1549. }
  1550. private void UpdateGraphics()
  1551. {
  1552. if ((this.Width > 0) && (this.Height > 0))
  1553. {
  1554. Size size2 = new Size(this.Width + 1, this.Height + 1);
  1555. this.GraphicsContext.MaximumBuffer = size2;
  1556. this.BuffGraphics = this.GraphicsContext.Allocate(this.CreateGraphics(), this.ClientRectangle);
  1557. this.BuffGraphics.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
  1558. }
  1559. }
  1560. protected override void OnPaint(PaintEventArgs e)
  1561. {
  1562. base.OnPaint(e);
  1563. this.BuffGraphics.Graphics.Clear(this.BackColor);
  1564. int num2 = this.FloatPoint.Length - 1;
  1565. for (int i = 0; i <= num2; i++)
  1566. {
  1567. if (this.IndicatorIndex == i)
  1568. {
  1569. this.BuffGraphics.Graphics.FillEllipse(this.AnimationColor, this.FloatPoint[i].X, this.FloatPoint[i].Y, 15f, 15f);
  1570. }
  1571. else
  1572. {
  1573. this.BuffGraphics.Graphics.FillEllipse(this.BaseColor, this.FloatPoint[i].X, this.FloatPoint[i].Y, 15f, 15f);
  1574. }
  1575. }
  1576. this.BuffGraphics.Render(e.Graphics);
  1577. }
  1578. private double Rise;
  1579. private double Run;
  1580. private PointF _StartingFloatPoint;
  1581. private X AssignValues<X>(ref X Run, X Length)
  1582. {
  1583. Run = Length;
  1584. return Length;
  1585. }
  1586. private void SetValue(PointF StartingFloatPoint, int Length, double Angle)
  1587. {
  1588. double CircleRadian = Math.PI * Angle / 180.0;
  1589. _StartingFloatPoint = StartingFloatPoint;
  1590. Rise = AssignValues(ref Run, Length);
  1591. Rise = Math.Sin(CircleRadian) * Rise;
  1592. Run = Math.Cos(CircleRadian) * Run;
  1593. }
  1594. private PointF EndPoint
  1595. {
  1596. get
  1597. {
  1598. float LocationX = Convert.ToSingle(_StartingFloatPoint.Y + Rise);
  1599. float LocationY = Convert.ToSingle(_StartingFloatPoint.X + Run);
  1600. return new PointF(LocationY, LocationX);
  1601. }
  1602. }
  1603. }
  1604. #endregion
  1605. #region Toggle Button
  1606. [DefaultEvent("ToggledChanged")]
  1607. public class Ambiance_Toggle : Control
  1608. {
  1609. #region Enums
  1610. public enum _Type
  1611. {
  1612. OnOff,
  1613. YesNo,
  1614. IO
  1615. }
  1616. #endregion
  1617. #region Variables
  1618. public delegate void ToggledChangedEventHandler();
  1619. private ToggledChangedEventHandler ToggledChangedEvent;
  1620. public event ToggledChangedEventHandler ToggledChanged
  1621. {
  1622. add
  1623. {
  1624. ToggledChangedEvent = (ToggledChangedEventHandler)System.Delegate.Combine(ToggledChangedEvent, value);
  1625. }
  1626. remove
  1627. {
  1628. ToggledChangedEvent = (ToggledChangedEventHandler)System.Delegate.Remove(ToggledChangedEvent, value);
  1629. }
  1630. }
  1631. private bool _Toggled;
  1632. private _Type ToggleType;
  1633. private Rectangle Bar;
  1634. private Size cHandle = new Size(15, 20);
  1635. #endregion
  1636. #region Properties
  1637. public bool Toggled
  1638. {
  1639. get
  1640. {
  1641. return _Toggled;
  1642. }
  1643. set
  1644. {
  1645. _Toggled = value;
  1646. Invalidate();
  1647. if (ToggledChangedEvent != null)
  1648. ToggledChangedEvent();
  1649. }
  1650. }
  1651. public _Type Type
  1652. {
  1653. get
  1654. {
  1655. return ToggleType;
  1656. }
  1657. set
  1658. {
  1659. ToggleType = value;
  1660. Invalidate();
  1661. }
  1662. }
  1663. #endregion
  1664. #region EventArgs
  1665. protected override void OnResize(EventArgs e)
  1666. {
  1667. base.OnResize(e);
  1668. Width = 79;
  1669. Height = 27;
  1670. }
  1671. protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e)
  1672. {
  1673. base.OnMouseUp(e);
  1674. Toggled = !Toggled;
  1675. Focus();
  1676. }
  1677. #endregion
  1678. public Ambiance_Toggle()
  1679. {
  1680. SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint), true);
  1681. }
  1682. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  1683. {
  1684. base.OnPaint(e);
  1685. Graphics G = e.Graphics;
  1686. G.SmoothingMode = SmoothingMode.HighQuality;
  1687. G.Clear(Parent.BackColor);
  1688. int SwitchXLoc = 3;
  1689. Rectangle ControlRectangle = new Rectangle(0, 0, Width - 1, Height - 1);
  1690. GraphicsPath ControlPath = RoundRectangle.RoundRect(ControlRectangle, 4);
  1691. LinearGradientBrush BackgroundLGB = default(LinearGradientBrush);
  1692. if (_Toggled)
  1693. {
  1694. SwitchXLoc = 37;
  1695. BackgroundLGB = new LinearGradientBrush(ControlRectangle, Color.FromArgb(231, 108, 58), Color.FromArgb(236, 113, 63), 90.0F);
  1696. }
  1697. else
  1698. {
  1699. SwitchXLoc = 0;
  1700. BackgroundLGB = new LinearGradientBrush(ControlRectangle, Color.FromArgb(208, 208, 208), Color.FromArgb(226, 226, 226), 90.0F);
  1701. }
  1702. // Fill inside background gradient
  1703. G.FillPath(BackgroundLGB, ControlPath);
  1704. // Draw string
  1705. switch (ToggleType)
  1706. {
  1707. case _Type.OnOff:
  1708. if (Toggled)
  1709. {
  1710. G.DrawString("ON", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, (float)(Bar.Y + 13.5), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  1711. }
  1712. else
  1713. {
  1714. G.DrawString("OFF", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 59, (float)(Bar.Y + 13.5), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  1715. }
  1716. break;
  1717. case _Type.YesNo:
  1718. if (Toggled)
  1719. {
  1720. G.DrawString("YES", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, (float)(Bar.Y + 13.5), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  1721. }
  1722. else
  1723. {
  1724. G.DrawString("NO", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 59, (float)(Bar.Y + 13.5), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  1725. }
  1726. break;
  1727. case _Type.IO:
  1728. if (Toggled)
  1729. {
  1730. G.DrawString("I", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.WhiteSmoke, Bar.X + 18, (float)(Bar.Y + 13.5), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  1731. }
  1732. else
  1733. {
  1734. G.DrawString("O", new Font("Segoe UI", 12, FontStyle.Regular), Brushes.DimGray, Bar.X + 59, (float)(Bar.Y + 13.5), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  1735. }
  1736. break;
  1737. }
  1738. Rectangle SwitchRectangle = new Rectangle(SwitchXLoc, 0, Width - 38, Height);
  1739. GraphicsPath SwitchPath = RoundRectangle.RoundRect(SwitchRectangle, 4);
  1740. LinearGradientBrush SwitchButtonLGB = new LinearGradientBrush(SwitchRectangle, Color.FromArgb(253, 253, 253), Color.FromArgb(240, 238, 237), LinearGradientMode.Vertical);
  1741. // Fill switch background gradient
  1742. G.FillPath(SwitchButtonLGB, SwitchPath);
  1743. // Draw borders
  1744. if (_Toggled == true)
  1745. {
  1746. G.DrawPath(new Pen(Color.FromArgb(185, 89, 55)), SwitchPath);
  1747. G.DrawPath(new Pen(Color.FromArgb(185, 89, 55)), ControlPath);
  1748. }
  1749. else
  1750. {
  1751. G.DrawPath(new Pen(Color.FromArgb(181, 181, 181)), SwitchPath);
  1752. G.DrawPath(new Pen(Color.FromArgb(181, 181, 181)), ControlPath);
  1753. }
  1754. }
  1755. }
  1756. #endregion
  1757. #region CheckBox
  1758. [DefaultEvent("CheckedChanged")]
  1759. class Ambiance_CheckBox : Control
  1760. {
  1761. #region Variables
  1762. private GraphicsPath Shape;
  1763. private LinearGradientBrush GB;
  1764. private Rectangle R1;
  1765. private Rectangle R2;
  1766. private bool _Checked;
  1767. public event CheckedChangedEventHandler CheckedChanged;
  1768. public delegate void CheckedChangedEventHandler(object sender);
  1769. #endregion
  1770. #region Properties
  1771. public bool Checked
  1772. {
  1773. get { return _Checked; }
  1774. set
  1775. {
  1776. _Checked = value;
  1777. if (CheckedChanged != null)
  1778. {
  1779. CheckedChanged(this);
  1780. }
  1781. Invalidate();
  1782. }
  1783. }
  1784. #endregion
  1785. public Ambiance_CheckBox()
  1786. {
  1787. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
  1788. BackColor = Color.Transparent;
  1789. DoubleBuffered = true;
  1790. // Reduce control flicker
  1791. Font = new Font("Segoe UI", 12);
  1792. Size = new Size(171, 26);
  1793. }
  1794. protected override void OnClick(EventArgs e)
  1795. {
  1796. _Checked = !_Checked;
  1797. if (CheckedChanged != null)
  1798. {
  1799. CheckedChanged(this);
  1800. }
  1801. Focus();
  1802. Invalidate();
  1803. base.OnClick(e);
  1804. }
  1805. protected override void OnTextChanged(System.EventArgs e)
  1806. {
  1807. Invalidate();
  1808. base.OnTextChanged(e);
  1809. }
  1810. protected override void OnResize(System.EventArgs e)
  1811. {
  1812. if (Width > 0 && Height > 0)
  1813. {
  1814. Shape = new GraphicsPath();
  1815. R1 = new Rectangle(17, 0, Width, Height + 1);
  1816. R2 = new Rectangle(0, 0, Width, Height);
  1817. GB = new LinearGradientBrush(new Rectangle(0, 0, 25, 25), Color.FromArgb(213, 85, 32), Color.FromArgb(224, 123, 82), 90);
  1818. var MyDrawer = Shape;
  1819. MyDrawer.AddArc(0, 0, 7, 7, 180, 90);
  1820. MyDrawer.AddArc(7, 0, 7, 7, -90, 90);
  1821. MyDrawer.AddArc(7, 7, 7, 7, 0, 90);
  1822. MyDrawer.AddArc(0, 7, 7, 7, 90, 90);
  1823. MyDrawer.CloseAllFigures();
  1824. Height = 15;
  1825. }
  1826. Invalidate();
  1827. base.OnResize(e);
  1828. }
  1829. protected override void OnPaint(PaintEventArgs e)
  1830. {
  1831. base.OnPaint(e);
  1832. var MyDrawer = e.Graphics;
  1833. MyDrawer.Clear(Parent.BackColor);
  1834. MyDrawer.SmoothingMode = SmoothingMode.AntiAlias;
  1835. MyDrawer.FillPath(GB, Shape);
  1836. // Fill the body of the CheckBox
  1837. MyDrawer.DrawPath(new Pen(Color.FromArgb(182, 88, 55)), Shape);
  1838. // Draw the border
  1839. MyDrawer.DrawString(Text, Font, new SolidBrush(Color.FromArgb(76, 76, 95)), new Rectangle(17, 0, Width, Height -1), new StringFormat { LineAlignment = StringAlignment.Center });
  1840. if (Checked)
  1841. {
  1842. MyDrawer.DrawString("ü", new Font("Wingdings", 12), new SolidBrush(Color.FromArgb(255, 255, 255)), new Rectangle(-2, 1, Width, Height + 2), new StringFormat { LineAlignment = StringAlignment.Center });
  1843. }
  1844. e.Dispose();
  1845. }
  1846. }
  1847. #endregion
  1848. #region RadioButton
  1849. [DefaultEvent("CheckedChanged")]
  1850. class Ambiance_RadioButton : Control
  1851. {
  1852. #region Enums
  1853. public enum MouseState : byte
  1854. {
  1855. None = 0,
  1856. Over = 1,
  1857. Down = 2,
  1858. Block = 3
  1859. }
  1860. #endregion
  1861. #region Variables
  1862. private bool _Checked;
  1863. public event CheckedChangedEventHandler CheckedChanged;
  1864. public delegate void CheckedChangedEventHandler(object sender);
  1865. #endregion
  1866. #region Properties
  1867. public bool Checked
  1868. {
  1869. get { return _Checked; }
  1870. set
  1871. {
  1872. _Checked = value;
  1873. InvalidateControls();
  1874. if (CheckedChanged != null)
  1875. {
  1876. CheckedChanged(this);
  1877. }
  1878. Invalidate();
  1879. }
  1880. }
  1881. #endregion
  1882. #region EventArgs
  1883. protected override void OnTextChanged(System.EventArgs e)
  1884. {
  1885. Invalidate();
  1886. base.OnTextChanged(e);
  1887. }
  1888. protected override void OnResize(EventArgs e)
  1889. {
  1890. base.OnResize(e);
  1891. Height = 15;
  1892. }
  1893. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  1894. {
  1895. if (!_Checked)
  1896. Checked = true;
  1897. base.OnMouseDown(e);
  1898. Focus();
  1899. }
  1900. #endregion
  1901. public Ambiance_RadioButton()
  1902. {
  1903. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
  1904. BackColor = Color.Transparent;
  1905. Font = new Font("Segoe UI", 12);
  1906. Width = 193;
  1907. }
  1908. private void InvalidateControls()
  1909. {
  1910. if (!IsHandleCreated || !_Checked)
  1911. return;
  1912. foreach (Control _Control in Parent.Controls)
  1913. {
  1914. if (!object.ReferenceEquals(_Control, this) && _Control is Ambiance_RadioButton)
  1915. {
  1916. ((Ambiance_RadioButton)_Control).Checked = false;
  1917. }
  1918. }
  1919. }
  1920. protected override void OnPaint(PaintEventArgs e)
  1921. {
  1922. base.OnPaint(e);
  1923. var MyDrawer = e.Graphics;
  1924. MyDrawer.Clear(Parent.BackColor);
  1925. MyDrawer.SmoothingMode = SmoothingMode.AntiAlias;
  1926. // Fill the body of the ellipse with a gradient
  1927. LinearGradientBrush LGB = new LinearGradientBrush(new Rectangle(new Point(0, 0), new Size(14, 14)), Color.FromArgb(213, 85, 32), Color.FromArgb(224, 123, 82), 90);
  1928. MyDrawer.FillEllipse(LGB, new Rectangle(new Point(0, 0), new Size(14, 14)));
  1929. GraphicsPath GP = new GraphicsPath();
  1930. GP.AddEllipse(new Rectangle(0, 0, 14, 14));
  1931. MyDrawer.SetClip(GP);
  1932. MyDrawer.ResetClip();
  1933. // Draw ellipse border
  1934. MyDrawer.DrawEllipse(new Pen(Color.FromArgb(182, 88, 55)), new Rectangle(new Point(0, 0), new Size(14, 14)));
  1935. // Draw an ellipse inside the body
  1936. if (_Checked)
  1937. {
  1938. SolidBrush EllipseColor = new SolidBrush(Color.FromArgb(255, 255, 255));
  1939. MyDrawer.FillEllipse(EllipseColor, new Rectangle(new Point(4, 4), new Size(6, 6)));
  1940. }
  1941. MyDrawer.DrawString(Text, Font, new SolidBrush(Color.FromArgb(76, 76, 95)), 16, 7, new StringFormat { LineAlignment = StringAlignment.Center });
  1942. e.Dispose();
  1943. }
  1944. }
  1945. #endregion
  1946. #region ComboBox
  1947. public class Ambiance_ComboBox : ComboBox
  1948. {
  1949. #region Variables
  1950. private int _StartIndex = 0;
  1951. private Color _HoverSelectionColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static. Assignment has been moved to the class constructors.
  1952. #endregion
  1953. #region Custom Properties
  1954. public int StartIndex
  1955. {
  1956. get
  1957. {
  1958. return _StartIndex;
  1959. }
  1960. set
  1961. {
  1962. _StartIndex = value;
  1963. try
  1964. {
  1965. base.SelectedIndex = value;
  1966. }
  1967. catch
  1968. {
  1969. }
  1970. Invalidate();
  1971. }
  1972. }
  1973. public Color HoverSelectionColor
  1974. {
  1975. get
  1976. {
  1977. return _HoverSelectionColor;
  1978. }
  1979. set
  1980. {
  1981. _HoverSelectionColor = value;
  1982. Invalidate();
  1983. }
  1984. }
  1985. #endregion
  1986. #region EventArgs
  1987. protected override void OnDrawItem(DrawItemEventArgs e)
  1988. {
  1989. base.OnDrawItem(e);
  1990. LinearGradientBrush LGB = new LinearGradientBrush(e.Bounds, Color.FromArgb(246, 132, 85), Color.FromArgb(231, 108, 57), 90.0F);
  1991. if (System.Convert.ToInt32((e.State & DrawItemState.Selected)) == (int)DrawItemState.Selected)
  1992. {
  1993. if (!(e.Index == -1))
  1994. {
  1995. e.Graphics.FillRectangle(LGB, e.Bounds);
  1996. e.Graphics.DrawString(GetItemText(Items[e.Index]), e.Font, Brushes.WhiteSmoke, e.Bounds);
  1997. }
  1998. }
  1999. else
  2000. {
  2001. if (!(e.Index == -1))
  2002. {
  2003. e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(242, 241, 240)), e.Bounds);
  2004. e.Graphics.DrawString(GetItemText(Items[e.Index]), e.Font, Brushes.DimGray, e.Bounds);
  2005. }
  2006. }
  2007. LGB.Dispose();
  2008. }
  2009. protected override void OnLostFocus(EventArgs e)
  2010. {
  2011. base.OnLostFocus(e);
  2012. SuspendLayout();
  2013. Update();
  2014. ResumeLayout();
  2015. }
  2016. protected override void OnPaintBackground(PaintEventArgs e)
  2017. {
  2018. base.OnPaintBackground(e);
  2019. }
  2020. protected override void OnResize(EventArgs e)
  2021. {
  2022. base.OnResize(e);
  2023. if (!Focused)
  2024. {
  2025. SelectionLength = 0;
  2026. }
  2027. }
  2028. #endregion
  2029. public Ambiance_ComboBox()
  2030. {
  2031. SetStyle((ControlStyles)(139286), true);
  2032. SetStyle(ControlStyles.Selectable, false);
  2033. DrawMode = DrawMode.OwnerDrawFixed;
  2034. DropDownStyle = ComboBoxStyle.DropDownList;
  2035. BackColor = Color.FromArgb(246, 246, 246);
  2036. ForeColor = Color.FromArgb(142, 142, 142);
  2037. Size = new Size(135, 26);
  2038. ItemHeight = 20;
  2039. DropDownHeight = 100;
  2040. Font = new Font("Segoe UI", 10, FontStyle.Regular);
  2041. }
  2042. protected override void OnPaint(PaintEventArgs e)
  2043. {
  2044. base.OnPaint(e);
  2045. LinearGradientBrush LGB = default(LinearGradientBrush);
  2046. GraphicsPath GP = default(GraphicsPath);
  2047. e.Graphics.Clear(Parent.BackColor);
  2048. e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
  2049. // Create a curvy border
  2050. GP = RoundRectangle.RoundRect(0, 0, Width - 1, Height - 1, 5);
  2051. // Fills the body of the rectangle with a gradient
  2052. LGB = new LinearGradientBrush(ClientRectangle, Color.FromArgb(253, 252, 252), Color.FromArgb(239, 237, 236), 90.0F);
  2053. e.Graphics.SetClip(GP);
  2054. e.Graphics.FillRectangle(LGB, ClientRectangle);
  2055. e.Graphics.ResetClip();
  2056. // Draw rectangle border
  2057. e.Graphics.DrawPath(new Pen(Color.FromArgb(180, 180, 180)), GP);
  2058. // Draw string
  2059. e.Graphics.DrawString(Text, Font, new SolidBrush(Color.FromArgb(76, 76, 97)), new Rectangle(3, 0, Width - 20, Height), new StringFormat
  2060. {
  2061. LineAlignment = StringAlignment.Center,
  2062. Alignment = StringAlignment.Near
  2063. });
  2064. e.Graphics.DrawString("6", new Font("Marlett", 13, FontStyle.Regular), new SolidBrush(Color.FromArgb(119, 119, 118)), new Rectangle(3, 0, Width - 4, Height), new StringFormat
  2065. {
  2066. LineAlignment = StringAlignment.Center,
  2067. Alignment = StringAlignment.Far
  2068. });
  2069. e.Graphics.DrawLine(new Pen(Color.FromArgb(224, 222, 220)), Width - 24, 4, Width - 24, this.Height - 5);
  2070. e.Graphics.DrawLine(new Pen(Color.FromArgb(250, 249, 249)), Width - 25, 4, Width - 25, this.Height - 5);
  2071. GP.Dispose();
  2072. LGB.Dispose();
  2073. }
  2074. }
  2075. #endregion
  2076. #region NumericUpDown
  2077. public class Ambiance_NumericUpDown : Control
  2078. {
  2079. #region Enums
  2080. public enum _TextAlignment
  2081. {
  2082. Near,
  2083. Center
  2084. }
  2085. #endregion
  2086. #region Variables
  2087. private GraphicsPath Shape;
  2088. private Pen P1;
  2089. private long _Value;
  2090. private long _Minimum;
  2091. private long _Maximum;
  2092. private int Xval;
  2093. private bool KeyboardNum;
  2094. private _TextAlignment MyStringAlignment;
  2095. private Timer LongPressTimer = new Timer();
  2096. #endregion
  2097. #region Properties
  2098. public long Value
  2099. {
  2100. get
  2101. {
  2102. return _Value;
  2103. }
  2104. set
  2105. {
  2106. if (value <= _Maximum & value >= _Minimum)
  2107. {
  2108. _Value = value;
  2109. }
  2110. Invalidate();
  2111. }
  2112. }
  2113. public long Minimum
  2114. {
  2115. get
  2116. {
  2117. return _Minimum;
  2118. }
  2119. set
  2120. {
  2121. if (value < _Maximum)
  2122. {
  2123. _Minimum = value;
  2124. }
  2125. if (_Value < _Minimum)
  2126. {
  2127. _Value = Minimum;
  2128. }
  2129. Invalidate();
  2130. }
  2131. }
  2132. public long Maximum
  2133. {
  2134. get
  2135. {
  2136. return _Maximum;
  2137. }
  2138. set
  2139. {
  2140. if (value > _Minimum)
  2141. {
  2142. _Maximum = value;
  2143. }
  2144. if (_Value > _Maximum)
  2145. {
  2146. _Value = _Maximum;
  2147. }
  2148. Invalidate();
  2149. }
  2150. }
  2151. public _TextAlignment TextAlignment
  2152. {
  2153. get
  2154. {
  2155. return MyStringAlignment;
  2156. }
  2157. set
  2158. {
  2159. MyStringAlignment = value;
  2160. Invalidate();
  2161. }
  2162. }
  2163. #endregion
  2164. #region EventArgs
  2165. protected override void OnResize(System.EventArgs e)
  2166. {
  2167. base.OnResize(e);
  2168. Height = 28;
  2169. MinimumSize = new Size(93, 28);
  2170. Shape = new GraphicsPath();
  2171. Shape.AddArc(0, 0, 10, 10, 180, 90);
  2172. Shape.AddArc(Width - 11, 0, 10, 10, -90, 90);
  2173. Shape.AddArc(Width - 11, Height - 11, 10, 10, 0, 90);
  2174. Shape.AddArc(0, Height - 11, 10, 10, 90, 90);
  2175. Shape.CloseAllFigures();
  2176. }
  2177. protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
  2178. {
  2179. base.OnMouseMove(e);
  2180. Xval = e.Location.X;
  2181. Invalidate();
  2182. if (e.X < Width - 50)
  2183. {
  2184. Cursor = Cursors.IBeam;
  2185. }
  2186. else
  2187. {
  2188. Cursor = Cursors.Default;
  2189. }
  2190. if (e.X > this.Width - 25 && e.X < this.Width - 10)
  2191. {
  2192. Cursor = Cursors.Hand;
  2193. }
  2194. if (e.X > this.Width - 44 && e.X < this.Width - 33)
  2195. {
  2196. Cursor = Cursors.Hand;
  2197. }
  2198. }
  2199. private void ClickButton()
  2200. {
  2201. if (Xval > this.Width - 25 && Xval < this.Width - 10)
  2202. {
  2203. if ((Value + 1) <= _Maximum)
  2204. {
  2205. _Value++;
  2206. }
  2207. }
  2208. else
  2209. {
  2210. if (Xval > this.Width - 44 && Xval < this.Width - 33)
  2211. {
  2212. if ((Value - 1) >= _Minimum)
  2213. {
  2214. _Value--;
  2215. }
  2216. }
  2217. KeyboardNum = !KeyboardNum;
  2218. }
  2219. Focus();
  2220. Invalidate();
  2221. }
  2222. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
  2223. {
  2224. base.OnMouseClick(e);
  2225. ClickButton();
  2226. LongPressTimer.Start();
  2227. }
  2228. protected override void OnMouseUp(MouseEventArgs e)
  2229. {
  2230. base.OnMouseUp(e);
  2231. LongPressTimer.Stop();
  2232. }
  2233. private void LongPressTimer_Tick(object sender, EventArgs e)
  2234. {
  2235. ClickButton();
  2236. }
  2237. protected override void OnKeyPress(System.Windows.Forms.KeyPressEventArgs e)
  2238. {
  2239. base.OnKeyPress(e);
  2240. try
  2241. {
  2242. if (KeyboardNum == true)
  2243. {
  2244. _Value = long.Parse((_Value).ToString() + e.KeyChar.ToString().ToString());
  2245. }
  2246. if (_Value > _Maximum)
  2247. {
  2248. _Value = _Maximum;
  2249. }
  2250. }
  2251. catch (Exception)
  2252. {
  2253. }
  2254. }
  2255. protected override void OnKeyUp(System.Windows.Forms.KeyEventArgs e)
  2256. {
  2257. base.OnKeyUp(e);
  2258. if (e.KeyCode == Keys.Back)
  2259. {
  2260. string TemporaryValue = _Value.ToString();
  2261. TemporaryValue = TemporaryValue.Remove(Convert.ToInt32(TemporaryValue.Length - 1));
  2262. if (TemporaryValue.Length == 0)
  2263. {
  2264. TemporaryValue = "0";
  2265. }
  2266. _Value = Convert.ToInt32(TemporaryValue);
  2267. }
  2268. Invalidate();
  2269. }
  2270. protected override void OnMouseWheel(MouseEventArgs e)
  2271. {
  2272. base.OnMouseWheel(e);
  2273. if (e.Delta > 0)
  2274. {
  2275. if ((Value + 1) <= _Maximum)
  2276. {
  2277. _Value++;
  2278. }
  2279. Invalidate();
  2280. }
  2281. else
  2282. {
  2283. if ((Value - 1) >= _Minimum)
  2284. {
  2285. _Value--;
  2286. }
  2287. Invalidate();
  2288. }
  2289. }
  2290. #endregion
  2291. public Ambiance_NumericUpDown()
  2292. {
  2293. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  2294. SetStyle(ControlStyles.UserPaint, true);
  2295. P1 = new Pen(Color.FromArgb(180, 180, 180));
  2296. BackColor = Color.Transparent;
  2297. ForeColor = Color.FromArgb(76, 76, 76);
  2298. _Minimum = 0;
  2299. _Maximum = 100;
  2300. Font = new Font("Tahoma", 11);
  2301. Size = new Size(70, 28);
  2302. MinimumSize = new Size(62, 28);
  2303. DoubleBuffered = true;
  2304. LongPressTimer.Tick += LongPressTimer_Tick;
  2305. LongPressTimer.Interval = 300;
  2306. }
  2307. public void Increment(int Value)
  2308. {
  2309. this._Value += Value;
  2310. Invalidate();
  2311. }
  2312. public void Decrement(int Value)
  2313. {
  2314. this._Value -= Value;
  2315. Invalidate();
  2316. }
  2317. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2318. {
  2319. base.OnPaint(e);
  2320. Bitmap B = new Bitmap(Width, Height);
  2321. Graphics G = Graphics.FromImage(B);
  2322. LinearGradientBrush BackgroundLGB = default(LinearGradientBrush);
  2323. BackgroundLGB = new LinearGradientBrush(ClientRectangle, Color.FromArgb(246, 246, 246), Color.FromArgb(254, 254, 254), 90.0F);
  2324. G.SmoothingMode = SmoothingMode.AntiAlias;
  2325. G.Clear(Color.Transparent); // Set control background color
  2326. G.FillPath(BackgroundLGB, Shape); // Draw background
  2327. G.DrawPath(P1, Shape); // Draw border
  2328. G.DrawString("+", new Font("Tahoma", 14), new SolidBrush(Color.FromArgb(75, 75, 75)), new Rectangle(Width - 25, 1, 19, 30));
  2329. G.DrawLine(new Pen(Color.FromArgb(229, 228, 227)), Width - 28, 1, Width - 28, this.Height - 2);
  2330. G.DrawString("-", new Font("Tahoma", 14), new SolidBrush(Color.FromArgb(75, 75, 75)), new Rectangle(Width - 44, 1, 19, 30));
  2331. G.DrawLine(new Pen(Color.FromArgb(229, 228, 227)), Width - 48, 1, Width - 48, this.Height - 2);
  2332. switch (MyStringAlignment)
  2333. {
  2334. case _TextAlignment.Near:
  2335. G.DrawString(System.Convert.ToString(Value), Font, new SolidBrush(ForeColor), new Rectangle(5, 0, Width - 1, Height - 1), new StringFormat() { Alignment = StringAlignment.Near, LineAlignment = StringAlignment.Center });
  2336. break;
  2337. case _TextAlignment.Center:
  2338. G.DrawString(System.Convert.ToString(Value), Font, new SolidBrush(ForeColor), new Rectangle(0, 0, Width - 1, Height - 1), new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center });
  2339. break;
  2340. }
  2341. e.Graphics.DrawImage((Image)(B.Clone()), 0, 0);
  2342. G.Dispose();
  2343. B.Dispose();
  2344. }
  2345. }
  2346. #endregion
  2347. #region TrackBar
  2348. [DefaultEvent("ValueChanged")]
  2349. public class Ambiance_TrackBar : Control
  2350. {
  2351. #region Enums
  2352. public enum ValueDivisor
  2353. {
  2354. By1 = 1,
  2355. By10 = 10,
  2356. By100 = 100,
  2357. By1000 = 1000
  2358. }
  2359. #endregion
  2360. #region Variables
  2361. private GraphicsPath PipeBorder;
  2362. private GraphicsPath FillValue;
  2363. private Rectangle TrackBarHandleRect;
  2364. private bool Cap;
  2365. private int ValueDrawer;
  2366. private Size ThumbSize = new Size(15, 15);
  2367. private Rectangle TrackThumb;
  2368. private int _Minimum = 0;
  2369. private int _Maximum = 10;
  2370. private int _Value = 0;
  2371. private bool _DrawValueString = false;
  2372. private bool _JumpToMouse = false;
  2373. private ValueDivisor DividedValue = ValueDivisor.By1;
  2374. #endregion
  2375. #region Properties
  2376. public int Minimum
  2377. {
  2378. get
  2379. {
  2380. return _Minimum;
  2381. }
  2382. set
  2383. {
  2384. if (value >= _Maximum)
  2385. {
  2386. value = _Maximum - 10;
  2387. }
  2388. if (_Value < value)
  2389. {
  2390. _Value = value;
  2391. }
  2392. _Minimum = value;
  2393. Invalidate();
  2394. }
  2395. }
  2396. public int Maximum
  2397. {
  2398. get
  2399. {
  2400. return _Maximum;
  2401. }
  2402. set
  2403. {
  2404. if (value <= _Minimum)
  2405. {
  2406. value = _Minimum + 10;
  2407. }
  2408. if (_Value > value)
  2409. {
  2410. _Value = value;
  2411. }
  2412. _Maximum = value;
  2413. Invalidate();
  2414. }
  2415. }
  2416. public delegate void ValueChangedEventHandler();
  2417. private ValueChangedEventHandler ValueChangedEvent;
  2418. public event ValueChangedEventHandler ValueChanged
  2419. {
  2420. add
  2421. {
  2422. ValueChangedEvent = (ValueChangedEventHandler)System.Delegate.Combine(ValueChangedEvent, value);
  2423. }
  2424. remove
  2425. {
  2426. ValueChangedEvent = (ValueChangedEventHandler)System.Delegate.Remove(ValueChangedEvent, value);
  2427. }
  2428. }
  2429. public int Value
  2430. {
  2431. get
  2432. {
  2433. return _Value;
  2434. }
  2435. set
  2436. {
  2437. if (_Value != value)
  2438. {
  2439. if (value < _Minimum)
  2440. {
  2441. _Value = _Minimum;
  2442. }
  2443. else
  2444. {
  2445. if (value > _Maximum)
  2446. {
  2447. _Value = _Maximum;
  2448. }
  2449. else
  2450. {
  2451. _Value = value;
  2452. }
  2453. }
  2454. Invalidate();
  2455. if (ValueChangedEvent != null)
  2456. ValueChangedEvent();
  2457. }
  2458. }
  2459. }
  2460. public ValueDivisor ValueDivison
  2461. {
  2462. get
  2463. {
  2464. return DividedValue;
  2465. }
  2466. set
  2467. {
  2468. DividedValue = value;
  2469. Invalidate();
  2470. }
  2471. }
  2472. [Browsable(false)]
  2473. public float ValueToSet
  2474. {
  2475. get
  2476. {
  2477. return _Value / (int)DividedValue;
  2478. }
  2479. set
  2480. {
  2481. Value = (int)(value * (int)DividedValue);
  2482. }
  2483. }
  2484. public bool JumpToMouse
  2485. {
  2486. get
  2487. {
  2488. return _JumpToMouse;
  2489. }
  2490. set
  2491. {
  2492. _JumpToMouse = value;
  2493. Invalidate();
  2494. }
  2495. }
  2496. public bool DrawValueString
  2497. {
  2498. get
  2499. {
  2500. return _DrawValueString;
  2501. }
  2502. set
  2503. {
  2504. _DrawValueString = value;
  2505. if (_DrawValueString == true)
  2506. {
  2507. Height = 35;
  2508. }
  2509. else
  2510. {
  2511. Height = 22;
  2512. }
  2513. Invalidate();
  2514. }
  2515. }
  2516. #endregion
  2517. #region EventArgs
  2518. protected override void OnMouseMove(MouseEventArgs e)
  2519. {
  2520. base.OnMouseMove(e);
  2521. checked
  2522. {
  2523. bool flag = this.Cap && e.X > -1 && e.X < this.Width + 1;
  2524. if (flag)
  2525. {
  2526. this.Value = this._Minimum + (int)Math.Round((double)(this._Maximum - this._Minimum) * ((double)e.X / (double)this.Width));
  2527. }
  2528. }
  2529. }
  2530. protected override void OnMouseDown(MouseEventArgs e)
  2531. {
  2532. base.OnMouseDown(e);
  2533. bool flag = e.Button == MouseButtons.Left;
  2534. checked
  2535. {
  2536. if (flag)
  2537. {
  2538. this.ValueDrawer = (int)Math.Round(((double)(this._Value - this._Minimum) / (double)(this._Maximum - this._Minimum)) * (double)(this.Width - 11));
  2539. this.TrackBarHandleRect = new Rectangle(this.ValueDrawer, 0, 25, 25);
  2540. this.Cap = this.TrackBarHandleRect.Contains(e.Location);
  2541. this.Focus();
  2542. flag = this._JumpToMouse;
  2543. if (flag)
  2544. {
  2545. this.Value = this._Minimum + (int)Math.Round((double)(this._Maximum - this._Minimum) * ((double)e.X / (double)this.Width));
  2546. }
  2547. }
  2548. }
  2549. }
  2550. protected override void OnMouseUp(MouseEventArgs e)
  2551. {
  2552. base.OnMouseUp(e);
  2553. Cap = false;
  2554. }
  2555. #endregion
  2556. public Ambiance_TrackBar()
  2557. {
  2558. SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer), true);
  2559. Size = new Size(80, 22);
  2560. MinimumSize = new Size(47, 22);
  2561. }
  2562. protected override void OnResize(EventArgs e)
  2563. {
  2564. base.OnResize(e);
  2565. if (_DrawValueString == true)
  2566. {
  2567. Height = 35;
  2568. }
  2569. else
  2570. {
  2571. Height = 22;
  2572. }
  2573. }
  2574. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2575. {
  2576. base.OnPaint(e);
  2577. Graphics G = e.Graphics;
  2578. G.Clear(Parent.BackColor);
  2579. G.SmoothingMode = SmoothingMode.AntiAlias;
  2580. TrackThumb = new Rectangle(8, 10, Width - 16, 2);
  2581. PipeBorder = RoundRectangle.RoundRect(1, 8, Width - 3, 5, 2);
  2582. try
  2583. {
  2584. this.ValueDrawer = (int)Math.Round(((double)(this._Value - this._Minimum) / (double)(this._Maximum - this._Minimum)) * (double)(this.Width - 11));
  2585. }
  2586. catch (Exception)
  2587. {
  2588. }
  2589. TrackBarHandleRect = new Rectangle(ValueDrawer, 0, 10, 20);
  2590. G.SetClip(PipeBorder); // Set the clipping region of this Graphics to the specified GraphicsPath
  2591. G.FillPath(new SolidBrush(Color.FromArgb(221, 221, 221)), PipeBorder);
  2592. FillValue = RoundRectangle.RoundRect(1, 8, TrackBarHandleRect.X + TrackBarHandleRect.Width - 4, 5, 2);
  2593. G.ResetClip(); // Reset the clip region of this Graphics to an infinite region
  2594. G.SmoothingMode = SmoothingMode.HighQuality;
  2595. G.DrawPath(new Pen(Color.FromArgb(200, 200, 200)), PipeBorder); // Draw pipe border
  2596. G.FillPath(new SolidBrush(Color.FromArgb(217, 99, 50)), FillValue);
  2597. G.FillEllipse(new SolidBrush(Color.FromArgb(244, 244, 244)), this.TrackThumb.X + (int)Math.Round(unchecked((double)this.TrackThumb.Width * ((double)this.Value / (double)this.Maximum))) - (int)Math.Round((double)this.ThumbSize.Width / 2.0), this.TrackThumb.Y + (int)Math.Round((double)this.TrackThumb.Height / 2.0) - (int)Math.Round((double)this.ThumbSize.Height / 2.0), this.ThumbSize.Width, this.ThumbSize.Height);
  2598. G.DrawEllipse(new Pen(Color.FromArgb(180, 180, 180)), this.TrackThumb.X + (int)Math.Round(unchecked((double)this.TrackThumb.Width * ((double)this.Value / (double)this.Maximum))) - (int)Math.Round((double)this.ThumbSize.Width / 2.0), this.TrackThumb.Y + (int)Math.Round((double)this.TrackThumb.Height / 2.0) - (int)Math.Round((double)this.ThumbSize.Height / 2.0), this.ThumbSize.Width, this.ThumbSize.Height);
  2599. if (_DrawValueString == true)
  2600. {
  2601. G.DrawString(System.Convert.ToString(ValueToSet), Font, Brushes.DimGray, 1, 20);
  2602. }
  2603. }
  2604. }
  2605. #endregion
  2606. #region Panel
  2607. public class Ambiance_Panel : ContainerControl
  2608. {
  2609. public Ambiance_Panel()
  2610. {
  2611. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  2612. SetStyle(ControlStyles.Opaque, false);
  2613. }
  2614. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2615. {
  2616. Graphics G = e.Graphics;
  2617. this.Font = new Font("Tahoma", 9);
  2618. this.BackColor = Color.White;
  2619. G.SmoothingMode = SmoothingMode.AntiAlias;
  2620. G.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, Width, Height));
  2621. G.FillRectangle(new SolidBrush(Color.White), new Rectangle(0, 0, Width - 1, Height - 1));
  2622. G.DrawRectangle(new Pen(Color.FromArgb(211, 208, 205)), 0, 0, Width - 1, Height - 1);
  2623. }
  2624. }
  2625. #endregion
  2626. #region TextBox
  2627. [DefaultEvent("TextChanged")]
  2628. class Amiance_TextBox : Control
  2629. {
  2630. #region Variables
  2631. public TextBox AmbianceTB = new TextBox();
  2632. private GraphicsPath Shape;
  2633. private int _maxchars = 32767;
  2634. private bool _ReadOnly;
  2635. private bool _Multiline;
  2636. private HorizontalAlignment ALNType;
  2637. private bool isPasswordMasked = false;
  2638. private Pen P1;
  2639. private SolidBrush B1;
  2640. #endregion
  2641. #region Properties
  2642. public HorizontalAlignment TextAlignment
  2643. {
  2644. get { return ALNType; }
  2645. set
  2646. {
  2647. ALNType = value;
  2648. Invalidate();
  2649. }
  2650. }
  2651. public int MaxLength
  2652. {
  2653. get { return _maxchars; }
  2654. set
  2655. {
  2656. _maxchars = value;
  2657. AmbianceTB.MaxLength = MaxLength;
  2658. Invalidate();
  2659. }
  2660. }
  2661. public bool UseSystemPasswordChar
  2662. {
  2663. get { return isPasswordMasked; }
  2664. set
  2665. {
  2666. AmbianceTB.UseSystemPasswordChar = UseSystemPasswordChar;
  2667. isPasswordMasked = value;
  2668. Invalidate();
  2669. }
  2670. }
  2671. public bool ReadOnly
  2672. {
  2673. get { return _ReadOnly; }
  2674. set
  2675. {
  2676. _ReadOnly = value;
  2677. if (AmbianceTB != null)
  2678. {
  2679. AmbianceTB.ReadOnly = value;
  2680. }
  2681. }
  2682. }
  2683. public bool Multiline
  2684. {
  2685. get { return _Multiline; }
  2686. set
  2687. {
  2688. _Multiline = value;
  2689. if (AmbianceTB != null)
  2690. {
  2691. AmbianceTB.Multiline = value;
  2692. if (value)
  2693. {
  2694. AmbianceTB.Height = Height - 10;
  2695. }
  2696. else
  2697. {
  2698. Height = AmbianceTB.Height + 10;
  2699. }
  2700. }
  2701. }
  2702. }
  2703. #endregion
  2704. #region EventArgs
  2705. protected override void OnTextChanged(System.EventArgs e)
  2706. {
  2707. base.OnTextChanged(e);
  2708. AmbianceTB.Text = Text;
  2709. Invalidate();
  2710. }
  2711. protected override void OnForeColorChanged(System.EventArgs e)
  2712. {
  2713. base.OnForeColorChanged(e);
  2714. AmbianceTB.ForeColor = ForeColor;
  2715. Invalidate();
  2716. }
  2717. protected override void OnFontChanged(System.EventArgs e)
  2718. {
  2719. base.OnFontChanged(e);
  2720. AmbianceTB.Font = Font;
  2721. }
  2722. protected override void OnPaintBackground(PaintEventArgs e)
  2723. {
  2724. base.OnPaintBackground(e);
  2725. }
  2726. private void _OnKeyDown(object Obj, KeyEventArgs e)
  2727. {
  2728. if (e.Control && e.KeyCode == Keys.A)
  2729. {
  2730. AmbianceTB.SelectAll();
  2731. e.SuppressKeyPress = true;
  2732. }
  2733. if (e.Control && e.KeyCode == Keys.C)
  2734. {
  2735. AmbianceTB.Copy();
  2736. e.SuppressKeyPress = true;
  2737. }
  2738. }
  2739. private void _Enter(object Obj, EventArgs e)
  2740. {
  2741. P1 = new Pen(Color.FromArgb(205, 87, 40));
  2742. Refresh();
  2743. }
  2744. private void _Leave(object Obj, EventArgs e)
  2745. {
  2746. P1 = new Pen(Color.FromArgb(180, 180, 180));
  2747. Refresh();
  2748. }
  2749. protected override void OnResize(System.EventArgs e)
  2750. {
  2751. base.OnResize(e);
  2752. if (_Multiline)
  2753. {
  2754. AmbianceTB.Height = Height - 10;
  2755. }
  2756. else
  2757. {
  2758. Height = AmbianceTB.Height + 10;
  2759. }
  2760. Shape = new GraphicsPath();
  2761. var _with1 = Shape;
  2762. _with1.AddArc(0, 0, 10, 10, 180, 90);
  2763. _with1.AddArc(Width - 11, 0, 10, 10, -90, 90);
  2764. _with1.AddArc(Width - 11, Height - 11, 10, 10, 0, 90);
  2765. _with1.AddArc(0, Height - 11, 10, 10, 90, 90);
  2766. _with1.CloseAllFigures();
  2767. }
  2768. protected override void OnGotFocus(System.EventArgs e)
  2769. {
  2770. base.OnGotFocus(e);
  2771. AmbianceTB.Focus();
  2772. }
  2773. #endregion
  2774. public void AddTextBox()
  2775. {
  2776. var _TB = AmbianceTB;
  2777. _TB.Size = new Size(Width - 10, 33);
  2778. _TB.Location = new Point(7, 4);
  2779. _TB.Text = string.Empty;
  2780. _TB.BorderStyle = BorderStyle.None;
  2781. _TB.TextAlign = HorizontalAlignment.Left;
  2782. _TB.Font = new Font("Tahoma", 11);
  2783. _TB.UseSystemPasswordChar = UseSystemPasswordChar;
  2784. _TB.Multiline = false;
  2785. AmbianceTB.KeyDown += _OnKeyDown;
  2786. AmbianceTB.Enter += _Enter;
  2787. AmbianceTB.Leave += _Leave;
  2788. }
  2789. public Amiance_TextBox()
  2790. {
  2791. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  2792. SetStyle(ControlStyles.UserPaint, true);
  2793. AddTextBox();
  2794. Controls.Add(AmbianceTB);
  2795. P1 = new Pen(Color.FromArgb(180, 180, 180)); // P1 = Border color
  2796. B1 = new SolidBrush(Color.White); // B1 = Rect Background color
  2797. BackColor = Color.Transparent;
  2798. ForeColor = Color.DimGray;
  2799. Text = null;
  2800. Font = new Font("Tahoma", 11);
  2801. Size = new Size(135, 33);
  2802. DoubleBuffered = true;
  2803. }
  2804. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2805. {
  2806. base.OnPaint(e);
  2807. Bitmap B = new Bitmap(Width, Height);
  2808. Graphics G = Graphics.FromImage(B);
  2809. G.SmoothingMode = SmoothingMode.AntiAlias;
  2810. var _TB = AmbianceTB;
  2811. _TB.Width = Width - 10;
  2812. _TB.TextAlign = TextAlignment;
  2813. _TB.UseSystemPasswordChar = UseSystemPasswordChar;
  2814. G.Clear(Color.Transparent);
  2815. G.FillPath(B1, Shape); // Draw background
  2816. G.DrawPath(P1, Shape); // Draw border
  2817. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  2818. G.Dispose();
  2819. B.Dispose();
  2820. }
  2821. }
  2822. #endregion
  2823. #region RichTextBox
  2824. [DefaultEvent("TextChanged")]
  2825. class Ambiance_RichTextBox : Control
  2826. {
  2827. #region Variables
  2828. public RichTextBox AmbianceRTB = new RichTextBox();
  2829. private bool _ReadOnly;
  2830. private bool _WordWrap;
  2831. private bool _AutoWordSelection;
  2832. private GraphicsPath Shape;
  2833. private Pen P1;
  2834. #endregion
  2835. #region Properties
  2836. public override string Text
  2837. {
  2838. get { return AmbianceRTB.Text; }
  2839. set
  2840. {
  2841. AmbianceRTB.Text = value;
  2842. Invalidate();
  2843. }
  2844. }
  2845. public bool ReadOnly
  2846. {
  2847. get { return _ReadOnly; }
  2848. set
  2849. {
  2850. _ReadOnly = value;
  2851. if (AmbianceRTB != null)
  2852. {
  2853. AmbianceRTB.ReadOnly = value;
  2854. }
  2855. }
  2856. }
  2857. public bool WordWrap
  2858. {
  2859. get { return _WordWrap; }
  2860. set
  2861. {
  2862. _WordWrap = value;
  2863. if (AmbianceRTB != null)
  2864. {
  2865. AmbianceRTB.WordWrap = value;
  2866. }
  2867. }
  2868. }
  2869. public bool AutoWordSelection
  2870. {
  2871. get { return _AutoWordSelection; }
  2872. set
  2873. {
  2874. _AutoWordSelection = value;
  2875. if (AmbianceRTB != null)
  2876. {
  2877. AmbianceRTB.AutoWordSelection = value;
  2878. }
  2879. }
  2880. }
  2881. #endregion
  2882. #region EventArgs
  2883. protected override void OnTextChanged(System.EventArgs e)
  2884. {
  2885. base.OnTextChanged(e);
  2886. AmbianceRTB.Text = Text;
  2887. Invalidate();
  2888. }
  2889. protected override void OnForeColorChanged(System.EventArgs e)
  2890. {
  2891. base.OnForeColorChanged(e);
  2892. AmbianceRTB.ForeColor = ForeColor;
  2893. Invalidate();
  2894. }
  2895. protected override void OnFontChanged(System.EventArgs e)
  2896. {
  2897. base.OnFontChanged(e);
  2898. AmbianceRTB.Font = Font;
  2899. }
  2900. protected override void OnPaintBackground(PaintEventArgs e)
  2901. {
  2902. base.OnPaintBackground(e);
  2903. }
  2904. protected override void OnSizeChanged(System.EventArgs e)
  2905. {
  2906. base.OnSizeChanged(e);
  2907. AmbianceRTB.Size = new Size(Width - 13, Height - 11);
  2908. }
  2909. private void _Enter(object Obj, EventArgs e)
  2910. {
  2911. P1 = new Pen(Color.FromArgb(205, 87, 40));
  2912. Refresh();
  2913. }
  2914. private void _Leave(object Obj, EventArgs e)
  2915. {
  2916. P1 = new Pen(Color.FromArgb(180, 180, 180));
  2917. Refresh();
  2918. }
  2919. protected override void OnResize(System.EventArgs e)
  2920. {
  2921. base.OnResize(e);
  2922. Shape = new GraphicsPath();
  2923. var _with1 = Shape;
  2924. _with1.AddArc(0, 0, 10, 10, 180, 90);
  2925. _with1.AddArc(Width - 11, 0, 10, 10, -90, 90);
  2926. _with1.AddArc(Width - 11, Height - 11, 10, 10, 0, 90);
  2927. _with1.AddArc(0, Height - 11, 10, 10, 90, 90);
  2928. _with1.CloseAllFigures();
  2929. }
  2930. #endregion
  2931. public void AddRichTextBox()
  2932. {
  2933. var _TB = AmbianceRTB;
  2934. _TB.BackColor = Color.White;
  2935. _TB.Size = new Size(Width - 10, 100);
  2936. _TB.Location = new Point(7, 5);
  2937. _TB.Text = string.Empty;
  2938. _TB.BorderStyle = BorderStyle.None;
  2939. _TB.Font = new Font("Tahoma", 10);
  2940. _TB.Multiline = true;
  2941. AmbianceRTB.Enter += _Enter;
  2942. AmbianceRTB.Leave += _Leave;
  2943. }
  2944. public Ambiance_RichTextBox()
  2945. : base()
  2946. {
  2947. SetStyle(ControlStyles.SupportsTransparentBackColor, true);
  2948. SetStyle(ControlStyles.UserPaint, true);
  2949. AddRichTextBox();
  2950. Controls.Add(AmbianceRTB);
  2951. BackColor = Color.Transparent;
  2952. ForeColor = Color.DimGray;
  2953. P1 = new Pen(Color.FromArgb(180, 180, 180)); // P1 = Border color
  2954. Text = null;
  2955. Font = new Font("Tahoma", 10);
  2956. Size = new Size(150, 100);
  2957. WordWrap = true;
  2958. AutoWordSelection = false;
  2959. DoubleBuffered = true;
  2960. }
  2961. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  2962. {
  2963. base.OnPaint(e);
  2964. Bitmap B = new Bitmap(this.Width, this.Height);
  2965. Graphics G = Graphics.FromImage(B);
  2966. G.SmoothingMode = SmoothingMode.AntiAlias;
  2967. G.Clear(Color.Transparent);
  2968. G.FillPath(Brushes.White, this.Shape);
  2969. G.DrawPath(P1, this.Shape);
  2970. G.Dispose();
  2971. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  2972. B.Dispose();
  2973. }
  2974. }
  2975. #endregion
  2976. #region ListBox
  2977. public class Ambiance_ListBox : ListBox
  2978. {
  2979. public Ambiance_ListBox()
  2980. {
  2981. this.SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint), true);
  2982. this.DrawMode = DrawMode.OwnerDrawFixed;
  2983. IntegralHeight = false;
  2984. ItemHeight = 18;
  2985. Font = new Font("Seoge UI", 11, FontStyle.Regular);
  2986. }
  2987. protected override void OnDrawItem(DrawItemEventArgs e)
  2988. {
  2989. base.OnDrawItem(e);
  2990. e.DrawBackground();
  2991. LinearGradientBrush LGB = new LinearGradientBrush(e.Bounds, Color.FromArgb(246, 132, 85), Color.FromArgb(231, 108, 57), 90.0F);
  2992. if (System.Convert.ToInt32((e.State & DrawItemState.Selected)) == (int)DrawItemState.Selected)
  2993. {
  2994. e.Graphics.FillRectangle(LGB, e.Bounds);
  2995. }
  2996. using (SolidBrush b = new SolidBrush(e.ForeColor))
  2997. {
  2998. if (base.Items.Count == 0)
  2999. {
  3000. return;
  3001. }
  3002. else
  3003. {
  3004. e.Graphics.DrawString(base.GetItemText(base.Items[e.Index]), e.Font, b, e.Bounds);
  3005. }
  3006. }
  3007. LGB.Dispose();
  3008. }
  3009. protected override void OnPaint(PaintEventArgs e)
  3010. {
  3011. base.OnPaint(e);
  3012. Region MyRegion = new Region(e.ClipRectangle);
  3013. e.Graphics.FillRegion(new SolidBrush(this.BackColor), MyRegion);
  3014. if (this.Items.Count > 0)
  3015. {
  3016. for (int i = 0; i <= this.Items.Count - 1; i++)
  3017. {
  3018. System.Drawing.Rectangle RegionRect = this.GetItemRectangle(i);
  3019. if (e.ClipRectangle.IntersectsWith(RegionRect))
  3020. {
  3021. if ((this.SelectionMode == SelectionMode.One && this.SelectedIndex == i) || (this.SelectionMode == SelectionMode.MultiSimple && this.SelectedIndices.Contains(i)) || (this.SelectionMode == SelectionMode.MultiExtended && this.SelectedIndices.Contains(i)))
  3022. {
  3023. OnDrawItem(new DrawItemEventArgs(e.Graphics, this.Font, RegionRect, i, DrawItemState.Selected, this.ForeColor, this.BackColor));
  3024. }
  3025. else
  3026. {
  3027. OnDrawItem(new DrawItemEventArgs(e.Graphics, this.Font, RegionRect, i, DrawItemState.Default, Color.FromArgb(60, 60, 60), this.BackColor));
  3028. }
  3029. MyRegion.Complement(RegionRect);
  3030. }
  3031. }
  3032. }
  3033. }
  3034. }
  3035. #endregion
  3036. #region TabControl
  3037. public class Ambiance_TabControl : TabControl
  3038. {
  3039. public Ambiance_TabControl()
  3040. {
  3041. SetStyle((System.Windows.Forms.ControlStyles)(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.UserPaint), true);
  3042. }
  3043. protected override void CreateHandle()
  3044. {
  3045. base.CreateHandle();
  3046. ItemSize = new Size(80, 24);
  3047. Alignment = TabAlignment.Top;
  3048. }
  3049. protected override void OnPaint(PaintEventArgs e)
  3050. {
  3051. Graphics G = e.Graphics;
  3052. Rectangle ItemBoundsRect = new Rectangle();
  3053. G.Clear(Parent.BackColor);
  3054. for (int TabIndex = 0; TabIndex <= TabCount - 1; TabIndex++)
  3055. {
  3056. ItemBoundsRect = GetTabRect(TabIndex);
  3057. if (!(TabIndex == SelectedIndex))
  3058. {
  3059. G.DrawString(TabPages[TabIndex].Text, new Font(Font.Name, Font.Size - 2, FontStyle.Bold), new SolidBrush(Color.FromArgb(80, 76, 76)), new Rectangle(GetTabRect(TabIndex).Location, GetTabRect(TabIndex).Size), new StringFormat
  3060. {
  3061. LineAlignment = StringAlignment.Center,
  3062. Alignment = StringAlignment.Center
  3063. });
  3064. }
  3065. }
  3066. // Draw container rectangle
  3067. G.FillPath(new SolidBrush(Color.FromArgb(247, 246, 246)), RoundRectangle.RoundRect(0, 23, Width - 1, Height - 24, 2));
  3068. G.DrawPath(new Pen(Color.FromArgb(201, 198, 195)), RoundRectangle.RoundRect(0, 23, Width - 1, Height - 24, 2));
  3069. for (int ItemIndex = 0; ItemIndex <= TabCount - 1; ItemIndex++)
  3070. {
  3071. ItemBoundsRect = GetTabRect(ItemIndex);
  3072. if (ItemIndex == SelectedIndex)
  3073. {
  3074. // Draw header tabs
  3075. G.DrawPath(new Pen(Color.FromArgb(201, 198, 195)), RoundRectangle.RoundedTopRect(new Rectangle(new Point(ItemBoundsRect.X - 2, ItemBoundsRect.Y - 2), new Size(ItemBoundsRect.Width + 3, ItemBoundsRect.Height)), 7));
  3076. G.FillPath(new SolidBrush(Color.FromArgb(247, 246, 246)), RoundRectangle.RoundedTopRect(new Rectangle(new Point(ItemBoundsRect.X - 1, ItemBoundsRect.Y - 1), new Size(ItemBoundsRect.Width + 2, ItemBoundsRect.Height)), 7));
  3077. try
  3078. {
  3079. G.DrawString(TabPages[ItemIndex].Text, new Font(Font.Name, Font.Size - 1, FontStyle.Bold), new SolidBrush(Color.FromArgb(80, 76, 76)), new Rectangle(GetTabRect(ItemIndex).Location, GetTabRect(ItemIndex).Size), new StringFormat
  3080. {
  3081. LineAlignment = StringAlignment.Center,
  3082. Alignment = StringAlignment.Center
  3083. });
  3084. TabPages[ItemIndex].BackColor = Color.FromArgb(247, 246, 246);
  3085. }
  3086. catch
  3087. {
  3088. }
  3089. }
  3090. }
  3091. }
  3092. }
  3093. #endregion

comments powered by Disqus