Advertisement
Yassine_Abbani

Dark [Combo Box], [Custom Control]

May 22nd, 2018
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.81 KB | None | 0 0
  1. #region Derectives
  2. using System.Drawing;
  3. using System.Drawing.Drawing2D;
  4. using System.Windows.Forms;
  5. #endregion
  6. #region Copyright & Contact
  7. // Creator  : Cheat Eye
  8. // CEO      : Yassine Abbani
  9. // Facebook : https://www.facebook.com/YassineAbbani.user
  10. // Pastebin : https://pastebin.com/u/Yassine_Abbani
  11. // Youtube  : https://www.youtube.com/channel/UCqvOCRs3HWbPH4yuZuTx8mw
  12. // Version  : 1.0
  13. // Color    : Dark
  14. // Project  : Creator Eye UI
  15. #endregion
  16.  
  17. #region ComboBox
  18. class Ce_ComboBox : ComboBox
  19. {
  20.     #region "Properties"
  21.     #region Installing
  22.     private int X;
  23.     public Ce_ComboBox()
  24.         : base()
  25.     {
  26.         TextChanged += GhostCombo_TextChanged;
  27.         DropDownClosed += GhostComboBox_DropDownClosed;
  28.         SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true);
  29.         DrawMode = DrawMode.OwnerDrawFixed;
  30.         ItemHeight = 18;
  31.         // Items Panel  BackColor (20, 20, 20)
  32.         BackColor = Color.FromArgb(20, 20, 20);
  33.         DropDownStyle = ComboBoxStyle.DropDownList;
  34.     }
  35.     #endregion
  36.     #region Point Location
  37.     public Point[] Triangle(Point Location, Size Size)
  38.     {
  39.         Point[] ReturnPoints = new Point[4];
  40.         ReturnPoints[0] = Location;
  41.         ReturnPoints[1] = new Point(Location.X + Size.Width, Location.Y);
  42.         ReturnPoints[2] = new Point(Location.X + Size.Width / 2, Location.Y + Size.Height);
  43.         ReturnPoints[3] = Location;
  44.  
  45.         return ReturnPoints;
  46.     }
  47.     #endregion
  48.     #endregion
  49.     #region "EventArgs"
  50.     protected override void OnMouseMove(System.Windows.Forms.MouseEventArgs e)
  51.     {
  52.         base.OnMouseMove(e);
  53.         X = e.X;
  54.         Invalidate();
  55.     }
  56.     protected override void OnMouseLeave(System.EventArgs e)
  57.     {
  58.         base.OnMouseLeave(e);
  59.         X = -1;
  60.         Invalidate();
  61.     }
  62.     private void GhostComboBox_DropDownClosed(object sender, System.EventArgs e)
  63.     {
  64.         DropDownStyle = ComboBoxStyle.Simple;
  65.         Application.DoEvents();
  66.         DropDownStyle = ComboBoxStyle.DropDownList;
  67.     }
  68.     private void GhostCombo_TextChanged(object sender, System.EventArgs e)
  69.     {
  70.         Invalidate();
  71.     }
  72.     protected override void OnDrawItem(DrawItemEventArgs e)
  73.     {
  74.         if (e.Index < 0)
  75.             return;
  76.         Rectangle rect = new Rectangle();
  77.         rect.X = e.Bounds.X;
  78.         rect.Y = e.Bounds.Y;
  79.         rect.Width = e.Bounds.Width - 1;
  80.         rect.Height = e.Bounds.Height - 1;
  81.  
  82.         e.DrawBackground();
  83.         if ((int)e.State == 785 | (int)e.State == 17)
  84.         {
  85.             e.Graphics.FillRectangle(new SolidBrush(BackColor), e.Bounds);
  86.             Rectangle x2 = new Rectangle(e.Bounds.Location, new Size(e.Bounds.Width + 2, e.Bounds.Height));
  87.             Rectangle x3 = new Rectangle(x2.Location, new Size(x2.Width, (x2.Height / 2) - 1));
  88.             // Items Button  BackColor Color.FromArgb(20, 20, 20), Color.FromArgb(112, 128, 144)
  89.             LinearGradientBrush G1 = new LinearGradientBrush(new Point(x2.X, x2.Y), new Point(x2.X, x2.Y + x2.Height), Color.FromArgb(20, 20, 20), Color.FromArgb(112, 128, 144));
  90.             // Items Button Transparent BackColor Effect (15, Color.Blue)
  91.             HatchBrush H = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Color.FromArgb(15, Color.Blue), Color.Transparent);
  92.             e.Graphics.FillRectangle(G1, x2);
  93.             G1.Dispose();
  94.             // Items Button Top Color (25, Color.White)
  95.             e.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(25, Color.White)), x3);
  96.             e.Graphics.FillRectangle(H, x2);
  97.             G1.Dispose();
  98.             e.Graphics.DrawString(" " + Items[e.Index].ToString(), Font, Brushes.Black, e.Bounds.X, e.Bounds.Y + 1);
  99.         }
  100.         else
  101.         {
  102.             e.Graphics.FillRectangle(new SolidBrush(BackColor), e.Bounds);
  103.             // Itmes  Text Color
  104.             e.Graphics.DrawString(" " + Items[e.Index].ToString(), Font, Brushes.DimGray, e.Bounds.X, e.Bounds.Y + 1);
  105.  
  106.         }
  107.  
  108.         base.OnDrawItem(e);
  109.     }
  110.     #endregion
  111.     #region "Method"
  112.     protected override void OnPaint(PaintEventArgs e)
  113.     {
  114.         if (!(DropDownStyle == ComboBoxStyle.DropDownList))
  115.             DropDownStyle = ComboBoxStyle.DropDownList;
  116.         Bitmap B = new Bitmap(Width, Height);
  117.         Graphics G = Graphics.FromImage(B);
  118.  
  119.         G.Clear(Color.FromArgb(20, 20, 20));
  120.         LinearGradientBrush GradientBrush = new LinearGradientBrush(new Rectangle(0, 0, Width, Height / 5 * 2), Color.FromArgb(20, 0, 0, 0), Color.FromArgb(15, Color.White), 90f);
  121.         G.FillRectangle(GradientBrush, new Rectangle(0, 0, Width, Height / 5 * 2));
  122.         HatchBrush hatch = default(HatchBrush);
  123.         hatch = new HatchBrush(HatchStyle.DarkUpwardDiagonal, Color.FromArgb(20, Color.Black), Color.FromArgb(0, Color.Gray));
  124.         G.FillRectangle(hatch, 0, 0, Width, Height);
  125.  
  126.         int S1 = (int)G.MeasureString("Ce ComboBox", Font).Height;
  127.         if (SelectedIndex != -1)
  128.         {
  129.             G.DrawString(Items[SelectedIndex].ToString(), Font, new SolidBrush(Color.DimGray), 4, Height / 2 - S1 / 2);
  130.         }
  131.         else
  132.         {
  133.             if ((Items != null) & Items.Count > 0)
  134.             {
  135.                 // On Changed Text Color (Color.DimGray)
  136.                 G.DrawString(Items[0].ToString(), Font, new SolidBrush(Color.DimGray), 4, Height / 2 - S1 / 2);
  137.             }
  138.             else
  139.             {
  140.                 // Correct  Text Name "Ce ComboBox",  Color (Color.DimGray)
  141.                 G.DrawString("Ce ComboBox", Font, new SolidBrush(Color.DimGray), 4, Height / 2 - S1 / 2);
  142.             }
  143.         }
  144.  
  145.         if (MouseButtons == MouseButtons.None & X > Width - 25)
  146.         {
  147.             //G.FillRectangle(New SolidBrush(Color.FromArgb(7, Color.White)), Width - 25, 1, Width - 25, Height - 3)
  148.             //  ElseIf MouseButtons = Windows.Forms.MouseButtons.None And X < Width - 25 And X >= 0 Then
  149.             G.FillRectangle(new SolidBrush(Color.FromArgb(7, Color.White)), 2, 1, Width - 5, Height - 3);
  150.         }
  151.  
  152.         G.DrawRectangle(Pens.Black, 0, 0, Width - 1, Height - 1);
  153.         G.DrawRectangle(new Pen(Color.FromArgb(40, 40, 40)), 1, 1, Width - 3, Height - 3);
  154.         //G.DrawLine(New Pen(Color.FromArgb(40, 40, 40)), Width - 25, 1, Width - 25, Height - 3)
  155.         //G.DrawLine(Pens.Black, Width - 24, 0, Width - 24, Height)
  156.         // G.DrawLine(New Pen(Color.FromArgb(40, 40, 40)), Width - 23, 1, Width - 23, Height - 3)
  157.  
  158.         G.FillPolygon(Brushes.Black, Triangle(new Point(Width - 14, Height / 2), new Size(5, 3)));
  159.         G.FillPolygon(Brushes.White, Triangle(new Point(Width - 15, Height / 2 - 1), new Size(5, 3)));
  160.  
  161.         e.Graphics.DrawImage((Bitmap)B.Clone(), 0, 0);
  162.         G.Dispose();
  163.         B.Dispose();
  164.     }
  165.     #endregion
  166. }
  167. #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement