Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Electron Theme
- public class ETheme : Control
- {
- private int _TitleHeight = 25;
- public int TitleHeight
- {
- get
- {
- return _TitleHeight;
- }
- set
- {
- if (value > Height)
- {
- value = Height;
- }
- if (value < 2)
- {
- Height = 1;
- }
- _TitleHeight = value;
- Invalidate();
- }
- }
- private HorizontalAlignment _TitleAlign = (HorizontalAlignment)2;
- public HorizontalAlignment TitleAlign
- {
- get
- {
- return _TitleAlign;
- }
- set
- {
- _TitleAlign = value;
- Invalidate();
- }
- }
- protected override void OnHandleCreated(System.EventArgs e)
- {
- Dock = (DockStyle)5;
- if (Parent is Form)
- {
- ((Form)Parent).FormBorderStyle = 0;
- }
- base.OnHandleCreated(e);
- }
- protected override void OnMouseDown(System.Windows.Forms.MouseEventArgs e)
- {
- if (new Rectangle(Parent.Location.X, Parent.Location.Y, Width - 1, _TitleHeight - 1).IntersectsWith(new Rectangle(MousePosition.X, MousePosition.Y, 1, 1)))
- {
- Capture = false;
- var M = Message.Create(Parent.Handle, 161, new IntPtr(2), new IntPtr(0));
- DefWndProc(ref M);
- }
- base.OnMouseDown(e);
- }
- private Color C1 = Color.FromArgb(0, 70, 114);
- private Color C2 = Color.FromArgb(0, 47, 78);
- private Color C3 = Color.FromArgb(0, 34, 57);
- private Color C4 = Color.FromArgb(0, 30, 50);
- protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs pevent)
- {
- }
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- using (Bitmap B = new Bitmap(Width, Height))
- {
- using (var G = Graphics.FromImage(B))
- {
- G.Clear(C3);
- Draw.Blend(G, C2, C3, C1, 0.5F, 1, 0, 0, Width, _TitleHeight);
- G.FillRectangle(new SolidBrush(Color.FromArgb(15, 255, 255, 255)), 1, 1, Width - 2, System.Convert.ToInt32(_TitleHeight / 2.0) - 2);
- G.DrawRectangle(new Pen(Color.FromArgb(35, 255, 255, 255)), 1, 1, Width - 3, _TitleHeight - 2);
- var S = G.MeasureString(Text, Font);
- var O = 6;
- if ((int)_TitleAlign == 2)
- {
- O = Width / 2 - (int)S.Width / 2;
- }
- if ((int)_TitleAlign == 1)
- {
- O = Width - (int)S.Width - 14;
- }
- var V = System.Convert.ToInt32(_TitleHeight / 2.0 - (S.Height + 4) / 2);
- Draw.Gradient(G, C3, C2, O, V, (int)S.Width + 8, (int)S.Height + 4);
- G.DrawRectangle(new Pen(C3), O, V, S.Width + 7, S.Height + 3);
- Rectangle R = new Rectangle(O + 4, System.Convert.ToInt32(_TitleHeight / 2 - S.Height / 2), (int)S.Width, (int)S.Height);
- using (LinearGradientBrush T = new LinearGradientBrush(R, C1, C2, LinearGradientMode.Vertical))
- {
- G.DrawString(Text, Font, T, R);
- }
- G.DrawRectangle(new Pen(C1), 1, _TitleHeight + 1, Width - 3, Height - _TitleHeight - 3);
- G.DrawLine(new Pen(C4), 0, _TitleHeight, Width, _TitleHeight);
- G.DrawRectangle(new Pen(C4), 0, 0, Width - 1, Height - 1);
- e.Graphics.DrawImage((Image)B.Clone(), 0, 0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement