Advertisement
Astekk

Modern theme c#

Dec 3rd, 2014
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.27 KB | None | 0 0
  1. //theme base 1.5.2
  2. using System;
  3. using System.Drawing;
  4. using System.Drawing.Drawing2D;
  5. using System.Windows.Forms;
  6.  
  7. public class ModernTheme : Control {
  8. public ModernTheme() {
  9. ForeColor = Color.FromArgb(50, 210, 50);
  10. }
  11.  
  12. private int _TitleHeight = 25;
  13. public int TitleHeight {
  14. get { return _TitleHeight; }
  15. set {
  16. if (value > Height) {
  17. value = Height;
  18. }
  19. if (value < 2) {
  20. Height = 1;
  21. }
  22. _TitleHeight = value;
  23. Invalidate();
  24. }
  25. }
  26. private HorizontalAlignment _TitleAlign = (HorizontalAlignment)2;
  27.  
  28. public HorizontalAlignment TitleAlign {
  29. get { return _TitleAlign; }
  30. set {
  31. _TitleAlign = value;
  32. Invalidate();
  33. }
  34. }
  35.  
  36. protected override void OnHandleCreated(System.EventArgs e) {
  37. Dock = (DockStyle)5;
  38. if (Parent is Form)
  39. ((Form)Parent).FormBorderStyle = 0;
  40. base.OnHandleCreated(e);
  41. }
  42.  
  43. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) {
  44. if (new Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(new Rectangle(MousePosition.X, MousePosition.Y, 1, 1))) {
  45. Capture = false;
  46. var M = Message.Create(Parent.Handle, 161, new IntPtr(2), new IntPtr(0));
  47. DefWndProc(ref M);
  48. }
  49. base.OnMouseDown(e);
  50. }
  51.  
  52. private Color C1 = Color.FromArgb(74, 74, 74);
  53. private Color C2 = Color.FromArgb(63, 63, 63);
  54. private Color C3 = Color.FromArgb(41, 41, 41);
  55. private Color C4 = Color.FromArgb(27, 27, 27);
  56. private Color C5 = Color.FromArgb(0, 0, 0, 0);
  57. private Color C6 = Color.FromArgb(25, 255, 255, 255);
  58.  
  59. protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent) { }
  60.  
  61. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) {
  62. using (Bitmap B = new Bitmap(Width, Height)) {
  63. using (var G = Graphics.FromImage(B)) {
  64. G.Clear(C3);
  65. Draw.Gradient(G, C4, C3, 0, 0, Width, _TitleHeight);
  66.  
  67. G.DrawString(Text, Font, new SolidBrush(ForeColor), 6, 6);
  68.  
  69. G.DrawLine(new Pen(C3), 0, 1, Width, 1);
  70. Draw.Blend(G, C5, C6, C5, 0.5F, 0, 0, _TitleHeight + 1, Width, 1);
  71. G.DrawLine(new Pen(C4), 0, _TitleHeight, Width, _TitleHeight);
  72. G.DrawRectangle(new Pen(C4), 0, 0, Width - 1, Height - 1);
  73. e.Graphics.DrawImage((Image)B.Clone(), (float)0, (float)0);
  74. }
  75. }
  76. }
  77. }
  78.  
  79. public class MCheckBox : Control {
  80. public MCheckBox() {
  81. ForeColor = Color.FromArgb(50, 210, 50);
  82. }
  83. private bool _checked;
  84. public bool Checked {
  85. get { return _checked; }
  86. set {
  87. _checked = value;
  88. Invalidate();
  89. }
  90. }
  91.  
  92. private int State;
  93. protected override void OnMouseEnter(System.EventArgs e) {
  94. State = 1;
  95. Invalidate();
  96. base.OnMouseEnter(e);
  97. }
  98.  
  99. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) {
  100. State = 2;
  101. Invalidate();
  102. base.OnMouseDown(e);
  103. }
  104.  
  105. protected override void OnMouseLeave(System.EventArgs e) {
  106. State = 0;
  107. Invalidate();
  108. base.OnMouseLeave(e);
  109. }
  110.  
  111. protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) {
  112. State = 1;
  113. Invalidate();
  114. base.OnMouseUp(e);
  115. }
  116.  
  117. protected override void OnClick(System.EventArgs e) {
  118. _checked = !_checked;
  119. }
  120.  
  121. private Color C1 = Color.FromArgb(31, 31, 31);
  122. private Color C2 = Color.FromArgb(41, 41, 41);
  123. private Color C3 = Color.FromArgb(51, 51, 51);
  124. private Color C4 = Color.FromArgb(0, 0, 0, 0);
  125. private Color C5 = Color.FromArgb(25, 255, 255, 255);
  126.  
  127. protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent) { }
  128.  
  129. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) {
  130.  
  131. using (Bitmap B = new Bitmap(Width, Height)) {
  132. using (var G = Graphics.FromImage(B)) {
  133.  
  134. G.Clear(Color.FromArgb(41, 41, 41));
  135.  
  136. int BWidth = 15, BHeight = 14;
  137.  
  138. if (State == 1 && _checked) {
  139. G.DrawRectangle(new Pen(C2), 1, 1, BWidth - 3, BHeight);
  140. Draw.Gradient(G, Color.FromArgb(0, 120, 0), Color.FromArgb(0, 110, 0), 1, 1, BWidth - 2, BHeight);
  141. G.DrawRectangle(new Pen(C1), 0, 0, BWidth - 1, BHeight);
  142. }
  143. else if (State == 2 && _checked) {
  144. G.DrawRectangle(new Pen(C2), 1, 1, BWidth - 3, BHeight - 3);
  145. Draw.Gradient(G, Color.FromArgb(0, 100, 0), Color.FromArgb(0, 90, 0), 1, 1, BWidth - 2, BHeight);
  146. G.DrawRectangle(new Pen(C1), 0, 0, BWidth - 1, BHeight);
  147. }
  148. else if (State == 1 && !_checked) {
  149. G.DrawRectangle(new Pen(C2), 1, 1, BWidth - 3, BHeight - 3);
  150. Draw.Gradient(G, Color.FromArgb(120, 0, 0), Color.FromArgb(110, 0, 0), 1, 1, BWidth - 2, BHeight);
  151. G.DrawRectangle(new Pen(C1), 0, 0, BWidth - 1, BHeight);
  152. }
  153. else if (State == 2 && !_checked) {
  154. G.DrawRectangle(new Pen(C2), 1, 1, BWidth - 3, BHeight - 3);
  155. Draw.Gradient(G, Color.FromArgb(100, 0, 0), Color.FromArgb(90, 0, 0), 1, 1, BWidth - 2, BHeight);
  156. G.DrawRectangle(new Pen(C1), 0, 0, BWidth - 1, BHeight);
  157. }
  158. else if (_checked) {
  159. G.DrawRectangle(new Pen(C2), 1, 1, BWidth - 3, BHeight - 3);
  160. Draw.Gradient(G, Color.FromArgb(0, 110, 0), Color.FromArgb(0, 100, 0), 1, 1, BWidth - 2, BHeight);
  161. G.DrawRectangle(new Pen(C1), 0, 0, BWidth - 1, BHeight);
  162. }
  163. else if (!_checked) {
  164. G.DrawRectangle(new Pen(C2), 1, 1, BWidth - 3, BHeight - 3);
  165. Draw.Gradient(G, Color.FromArgb(110, 0, 0), Color.FromArgb(100, 0, 0), 1, 1, BWidth - 2, BHeight);
  166. G.DrawRectangle(new Pen(C1), 0, 0, BWidth - 1, BHeight);
  167. }
  168. G.DrawString(Text, Font, new SolidBrush(ForeColor), 16, 1);
  169. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  170. }
  171. }
  172. }
  173. }
  174.  
  175. public class MGroupBox : Control {
  176.  
  177. public MGroupBox() {
  178. ForeColor = Color.FromArgb(50, 210, 50);
  179. }
  180.  
  181. private Color C1 = Color.FromArgb(31, 31, 31);
  182. private Color C2 = Color.FromArgb(41, 41, 41);
  183. private Color C3 = Color.FromArgb(51, 51, 51);
  184.  
  185. protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent) { }
  186.  
  187. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) {
  188. using (Bitmap B = new Bitmap(Width, Height)) {
  189. using (var G = Graphics.FromImage(B)) {
  190.  
  191. Draw.Gradient(G, C3, C2, 1, 1, Width - 2, 20);
  192. G.FillRectangle(new SolidBrush(C2), new Rectangle(1, 21, Width - 1, Height - 1));
  193.  
  194. G.DrawString(Text, Font, new SolidBrush(ForeColor), 5 , 4);
  195.  
  196. G.DrawRectangle(new Pen(C1), 0, 0, Width - 1, Height - 1);
  197. G.DrawLine(new Pen(C1), 0, 21, Width, 21);
  198.  
  199. e.Graphics.DrawImage((Image)B.Clone(), (float)0, (float)0);
  200. }
  201. }
  202. }
  203. }
  204.  
  205.  
  206.  
  207. public class MButton : Control {
  208. public MButton() {
  209. ForeColor = Color.FromArgb(50, 210, 50);
  210. }
  211.  
  212. private int State;
  213. protected override void OnMouseEnter(System.EventArgs e) {
  214. State = 1;
  215. Invalidate();
  216. base.OnMouseEnter(e);
  217. }
  218.  
  219. protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e) {
  220. State = 2;
  221. Invalidate();
  222. base.OnMouseDown(e);
  223. }
  224.  
  225. protected override void OnMouseLeave(System.EventArgs e) {
  226. State = 0;
  227. Invalidate();
  228. base.OnMouseLeave(e);
  229. }
  230.  
  231. protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) {
  232. State = 1;
  233. Invalidate();
  234. base.OnMouseUp(e);
  235. }
  236.  
  237. private Color C1 = Color.FromArgb(31, 31, 31);
  238. private Color C2 = Color.FromArgb(41, 41, 41);
  239. private Color C3 = Color.FromArgb(51, 51, 51);
  240. private Color C4 = Color.FromArgb(0, 0, 0, 0);
  241. private Color C5 = Color.FromArgb(25, 255, 255, 255);
  242.  
  243. protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent) { }
  244.  
  245. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) {
  246. using (Bitmap B = new Bitmap(Width, Height)) {
  247. using (var G = Graphics.FromImage(B)) {
  248. G.DrawRectangle(new Pen(C1), 0, 0, Width - 1, Height - 1);
  249.  
  250. if (State == 2)
  251. Draw.Gradient(G, C2, C3, 1, 1, Width - 2, Height - 2);
  252. else
  253. Draw.Gradient(G, C3, C2, 1, 1, Width - 2, Height - 2);
  254.  
  255. var O = G.MeasureString(Text, Font);
  256. G.DrawString(Text, Font, new SolidBrush(ForeColor), Width / 2 - O.Width / 2, Height / 2 - O.Height / 2 + 1);
  257. Draw.Blend(G, C4, C5, C4, 0.5F, 0, 1, 1, Width - 2, 1);
  258. e.Graphics.DrawImage((Image)B.Clone(), (float)0, (float)0);
  259. }
  260. }
  261. }
  262. }
  263.  
  264. public class MProgress : Control {
  265.  
  266. private bool _percent;
  267. public bool ShowPercent {
  268. get { return _percent; }
  269. set { _percent = value; }
  270. }
  271.  
  272. private int _Maximum = 100;
  273. public int Maximum {
  274. get { return _Maximum; }
  275. set {
  276. if (value == 0)
  277. value = 1;
  278. _Maximum = value;
  279. Invalidate();
  280. }
  281. }
  282.  
  283. private int _Value;
  284. public int Value {
  285. get { return _Value; }
  286. set {
  287. _Value = value;
  288. Invalidate();
  289. }
  290. }
  291.  
  292. public MProgress() {
  293. ForeColor = Color.FromArgb(50, 210, 50);
  294. Height = 18;
  295. }
  296.  
  297. private Color C1 = Color.FromArgb(31, 31, 31);
  298. private Color C2 = Color.FromArgb(41, 41, 41);
  299. private Color C3 = Color.FromArgb(51, 51, 51);
  300. private Color C4 = Color.FromArgb(0, 0, 0, 0);
  301. private Color C5 = Color.FromArgb(25, 255, 255, 255);
  302.  
  303. protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent) { }
  304.  
  305. protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) {
  306. int V = Width * _Value / _Maximum;
  307. using (Bitmap B = new Bitmap(Width, Height)) {
  308. using (var G = Graphics.FromImage(B)) {
  309. Draw.Gradient(G, C2, C3, 1, 1, Width - 2, Height - 2);
  310. G.DrawRectangle(new Pen(C2), 1, 1, V - 3, Height - 3);
  311. Draw.Gradient(G, C3, C2, 2, 2, V - 4, Height - 4);
  312. G.DrawRectangle(new Pen(C1), 0, 0, Width - 1, Height - 1);
  313. if (_percent) {
  314. string _spercent = (100 * _Value / _Maximum).ToString() + "%";
  315. var O = G.MeasureString(_spercent, Font);
  316. G.DrawString(_spercent, Font, new SolidBrush(ForeColor), new PointF(Width / 2 - O.Width / 2, Height / 2 - O.Height / 2 + 1));
  317. }
  318. e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
  319. }
  320. }
  321. }
  322. }
  323.  
  324. class MComboBox : ComboBox {
  325.  
  326. private Color C1 = Color.FromArgb(31, 31, 31);
  327. private Color C2 = Color.FromArgb(41, 41, 41);
  328. private Color C3 = Color.FromArgb(51, 51, 51);
  329. private Color C4 = Color.FromArgb(0, 0, 0, 0);
  330. private Color C5 = Color.FromArgb(25, 255, 255, 255);
  331.  
  332. private int X;
  333. public MComboBox()
  334. : base() {
  335. ForeColor = Color.FromArgb(50, 210, 50);
  336. TextChanged += GhostCombo_TextChanged;
  337. DropDownClosed += GhostComboBox_DropDownClosed;
  338. SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  339. DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
  340. ItemHeight = 20;
  341. BackColor = Color.FromArgb(30, 30, 30);
  342. DropDownStyle = ComboBoxStyle.DropDownList;
  343. }
  344.  
  345. protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e) {
  346. base.OnMouseMove(e);
  347. X = e.X;
  348. Invalidate();
  349. }
  350.  
  351. protected override void OnMouseLeave(System.EventArgs e) {
  352. base.OnMouseLeave(e);
  353. X = -1;
  354. Invalidate();
  355. }
  356.  
  357. protected override void OnPaint(PaintEventArgs e) {
  358. if (!(DropDownStyle == ComboBoxStyle.DropDownList))
  359. DropDownStyle = ComboBoxStyle.DropDownList;
  360. Bitmap B = new Bitmap(Width, Height);
  361. Graphics G = Graphics.FromImage(B);
  362.  
  363. G.Clear(Color.FromArgb(50, 50, 50));
  364. LinearGradientBrush GradientBrush = new LinearGradientBrush(new Rectangle(0, 0, Width, Height / 5 * 2), Color.FromArgb(20, 0, 0, 0), Color.FromArgb(15, Color.White), 90f);
  365.  
  366. G.DrawRectangle(new Pen(C1), 0, 0, Width - 1, Height - 1);
  367. Draw.Gradient(G, C3, C2, 1, 1, Width - 2, Height - 2);
  368.  
  369. int S1 = (int)G.MeasureString("...", Font).Height;
  370. if (SelectedIndex != -1) {
  371. G.DrawString(Items[SelectedIndex].ToString(), Font, new SolidBrush(ForeColor), 4, Height / 2 - S1 / 2);
  372. }
  373. else {
  374. if ((Items != null) & Items.Count > 0) {
  375. G.DrawString(Items[0].ToString(), Font, new SolidBrush(ForeColor), 4, Height / 2 - S1 / 2);
  376. }
  377. else {
  378. G.DrawString("...", Font, new SolidBrush(ForeColor), 4, Height / 2 - S1 / 2);
  379. }
  380. }
  381.  
  382. if (MouseButtons == System.Windows.Forms.MouseButtons.None & X >= Width - 25 ||
  383. MouseButtons == System.Windows.Forms.MouseButtons.None & X <= Width - 25 & X >= 0) {
  384. G.FillRectangle(new SolidBrush(Color.FromArgb(7, Color.White)), Width - 25, 1, Width - 25, Height - 3);
  385. G.FillRectangle(new SolidBrush(Color.FromArgb(7, Color.White)), 2, 1, Width - 27, Height - 3);
  386. }
  387.  
  388. G.FillPolygon(Brushes.Black, Triangle(new Point(Width - 14, Height / 2), new Size(5, 3)));
  389. G.FillPolygon(Brushes.White, Triangle(new Point(Width - 15, Height / 2 - 1), new Size(5, 3)));
  390.  
  391. e.Graphics.DrawImage(B, 0, 0);
  392. G.Dispose();
  393. B.Dispose();
  394. }
  395.  
  396. protected override void OnDrawItem(DrawItemEventArgs e) {
  397. if (e.Index < 0)
  398. return;
  399. Rectangle rect = new Rectangle();
  400. rect.X = e.Bounds.X;
  401. rect.Y = e.Bounds.Y;
  402. rect.Width = e.Bounds.Width - 1;
  403. rect.Height = e.Bounds.Height - 1;
  404.  
  405. e.DrawBackground();
  406. if ((int)e.State == 785 | (int)e.State == 17) {
  407. Rectangle x2 = new Rectangle(e.Bounds.Location, new Size(e.Bounds.Width, e.Bounds.Height));
  408. Rectangle x3 = new Rectangle(x2.Location, new Size(x2.Width, (x2.Height / 2) - 1));
  409. LinearGradientBrush G1 = new LinearGradientBrush(new Point(x2.X, x2.Y), new Point(x2.X, x2.Y + x2.Height), Color.FromArgb(60, 60, 60), Color.FromArgb(50, 50, 50));
  410. e.Graphics.FillRectangle(G1, x2);
  411. G1.Dispose();
  412. e.Graphics.DrawString(" " + Items[e.Index].ToString(), Font, new SolidBrush(ForeColor), e.Bounds.X, e.Bounds.Y + 2);
  413. }
  414. else {
  415. e.Graphics.FillRectangle(new SolidBrush(BackColor), e.Bounds);
  416. e.Graphics.DrawString(" " + Items[e.Index].ToString(), Font, new SolidBrush(ForeColor), e.Bounds.X, e.Bounds.Y + 2);
  417. }
  418. base.OnDrawItem(e);
  419. }
  420.  
  421. public Point[] Triangle(Point Location, Size Size) {
  422. Point[] ReturnPoints = new Point[4];
  423. ReturnPoints[0] = Location;
  424. ReturnPoints[1] = new Point(Location.X + Size.Width, Location.Y);
  425. ReturnPoints[2] = new Point(Location.X + Size.Width / 2, Location.Y + Size.Height);
  426. ReturnPoints[3] = Location;
  427.  
  428. return ReturnPoints;
  429. }
  430.  
  431. private void GhostComboBox_DropDownClosed(object sender, System.EventArgs e) {
  432. DropDownStyle = ComboBoxStyle.Simple;
  433. Application.DoEvents();
  434. DropDownStyle = ComboBoxStyle.DropDownList;
  435. }
  436.  
  437. private void GhostCombo_TextChanged(object sender, System.EventArgs e) {
  438. Invalidate();
  439. }
  440. }
  441.  
  442. public class Draw {
  443. public static void Gradient(Graphics g, Color c1, Color c2, int x, int y, int width, int height) {
  444. Rectangle R = new Rectangle(x, y, width, height);
  445. using (LinearGradientBrush T = new LinearGradientBrush(R, c1, c2, LinearGradientMode.Vertical)) {
  446. g.FillRectangle(T, R);
  447. }
  448. }
  449. public static void Blend(Graphics g, Color c1, Color c2, Color c3, float c, int d, int x, int y, int width, int height) {
  450. ColorBlend V = new ColorBlend(3);
  451. V.Colors = new Color[] { c1, c2, c3 };
  452. V.Positions = new float[] { 0F, c, 1F };
  453. Rectangle R = new Rectangle(x, y, width, height);
  454. using (LinearGradientBrush T = new LinearGradientBrush(R, c1, c1, (LinearGradientMode)d)) {
  455. T.InterpolationColors = V;
  456. g.FillRectangle(T, R);
  457. }
  458. }
  459. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement