Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region NameSpaces
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Drawing.Drawing2D;
- using System.ComponentModel;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Imaging;
- using System.Drawing.Text;
- using System.Reflection;
- using System.Runtime.CompilerServices;
- using System.Runtime.InteropServices;
- using System.Windows.Forms;
- using Microsoft.VisualBasic;
- using System.Windows;
- using static HelperMethods;
- #endregion
- /// <summary>
- /// Youtube Theme
- /// Author : THE LORD
- /// Release Date : Monday, June 19, 2017
- /// Updated : Wednesday, June 21, 2017
- /// HF Account : https://hackforums.net/member.php?action=profile&uid=3304362
- /// PM Me for any bug.
- /// </summary>
- #region Helper
- public sealed class HelperMethods
- {
- #region MouseStates
- /// <summary>
- /// The helper enumerator to get mouse states.
- /// </summary>
- public enum MouseMode : byte
- {
- Normal,
- Hovered,
- Pushed,
- Disabled
- }
- #endregion
- #region Draw Methods
- /// <summary>
- /// The Method to draw the image from encoded base64 string.
- /// </summary>
- /// <param name="G">The Graphics to draw the image.</param>
- /// <param name="Base64Image">The Encoded base64 image.</param>
- /// <param name="Rect">The Rectangle area for the image.</param>
- public void DrawImageFromBase64(Graphics G, string Base64Image, Rectangle Rect)
- {
- Image IM = null;
- using (System.IO.MemoryStream ms = new System.IO.MemoryStream(Convert.FromBase64String(Base64Image)))
- {
- IM = Image.FromStream(ms);
- ms.Close();
- }
- G.DrawImage(IM, Rect);
- }
- /// <summary>
- /// The Method to fill rounded rectangle.
- /// </summary>
- /// <param name="G">The Graphics to draw the image.</param>
- /// <param name="C">The Color to the rectangle area.</param>
- /// <param name="Rect">The Rectangle area to be filled.</param>
- /// <param name="Curve">The Rounding border radius.</param>
- /// <param name="TopLeft">Wether the top left of rectangle be round or not.</param>
- /// <param name="TopRight">Wether the top right of rectangle be round or not.</param>
- /// <param name="BottomLeft">Wether the bottom left of rectangle be round or not.</param>
- /// <param name="BottomRight">Wether the bottom right of rectangle be round or not.</param>
- public void FillRoundedPath(Graphics G, Color C, Rectangle Rect, int Curve, bool TopLeft = true,
- bool TopRight = true, bool BottomLeft = true, bool BottomRight = true)
- {
- G.FillPath(new SolidBrush(C), RoundRec(Rect, Curve, TopLeft, TopRight, BottomLeft, BottomRight));
- }
- /// <summary>
- /// The Method to fill the rounded rectangle.
- /// </summary>
- /// <param name="G">The Graphics to fill the rectangle.</param>
- /// <param name="B">The brush to the rectangle area.</param>
- /// <param name="Rect">The Rectangle area to be filled.</param>
- /// <param name="Curve">The Rounding border radius.</param>
- /// <param name="TopLeft">Wether the top left of rectangle be round or not.</param>
- /// <param name="TopRight">Wether the top right of rectangle be round or not.</param>
- /// <param name="BottomLeft">Wether the bottom left of rectangle be round or not.</param>
- /// <param name="BottomRight">Wether the bottom right of rectangle be round or not.</param>
- public void FillRoundedPath(Graphics G, Brush B, Rectangle Rect, int Curve, bool TopLeft = true,
- bool TopRight = true, bool BottomLeft = true, bool BottomRight = true)
- {
- G.FillPath(B, RoundRec(Rect, Curve, TopLeft, TopRight, BottomLeft, BottomRight));
- }
- /// <summary>
- /// The Method to fill the rectangle the base color and surrounding with another color(Rectangle with shadow).
- /// </summary>
- /// <param name="G">The Graphics to fill the rectangle.</param>
- /// <param name="CenterColor">The Center color of the rectangle area.</param>
- /// <param name="SurroundColor">The Inner Surround color of the rectangle area.</param>
- /// <param name="P">The Point of the surrounding color.</param>
- /// <param name="Rect">The Rectangle area to be filled.</param>
- /// <param name="Curve">The Rounding border radius.</param>
- /// <param name="TopLeft">Wether the top left of rectangle be round or not.</param>
- /// <param name="TopRight">Wether the top right of rectangle be round or not.</param>
- /// <param name="BottomLeft">Wether the bottom left of rectangle be round or not.</param>
- /// <param name="BottomRight">Wether the bottom right of rectangle be round or not.</param>
- public void FillWithInnerRectangle(Graphics G, Color CenterColor, Color SurroundColor, Point P, Rectangle Rect,
- int Curve, bool TopLeft = true, bool TopRight = true, bool BottomLeft = true, bool BottomRight = true)
- {
- using (
- PathGradientBrush PGB =
- new PathGradientBrush(RoundRec(Rect, Curve, TopLeft, TopRight, BottomLeft, BottomRight)))
- {
- PGB.CenterColor = CenterColor;
- PGB.SurroundColors = new Color[] { SurroundColor };
- PGB.FocusScales = P;
- GraphicsPath GP = new GraphicsPath { FillMode = FillMode.Winding };
- GP.AddRectangle(Rect);
- G.FillPath(PGB, GP);
- GP.Dispose();
- }
- }
- /// <summary>
- /// The Method to fill the circle the base color and surrounding with another color(Rectangle with shadow).
- /// </summary>
- /// <param name="G">The Graphics to fill the circle.</param>
- /// <param name="CenterColor">The Center color of the rectangle area.</param>
- /// <param name="SurroundColor">The Inner Surround color of the rectangle area.</param>
- /// <param name="P">The Point of the surrounding color.</param>
- /// <param name="Rect">The circle area to be filled.</param>
- public void FillWithInnerEllipse(Graphics G, Color CenterColor, Color SurroundColor, Point P, Rectangle Rect)
- {
- GraphicsPath GP = new GraphicsPath { FillMode = FillMode.Winding };
- GP.AddEllipse(Rect);
- using (PathGradientBrush PGB = new PathGradientBrush(GP))
- {
- PGB.CenterColor = CenterColor;
- PGB.SurroundColors = new Color[] { SurroundColor };
- PGB.FocusScales = P;
- G.FillPath(PGB, GP);
- GP.Dispose();
- }
- }
- /// <summary>
- /// The Method to fill the rounded rectangle the base color and surrounding with another color(Rectangle with shadow).
- /// </summary>
- /// <param name="G">The Graphics to fill rounded the rectangle.</param>
- /// <param name="CenterColor">The Center color of the rectangle area.</param>
- /// <param name="SurroundColor">The Inner Surround color of the rectangle area.</param>
- /// <param name="P">The Point of the surrounding color.</param>
- /// <param name="Rect">The Rectangle area to be filled.</param>
- /// <param name="Curve">The Rounding border radius.</param>
- /// <param name="TopLeft">Wether the top left of rectangle be round or not.</param>
- /// <param name="TopRight">Wether the top right of rectangle be round or not.</param>
- /// <param name="BottomLeft">Wether the bottom left of rectangle be round or not.</param>
- /// <param name="BottomRight">Wether the bottom right of rectangle be round or not.</param>
- public void FillWithInnerRoundedPath(Graphics G, Color CenterColor, Color SurroundColor, Point P, Rectangle Rect,
- int Curve, bool TopLeft = true, bool TopRight = true, bool BottomLeft = true, bool BottomRight = true)
- {
- using (
- PathGradientBrush PGB =
- new PathGradientBrush(RoundRec(Rect, Curve, TopLeft, TopRight, BottomLeft, BottomRight)))
- {
- PGB.CenterColor = CenterColor;
- PGB.SurroundColors = new Color[] { SurroundColor };
- PGB.FocusScales = P;
- G.FillPath(PGB, RoundRec(Rect, Curve, TopLeft, TopRight, BottomLeft, BottomRight));
- }
- }
- /// <summary>
- /// The Method to draw the rounded rectangle area.
- /// </summary>
- /// <param name="G">The Graphics to draw rounded the rectangle.</param>
- /// <param name="C">Border Color</param>
- /// <param name="Size">Border thickness</param>
- /// <param name="Rect">The Rectangle area to be drawn.</param>
- /// <param name="Curve">The Rounding border radius.</param>
- /// <param name="TopLeft">Wether the top left of rectangle be round or not.</param>
- /// <param name="TopRight">Wether the top right of rectangle be round or not.</param>
- /// <param name="BottomLeft">Wether the bottom left of rectangle be round or not.</param>
- /// <param name="BottomRight">Wether the bottom right of rectangle be round or not.</param>
- public void DrawRoundedPath(Graphics G, Color C, float Size, Rectangle Rect, int Curve, bool TopLeft = true,
- bool TopRight = true, bool BottomLeft = true, bool BottomRight = true)
- {
- G.DrawPath(new Pen(C, Size), RoundRec(Rect, Curve, TopLeft, TopRight, BottomLeft, BottomRight));
- }
- /// <summary>
- /// The method to draw the triangle.
- /// </summary>
- /// <param name="G">The Graphics to draw triangle.</param>
- /// <param name="C">The Triangle Color.</param>
- /// <param name="Size">The Triangle thickness</param>
- /// <param name="P1">Point 1</param>
- /// <param name="P2">Point 2</param>
- /// <param name="P3">Point 3</param>
- /// <param name="P4">Point 4</param>
- /// <param name="P5">Point 5</param>
- /// <param name="P6">Point 6</param>
- public void DrawTriangle(Graphics G, Color C, int Size, Point P1_0, Point P1_1, Point P2_0, Point P2_1, Point P3_0,
- Point P3_1)
- {
- G.DrawLine(new Pen(C, Size), P1_0, P1_1);
- G.DrawLine(new Pen(C, Size), P2_0, P2_1);
- G.DrawLine(new Pen(C, Size), P3_0, P3_1);
- }
- /// <summary>
- /// The Method to fill the rectangle with border.
- /// </summary>
- /// <param name="G">The Graphics to fill the the rectangle.</param>
- /// <param name="Rect">The Rectangle to fill.</param>
- /// <param name="RectColor">The Rectangle color.</param>
- /// <param name="StrokeColor">The Stroke(Border) color.</param>
- /// <param name="StrokeSize">The Stroke thickness.</param>
- public void FillStrokedRectangle(Graphics G, Rectangle Rect, Color RectColor, Color Stroke, int StrokeSize = 1)
- {
- using (SolidBrush B = new SolidBrush(RectColor))
- using (Pen S = new Pen(Stroke, StrokeSize))
- {
- G.FillRectangle(B, Rect);
- G.DrawRectangle(S, Rect);
- }
- }
- /// <summary>
- /// The Method to fill rounded rectangle with border.
- /// </summary>
- /// <param name="G">The Graphics to fill rounded the rectangle.</param>
- /// <param name="Rect">The Rectangle to fill.</param>
- /// <param name="RectColor">The Rectangle color.</param>
- /// <param name="StrokeColor">The Stroke(Border) color.</param>
- /// <param name="StrokeSize">The Stroke thickness.</param>
- /// <param name="Curve">The Rounding border radius.</param>
- /// <param name="TopLeft">Wether the top left of rectangle be round or not.</param>
- /// <param name="TopRight">Wether the top right of rectangle be round or not.</param>
- /// <param name="BottomLeft">Wether the bottom left of rectangle be round or not.</param>
- /// <param name="BottomRight">Wether the bottom right of rectangle be round or not.</param>
- public void FillRoundedStrokedRectangle(Graphics G, Rectangle Rect, Color RectColor, Color Stroke,
- int StrokeSize = 1, int curve = 1, bool TopLeft = true, bool TopRight = true, bool BottomLeft = true,
- bool BottomRight = true)
- {
- using (SolidBrush B = new SolidBrush(RectColor))
- {
- using (Pen S = new Pen(Stroke, StrokeSize))
- {
- FillRoundedPath(G, B, Rect, curve, TopLeft, TopRight, BottomLeft, BottomRight);
- DrawRoundedPath(G, Stroke, StrokeSize, Rect, curve, TopLeft, TopRight, BottomLeft, BottomRight);
- }
- }
- }
- /// <summary>
- /// The Method to draw the image with custom color.
- /// </summary>
- /// <param name="G"> The Graphic to draw the image.</param>
- /// <param name="R"> The Rectangle area of image.</param>
- /// <param name="_Image"> The image that the custom color applies on it.</param>
- /// <param name="C">The Color that be applied to the image.</param>
- /// <remarks></remarks>
- public void DrawImageWithColor(Graphics G, Rectangle R, Image _Image, Color C)
- {
- float[][] ptsArray = new float[][]
- {
- new float[] {Convert.ToSingle(C.R / 255.0), 0f, 0f, 0f, 0f},
- new float[] {0f, Convert.ToSingle(C.G / 255.0), 0f, 0f, 0f},
- new float[] {0f, 0f, Convert.ToSingle(C.B / 255.0), 0f, 0f},
- new float[] {0f, 0f, 0f, Convert.ToSingle(C.A / 255.0), 0f},
- new float[]
- {
- Convert.ToSingle( C.R/255.0),
- Convert.ToSingle( C.G/255.0),
- Convert.ToSingle( C.B/255.0), 0f,
- Convert.ToSingle( C.A/255.0)
- }
- };
- ImageAttributes imgAttribs = new ImageAttributes();
- imgAttribs.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Default);
- G.DrawImage(_Image, R, 0, 0, _Image.Width, _Image.Height, GraphicsUnit.Pixel, imgAttribs);
- _Image.Dispose();
- }
- /// <summary>
- /// The Method to draw the image with custom color.
- /// </summary>
- /// <param name="G"> The Graphic to draw the image.</param>
- /// <param name="R"> The Rectangle area of image.</param>
- /// <param name="_Image"> The Encoded base64 image that the custom color applies on it.</param>
- /// <param name="C">The Color that be applied to the image.</param>
- /// <remarks></remarks>
- public void DrawImageWithColor(Graphics G, Rectangle R, string _Image, Color C)
- {
- Image IM = ImageFromBase64(_Image);
- float[][] ptsArray = new float[][]
- {
- new float[] {Convert.ToSingle(C.R / 255.0), 0f, 0f, 0f, 0f},
- new float[] {0f, Convert.ToSingle(C.G / 255.0), 0f, 0f, 0f},
- new float[] {0f, 0f, Convert.ToSingle(C.B / 255.0), 0f, 0f},
- new float[] {0f, 0f, 0f, Convert.ToSingle(C.A / 255.0), 0f},
- new float[]
- {
- Convert.ToSingle( C.R/255.0),
- Convert.ToSingle( C.G/255.0),
- Convert.ToSingle( C.B/255.0), 0f,
- Convert.ToSingle( C.A/255.0)
- }
- };
- ImageAttributes imgAttribs = new ImageAttributes();
- imgAttribs.SetColorMatrix(new ColorMatrix(ptsArray), ColorMatrixFlag.Default, ColorAdjustType.Default);
- G.DrawImage(IM, R, 0, 0, IM.Width, IM.Height, GraphicsUnit.Pixel, imgAttribs);
- }
- #endregion
- #region Shapes
- /// <summary>
- /// The Triangle that joins 3 points to the triangle shape.
- /// </summary>
- /// <param name="P1">Point 1.</param>
- /// <param name="P2">Point 2.</param>
- /// <param name="P3">Point 3.</param>
- /// <returns>The Trangle shape based on given points.</returns>
- public Point[] Triangle(Point P1, Point P2, Point P3)
- {
- return new Point[] {
- P1,
- P2,
- P3
- };
- }
- #endregion
- #region Brushes
- /// <summary>
- /// The Brush with two colors one center another surounding the center based on the given rectangle area.
- /// </summary>
- /// <param name="CenterColor">The Center color of the rectangle.</param>
- /// <param name="SurroundColor">The Surrounding color of the rectangle.</param>
- /// <param name="P">The Point of surrounding.</param>
- /// <param name="Rect">The Rectangle of the brush.</param>
- /// <returns>The Brush with two colors one center another surounding the center.</returns>
- public static PathGradientBrush GlowBrush(Color CenterColor, Color SurroundColor, Point P, Rectangle Rect)
- {
- GraphicsPath GP = new GraphicsPath { FillMode = FillMode.Winding };
- GP.AddRectangle(Rect);
- return new PathGradientBrush(GP)
- {
- CenterColor = CenterColor,
- SurroundColors = new Color[] { SurroundColor },
- FocusScales = P
- };
- }
- /// <summary>
- /// The Brush from RGBA color.
- /// </summary>
- /// <param name="R">Red.</param>
- /// <param name="G">Green.</param>
- /// <param name="B">Blue.</param>
- /// <param name="A">Alpha.</param>
- /// <returns>The Brush from given RGBA color.</returns>
- public SolidBrush SolidBrushRGBColor(int R, int G, int B, int A = 0)
- {
- return new SolidBrush(Color.FromArgb(A, R, G, B));
- }
- /// <summary>
- /// The Brush from HEX color.
- /// </summary>
- /// <param name="C_WithoutHash">HEX Color without hash.</param>
- /// <returns>The Brush from given HEX color.</returns>
- public SolidBrush SolidBrushHTMlColor(string C_WithoutHash)
- {
- return new SolidBrush(GetHTMLColor(C_WithoutHash));
- }
- #endregion
- #region Pens
- /// <summary>
- /// The Pen from RGBA color.
- /// </summary>
- /// <param name="R">Red.</param>
- /// <param name="G">Green.</param>
- /// <param name="B">Blue.</param>
- /// <param name="A">Alpha.</param>
- /// <returns>The Pen from given RGBA color.</returns>
- public Pen PenRGBColor(int R, int G, int B, int A, float Size)
- {
- return new Pen(Color.FromArgb(A, R, G, B), Size);
- }
- /// <summary>
- /// The Pen from HEX color.
- /// </summary>
- /// <param name="C_WithoutHash">HEX Color without hash.</param>
- /// <param name="Size">The Size of the pen.</param>
- /// <returns></returns>
- public Pen PenHTMlColor(string C_WithoutHash, float Size = 1)
- {
- return new Pen(GetHTMLColor(C_WithoutHash), Size);
- }
- #endregion
- #region Colors
- /// <summary>
- ///
- /// </summary>
- /// <param name="C_WithoutHash"></param>
- /// <returns></returns>
- public Color GetHTMLColor(string C_WithoutHash)
- {
- return ColorTranslator.FromHtml("#" + C_WithoutHash);
- }
- /// <summary>
- /// The Color from HEX by alpha property.
- /// </summary>
- /// <param name="alpha">Alpha.</param>
- /// <param name="C_WithoutHash">HEX Color without hash.</param>
- /// <returns>The Color from HEX with given ammount of transparency</returns>
- public Color GetAlphaHTMLColor(int alpha, string C_WithoutHash)
- {
- return Color.FromArgb(alpha, ColorTranslator.FromHtml("#" + C_WithoutHash));
- }
- #endregion
- #region Methods
- /// <summary>
- /// The String format to provide the alignment.
- /// </summary>
- /// <param name="Horizontal">Horizontal alignment.</param>
- /// <param name="Vertical">Horizontal alignment. alignment.</param>
- /// <returns>The String format.</returns>
- public StringFormat SetPosition(StringAlignment Horizontal = StringAlignment.Center, StringAlignment Vertical = StringAlignment.Center)
- {
- return new StringFormat
- {
- Alignment = Horizontal,
- LineAlignment = Vertical
- };
- }
- /// <summary>
- /// The Matrix array of single from color.
- /// </summary>
- /// <param name="C">The Color.</param>
- /// <returns>The Matrix array of single from the given color</returns>
- public float[][] ColorToMatrix(Color C)
- {
- return new float[][] {
- new float[] {
- Convert.ToSingle(C.R / 255),
- 0,
- 0,
- 0,
- 0
- },
- new float[] {
- 0,
- Convert.ToSingle(C.G / 255),
- 0,
- 0,
- 0
- },
- new float[] {
- 0,
- 0,
- Convert.ToSingle(C.B / 255),
- 0,
- 0
- },
- new float[] {
- 0,
- 0,
- 0,
- Convert.ToSingle(C.A / 255),
- 0
- },
- new float[] {
- Convert.ToSingle(C.R / 255),
- Convert.ToSingle(C.G / 255),
- Convert.ToSingle(C.B / 255),
- 0f,
- Convert.ToSingle(C.A / 255)
- }
- };
- }
- /// <summary>
- /// The Image from encoded base64 image.
- /// </summary>
- /// <param name="Base64Image">The Encoded base64 image</param>
- /// <returns>The Image from encoded base64.</returns>
- public Image ImageFromBase64(string Base64Image)
- {
- using (System.IO.MemoryStream ms = new System.IO.MemoryStream(Convert.FromBase64String(Base64Image)))
- {
- return Image.FromStream(ms);
- }
- }
- #endregion
- #region Round Border
- /// <summary>
- /// Credits : AeonHack
- /// </summary>
- public GraphicsPath RoundRec(Rectangle r, int Curve, bool TopLeft = true, bool TopRight = true,
- bool BottomLeft = true, bool BottomRight = true)
- {
- GraphicsPath CreateRoundPath = new GraphicsPath(FillMode.Winding);
- if (TopLeft)
- {
- CreateRoundPath.AddArc(r.X, r.Y, Curve, Curve, 180f, 90f);
- }
- else
- {
- CreateRoundPath.AddLine(r.X, r.Y, r.X, r.Y);
- }
- if (TopRight)
- {
- CreateRoundPath.AddArc(r.Right - Curve, r.Y, Curve, Curve, 270f, 90f);
- }
- else
- {
- CreateRoundPath.AddLine(r.Right - r.Width, r.Y, r.Width, r.Y);
- }
- if (BottomRight)
- {
- CreateRoundPath.AddArc(r.Right - Curve, r.Bottom - Curve, Curve, Curve, 0f, 90f);
- }
- else
- {
- CreateRoundPath.AddLine(r.Right, r.Bottom, r.Right, r.Bottom);
- }
- if (BottomLeft)
- {
- CreateRoundPath.AddArc(r.X, (r.Bottom + r.Y) - Curve, Curve, Curve, 90f, 90f);
- }
- else
- {
- CreateRoundPath.AddLine(r.X, r.Bottom, r.X, r.Bottom);
- }
- CreateRoundPath.CloseFigure();
- return CreateRoundPath;
- }
- #endregion
- }
- #endregion
- #region TabControl
- public class YoutubeTabControl : TabControl
- {
- #region Declarations
- private static readonly HelperMethods H = new HelperMethods();
- private Rectangle R;
- private Point _LocatedPostion;
- private Point _ImageLocation;
- private Point _TextLocation;
- private Point _HeaderTextLocation;
- #endregion
- #region Constructors
- public YoutubeTabControl()
- {
- SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor, true);
- DoubleBuffered = true;
- UpdateStyles();
- SizeMode = TabSizeMode.Fixed;
- Dock = DockStyle.None;
- ItemSize = new Size(38, 180);
- Alignment = TabAlignment.Left;
- Font = new Font("Myriad Pro", 9);
- _LocatedPostion = new Point(-1, -1);
- _ImageLocation = new Point(30, 13);
- _TextLocation = new Point(50, 2);
- _HeaderTextLocation = new Point(16, 5);
- }
- #endregion
- #region Events
- protected override void OnCreateControl()
- {
- foreach (TabPage Tab in TabPages)
- {
- Tab.BackColor = Colors.LightSilver;
- Invalidate();
- }
- base.OnCreateControl();
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- if (DesignMode)
- return;
- _LocatedPostion = e.Location;
- Cursor = Cursors.Hand;
- Invalidate();
- base.OnMouseMove(e);
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- _LocatedPostion = new Point(-1, -1);
- Cursor = Cursors.Default;
- Invalidate();
- base.OnMouseLeave(e);
- }
- #endregion
- #region Properties
- [Category("Custom"), Description("Gets or sets the tab pages image location.")]
- public Point ImageLocation
- {
- get { return _ImageLocation; }
- set
- {
- _ImageLocation = value;
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the tab pages text location.")]
- public Point TextLocation
- {
- get { return _TextLocation; }
- set
- {
- _TextLocation = value;
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the tab pages header text location.")]
- public Point HeaderTextLocation
- {
- get { return _HeaderTextLocation; }
- set
- {
- _HeaderTextLocation = value;
- Invalidate();
- }
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- G.InterpolationMode = InterpolationMode.HighQualityBicubic;
- G.FillRectangle(Brushes.White, new Rectangle(0, 0, ItemSize.Height, Height));
- G.FillRectangle(Brushes.LightSilver, new Rectangle(ItemSize.Height, 0, Width, Height));
- using (StringFormat SF = new StringFormat { LineAlignment = StringAlignment.Center })
- {
- for (int i = 0; i <= TabCount - 1; i++)
- {
- R = GetTabRect(i);
- if (TabPages[i].Tag != null)
- {
- using (Font F = new Font(Font.Name, 9, FontStyle.Bold))
- {
- G.DrawString(TabPages[i].Text.ToUpper(), F, Brushes.Red, new Rectangle(R.X + HeaderTextLocation.X, R.Y + HeaderTextLocation.Y, R.Width - 2, R.Height), SF);
- }
- }
- else if (i == SelectedIndex)
- {
- G.FillRectangle(Brushes.Red, new Rectangle(R.X - 2, R.Y + 2, R.Width - 1, R.Height - 2));
- G.DrawString(TabPages[i].Text, Font, Brushes.White, new Rectangle(R.X + TextLocation.X, R.Y + TextLocation.Y, R.Width - 2, R.Height), SF);
- }
- else
- {
- if (R.Contains(_LocatedPostion))
- {
- G.FillRectangle(Brushes.Gray, new Rectangle(R.X - 2, R.Y + 2, R.Width - 1, R.Height - 2));
- G.DrawString(TabPages[i].Text, Font, Brushes.White, new Rectangle(R.X + TextLocation.X, R.Y + TextLocation.Y, R.Width - 2, R.Height), SF);
- }
- else
- {
- G.DrawString(TabPages[i].Text, Font, Brushes.Gray, new Rectangle(R.X + TextLocation.X, R.Y + TextLocation.Y, R.Width - 2, R.Height), SF);
- }
- }
- if ((ImageList != null) && ImageList.Images[i] != null && TabPages[i].Tag == null)
- {
- H.DrawImageWithColor(G, new Rectangle(R.X + ImageLocation.X, R.Y + ImageLocation.Y, 13, 13), ImageList.Images[i], i == SelectedIndex || R.Contains(_LocatedPostion) ? Colors.White : Colors.Gray);
- }
- }
- }
- }
- #endregion
- }
- public class YoutubeHorizontalTabControl : TabControl
- {
- #region Declarations
- private static readonly HelperMethods H = new HelperMethods();
- private Point _LocatedPostion;
- private Rectangle R;
- #endregion
- #region Constructors
- public YoutubeHorizontalTabControl()
- {
- SetStyle(ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor, true);
- DoubleBuffered = true;
- UpdateStyles();
- SizeMode = TabSizeMode.Fixed;
- Dock = DockStyle.None;
- ItemSize = new Size(90, 48);
- Alignment = TabAlignment.Top;
- Font = new Font("Myriad Pro", 9);
- _LocatedPostion = new Point(-1, -1);
- }
- #endregion
- #region Events
- protected override void OnCreateControl()
- {
- foreach (TabPage Tab in TabPages)
- {
- Tab.BackColor = Colors.White;
- Invalidate();
- }
- base.OnCreateControl();
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- if (DesignMode)
- return;
- _LocatedPostion = e.Location;
- Cursor = Cursors.Hand;
- Invalidate();
- base.OnMouseMove(e);
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- _LocatedPostion = new Point(-1, -1);
- Cursor = Cursors.Default;
- Invalidate();
- base.OnMouseLeave(e);
- }
- #endregion
- #region Properties
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- G.InterpolationMode = InterpolationMode.HighQualityBilinear;
- G.CompositingQuality = CompositingQuality.HighQuality;
- G.FillRectangle(Brushes.White, new Rectangle(0, 0, Width, ItemSize.Height));
- G.FillRectangle(Brushes.White, new Rectangle(0, ItemSize.Height + 3, Width, Height));
- using (StringFormat SF = new StringFormat { LineAlignment = StringAlignment.Center })
- {
- for (int i = 0; i <= TabCount - 1; i++)
- {
- R = GetTabRect(i);
- if (i == SelectedIndex)
- {
- G.FillRectangle(Brushes.Red, new Rectangle(R.X - 2, R.Height - 4, R.Width - 1, 4));
- G.DrawString(TabPages[i].Text, Font, Brushes.DarkGray, R, H.SetPosition());
- }
- else
- {
- if (R.Contains(_LocatedPostion))
- {
- G.DrawString(TabPages[i].Text, Font, Brushes.DarkGray, R, H.SetPosition());
- }
- else
- {
- G.DrawString(TabPages[i].Text, Font, Brushes.Gray, R, H.SetPosition());
- }
- }
- }
- }
- }
- #endregion
- }
- #endregion
- #region Button
- public class YoutubeButton : Control
- {
- #region Declarations
- private static readonly HelperMethods H = new HelperMethods();
- private MouseMode State;
- private iStyle _Style;
- private int _BorderRadius;
- #endregion
- #region Constructors
- public YoutubeButton()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
- DoubleBuffered = true;
- UpdateStyles();
- BackColor = Color.Transparent;
- Font = new Font("Segoe UI", 10);
- _BorderRadius = 0;
- _Style = iStyle.Light;
- State = MouseMode.Normal;
- }
- #endregion
- #region Events
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.OnMouseDown(e);
- State = MouseMode.Pushed;
- Cursor = Cursors.Hand;
- Invalidate();
- }
- protected override void OnMouseHover(EventArgs e)
- {
- base.OnMouseHover(e);
- State = MouseMode.Hovered;
- Cursor = Cursors.Hand;
- Invalidate();
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- base.OnMouseLeave(e);
- State = MouseMode.Normal;
- Cursor = Cursors.Default;
- Invalidate();
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- base.OnMouseUp(e);
- State = MouseMode.Hovered;
- Cursor = Cursors.Hand;
- Invalidate();
- }
- #endregion
- #region Properties
- [Category("Custom"), Description("Gets or sets the style for the control.")]
- public iStyle Style
- {
- get { return _Style; }
- set
- {
- _Style = value;
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the rounded corner degree of the control.")]
- public int BorderRadius
- {
- get { return _BorderRadius; }
- set
- {
- _BorderRadius = value;
- Invalidate();
- }
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- Rectangle Rect = new Rectangle(0, 0, Width - 1, Height - 1);
- G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- GraphicsPath GP = new GraphicsPath();
- if (BorderRadius > 1)
- {
- G.SmoothingMode = SmoothingMode.AntiAlias;
- GP = H.RoundRec(Rect, BorderRadius);
- }
- else
- {
- GP.AddRectangle(Rect);
- }
- switch (State)
- {
- case MouseMode.Normal:
- G.FillPath(Style == iStyle.Light ? Brushes.LightSilver : Brushes.Blue, GP);
- G.DrawPath(Style == iStyle.Light ? Pens.Silver : Pens.LighterBlue, GP);
- G.DrawString(Text, Font, Style == iStyle.Light ? Brushes.Gray : Brushes.White, Rect, H.SetPosition());
- break;
- case MouseMode.Hovered:
- G.FillPath(Style == iStyle.Light ? Brushes.Silver : Brushes.LighterBlue, GP);
- G.DrawPath(Style == iStyle.Light ? Pens.Silver : Pens.Blue, GP);
- G.DrawString(Text, Font, Style == iStyle.Light ? Brushes.Gray : Brushes.White, Rect, H.SetPosition());
- break;
- case MouseMode.Pushed:
- G.FillPath(Style == iStyle.Light ? Brushes.LightGray : Brushes.DarkBlue, GP);
- G.DrawPath(Style == iStyle.Light ? Pens.Silver : Pens.DarkBlue, GP);
- G.DrawString(Text, Font, Style == iStyle.Light ? Brushes.Gray : Brushes.White, Rect, H.SetPosition());
- break;
- }
- }
- #endregion
- #region Enumerators
- public enum iStyle
- {
- Light,
- Blue
- }
- #endregion
- }
- #endregion
- #region ButtonX
- public class YoutubeButtonX : Control
- {
- #region Declarations
- private static readonly HelperMethods H = new HelperMethods();
- private string _LeftText;
- private string _RightText;
- private Rectangle RedPart;
- private Rectangle LightPart;
- private MouseMode State;
- private iStyle _Style;
- #endregion
- #region Constructors
- public YoutubeButtonX()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
- DoubleBuffered = true;
- UpdateStyles();
- BackColor = Color.Transparent;
- Font = new Font("Segoe UI", 10);
- _Style = iStyle.Red;
- State = MouseMode.Normal;
- _LeftText = "12,961,386";
- _RightText = "Subscribe";
- }
- #endregion
- #region Events
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.OnMouseDown(e);
- State = MouseMode.Pushed;
- Cursor = Cursors.Hand;
- Invalidate();
- }
- protected override void OnMouseHover(EventArgs e)
- {
- base.OnMouseHover(e);
- State = MouseMode.Hovered;
- Cursor = Cursors.Hand;
- Invalidate();
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- base.OnMouseLeave(e);
- State = MouseMode.Normal;
- Cursor = Cursors.Default;
- Invalidate();
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- base.OnMouseUp(e);
- State = MouseMode.Hovered;
- Cursor = Cursors.Hand;
- Invalidate();
- }
- #endregion
- #region Properties
- [Category("Custom"), Description("Gets or sets the style for the control.")]
- public iStyle Style
- {
- get { return _Style; }
- set
- {
- _Style = value;
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the text of the left side of the control.")]
- public string LeftText
- {
- get { return _LeftText; }
- set
- {
- _LeftText = value;
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the text of the right side of the control.")]
- public string RightText
- {
- get { return _RightText; }
- set
- {
- _RightText = value;
- Invalidate();
- }
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- Rectangle Rect = new Rectangle(0, 0, Width - 1, Height - 1);
- G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- G.SmoothingMode = SmoothingMode.AntiAlias;
- RedPart = new Rectangle(0, 0, Width / 2, Height);
- LightPart = new Rectangle(Width / 2, 0, Width - Width / 2, Height);
- switch (State) {
- case MouseMode.Normal:
- G.FillPath(Style == iStyle.Red ? Brushes.Red : Brushes.Blue, H.RoundRec(RedPart, 6, true, false, true, false));
- G.FillRectangle(Brushes.LightSilver, LightPart);
- G.DrawLine(Pens.Silver, Convert.ToInt32(Width / 2), 0, Convert.ToInt32(Width - 1), 0);
- G.DrawLine(Pens.Silver, Convert.ToInt32(Width / 2), Height - 1, Width, Height - 1);
- G.DrawLine(Pens.Silver, Width - 1, 0, Width - 1, Height);
- G.DrawString(RightText, Font, Brushes.White, RedPart, H.SetPosition());
- G.DrawString(LeftText, Font, Brushes.Gray, LightPart, H.SetPosition());
- break;
- case MouseMode.Hovered:
- G.FillPath(Style == iStyle.Red ? Brushes.LightRed : Brushes.LighterBlue, H.RoundRec(RedPart, 6, true, false, true, false));
- G.FillRectangle(Brushes.LightSilver, LightPart);
- G.DrawLine(Pens.Silver, Convert.ToInt32(Width / 2), 0, Convert.ToInt32(Width - 1), 0);
- G.DrawLine(Pens.Silver, Convert.ToInt32(Width / 2), Height - 1, Width, Height - 1);
- G.DrawLine(Pens.Silver, Width - 1, 0, Width - 1, Height);
- G.DrawString(RightText, Font, Brushes.White, RedPart, H.SetPosition());
- G.DrawString(LeftText, Font, Brushes.Gray, LightPart, H.SetPosition());
- break;
- case MouseMode.Pushed:
- G.FillPath(Style == iStyle.Red ? Brushes.DarkRed : Brushes.DarkBlue, H.RoundRec(RedPart, 6, true, false, true, false));
- G.FillRectangle(Brushes.LightSilver, LightPart);
- G.DrawLine(Pens.Silver, Convert.ToInt32(Width / 2), 0, Convert.ToInt32(Width - 1), 0);
- G.DrawLine(Pens.Silver, Convert.ToInt32(Width / 2), Height - 1, Width, Height - 1);
- G.DrawLine(Pens.Silver, Width - 1, 0, Width - 1, Height);
- G.DrawString(RightText, Font, Brushes.White, RedPart, H.SetPosition());
- G.DrawString(LeftText, Font, Brushes.Gray, LightPart, H.SetPosition());
- break;
- }
- }
- #endregion
- #region Enumerators
- public enum iStyle
- {
- Blue,
- Red
- }
- #endregion
- }
- #endregion
- #region TextBox
- [DefaultEvent("TextChanged")]
- public class YoutubeTextbox : Control
- {
- #region Declarations
- private TextBox _T = new TextBox();
- private TextBox T
- {
- get { return _T; }
- set
- {
- if (_T != null)
- {
- _T.MouseLeave -= T_MouseLeave;
- _T.MouseEnter -= T_MouseEnter;
- _T.MouseDown -= T_MouseEnter;
- _T.MouseHover -= T_MouseEnter;
- _T.TextChanged -= T_TextChanged;
- _T.KeyDown -= T_KeyDown;
- }
- _T = value;
- if (_T != null)
- {
- _T.MouseLeave += T_MouseLeave;
- _T.MouseEnter += T_MouseEnter;
- _T.MouseDown += T_MouseEnter;
- _T.MouseHover += T_MouseEnter;
- _T.TextChanged += T_TextChanged;
- _T.KeyDown += T_KeyDown;
- }
- }
- }
- private static readonly HelperMethods H = new HelperMethods();
- private HorizontalAlignment _TextAlign;
- private int _MaxLength;
- private bool _ReadOnly;
- private bool _UseSystemPasswordChar;
- private string _WatermarkText;
- private Image _Image;
- private MouseMode State;
- private AutoCompleteSource _AutoCompleteSource;
- private AutoCompleteMode _AutoCompleteMode;
- private AutoCompleteStringCollection _AutoCompleteCustomSource;
- private bool _Multiline;
- private string[] _Lines;
- #endregion
- #region Native Methods
- [DllImport("user32.dll", CharSet = CharSet.Auto)]
- static extern IntPtr SendMessage(IntPtr hWnd, int Msg, int wParam, string lParam);
- #endregion
- #region Properties
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public BorderStyle BorderStyle
- {
- get
- {
- return BorderStyle.None;
- }
- }
- [Category("Custom"), Description("Gets or sets how text is aligned in TextBox control.")]
- public HorizontalAlignment TextAlign
- {
- get { return _TextAlign; }
- set
- {
- _TextAlign = value;
- if (T != null)
- {
- T.TextAlign = value;
- }
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets how text is aligned in TextBox control.")]
- public int MaxLength
- {
- get { return _MaxLength; }
- set
- {
- _MaxLength = value;
- if (T != null)
- {
- T.MaxLength = value;
- }
- Invalidate();
- }
- }
- [Browsable(false), ReadOnly(true)]
- public override Color BackColor
- {
- get { return Color.Transparent; }
- }
- [Browsable(false), ReadOnly(true)]
- public override Color ForeColor
- {
- get { return Color.Transparent; }
- }
- [Category("Custom"), Description("Gets or sets a value indicating whether text in the text box is read-only.")]
- public bool ReadOnly
- {
- get { return _ReadOnly; }
- set
- {
- _ReadOnly = value;
- if (T != null)
- {
- T.ReadOnly = value;
- }
- }
- }
- [Category("Custom"), Description("Gets or sets a value indicating whether the text in TextBox control should appear as the default password character.")]
- public bool UseSystemPasswordChar
- {
- get { return _UseSystemPasswordChar; }
- set
- {
- _UseSystemPasswordChar = value;
- if (T != null)
- {
- T.UseSystemPasswordChar = value;
- }
- }
- }
- [Category("Custom"), Description("Gets or sets a value indicating whether this is a multiline System.Windows.Forms.TextBox control.")]
- public bool Multiline
- {
- get { return _Multiline; }
- set
- {
- _Multiline = value;
- if (T == null)
- return;
- T.Multiline = value;
- if (value)
- {
- T.Height = Height - 10;
- }
- else
- {
- Height = T.Height + 10;
- }
- }
- }
- [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
- public new Image BackgroundImage
- {
- get { return null; }
- }
- [Category("Custom"), Description("Gets or sets the current text in TextBox.")]
- public override string Text
- {
- get { return base.Text; }
- set
- {
- base.Text = value;
- if (T != null)
- {
- T.Text = value;
- }
- }
- }
- [Category("Custom"), Description("Gets or sets the text in the System.Windows.Forms.TextBox while being empty.")]
- public string WatermarkText
- {
- get { return _WatermarkText; }
- set
- {
- _WatermarkText = value;
- SendMessage(T.Handle, 5377, 0, value);
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the image of the control.")]
- public Image Image
- {
- get { return _Image; }
- set
- {
- _Image = value;
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets a value specifying the source of complete strings used for automatic completion.")]
- public AutoCompleteSource AutoCompleteSource
- {
- get { return _AutoCompleteSource; }
- set
- {
- _AutoCompleteSource = value;
- if (T != null)
- {
- T.AutoCompleteSource = value;
- }
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets a value specifying the source of complete strings used for automatic completion.")]
- public AutoCompleteStringCollection AutoCompleteCustomSource
- {
- get { return _AutoCompleteCustomSource; }
- set
- {
- _AutoCompleteCustomSource = value;
- if (T != null)
- {
- T.AutoCompleteCustomSource = value;
- }
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets an option that controls how automatic completion works for the TextBox.")]
- public AutoCompleteMode AutoCompleteMode
- {
- get { return _AutoCompleteMode; }
- set
- {
- _AutoCompleteMode = value;
- if (T != null)
- {
- T.AutoCompleteMode = value;
- }
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the font of the text displayed by the control.")]
- public new Font Font
- {
- get { return base.Font; }
- set
- {
- base.Font = value;
- if (T == null)
- return;
- T.Font = value;
- T.Location = new Point(5, 5);
- T.Width = Width - 8;
- if (!Multiline)
- Height = T.Height + 11;
- }
- }
- [Category("Custom"), Description("Gets or sets the lines of text in the control.")]
- public string[] Lines
- {
- get { return _Lines; }
- set
- {
- _Lines = value;
- if (T == null)
- return;
- T.Lines = value;
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the ContextMenuStrip associated with this control.")]
- public override ContextMenuStrip ContextMenuStrip
- {
- get { return base.ContextMenuStrip; }
- set
- {
- base.ContextMenuStrip = value;
- if (T == null)
- return;
- T.ContextMenuStrip = value;
- Invalidate();
- }
- }
- #endregion
- #region Constructors
- public YoutubeTextbox()
- {
- SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
- DoubleBuffered = true;
- UpdateStyles();
- _TextAlign = HorizontalAlignment.Left;
- _MaxLength = 32767;
- _ReadOnly = false;
- _UseSystemPasswordChar = false;
- _WatermarkText = string.Empty;
- _Image = null;
- State = HelperMethods.MouseMode.Normal;
- _AutoCompleteSource = AutoCompleteSource.None;
- _AutoCompleteMode = AutoCompleteMode.None;
- _Multiline = false;
- _Lines = null;
- Font = new Font("Segoe UI", 10);
- T.Multiline = false;
- T.Cursor = Cursors.IBeam;
- T.BackColor = Colors.White;
- T.ForeColor = Colors.Silver;
- T.BorderStyle = BorderStyle.None;
- T.Location = new Point(7, 8);
- T.Font = Font;
- T.UseSystemPasswordChar = UseSystemPasswordChar;
- Size = new Size(135, 30);
- if (Multiline)
- {
- T.Height = Height - 11;
- }
- else
- {
- Height = T.Height + 11;
- }
- }
- #endregion
- #region Events
- public new event TextChangedEventHandler TextChanged;
- public delegate void TextChangedEventHandler(object sender);
- protected override void OnCreateControl()
- {
- base.OnCreateControl();
- if (!Controls.Contains(T))
- Controls.Add(T);
- }
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- T.Size = new Size(Width - 10, Height - 10);
- }
- #region TextBox MouseEvents
- private void T_MouseLeave(object sender, EventArgs e)
- {
- State = HelperMethods.MouseMode.Normal;
- Invalidate();
- }
- private void T_MouseEnter(object sender, EventArgs e)
- {
- State = HelperMethods.MouseMode.Pushed;
- Invalidate();
- }
- private void T_TextChanged(object sender, EventArgs e)
- {
- Text = T.Text;
- TextChanged?.Invoke(this);
- Invalidate();
- }
- private void T_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.Control && e.KeyCode == Keys.A)
- e.SuppressKeyPress = true;
- if (e.Control && e.KeyCode == Keys.C)
- {
- T.Copy();
- e.SuppressKeyPress = true;
- }
- State = MouseMode.Pushed;
- Invalidate();
- }
- #endregion
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- GraphicsPath GP = new GraphicsPath();
- Rectangle Rect = new Rectangle(0, 0, Width - 1, Height - 1);
- GP.AddRectangle(Rect);
- GP.CloseFigure();
- using (PathGradientBrush B = new PathGradientBrush(GP) { CenterColor = Colors.White, SurroundColors = new Color[] { Colors.LightSilver }, FocusScales = new PointF(0.98f, 0.75f) })
- using (Pen P = new Pen(Colors.Silver))
- using (Pen P2 = new Pen(Colors.Blue))
- {
- switch (State)
- {
- case MouseMode.Normal:
- G.FillRectangle(B, Rect);
- G.DrawRectangle(P, Rect);
- break;
- case MouseMode.Pushed:
- G.FillRectangle(B, Rect);
- G.DrawRectangle(P2, Rect);
- break;
- }
- }
- if (Image != null)
- {
- T.Location = new Point(31, 5);
- T.Width = Width - 60;
- G.InterpolationMode = InterpolationMode.HighQualityBicubic;
- G.DrawImage(Image, new Rectangle(8, 6, 16, 16));
- }
- else
- {
- T.Location = new Point(7, 5);
- T.Width = Width - 10;
- }
- GP.Dispose();
- }
- #endregion
- }
- #endregion
- #region Seperator
- public class YoutubeSeperator : Control
- {
- #region Variables
- private Style _SeperatorStyle;
- private Color _SeperatorColor;
- #endregion
- #region Enumerators
- public enum Style
- {
- Horizental,
- Vertiacal
- }
- #endregion
- #region Properties
- [Category("Custom"), Description("Gets or sets the style for the control.")]
- public Style SeperatorStyle
- {
- get { return _SeperatorStyle; }
- set
- {
- _SeperatorStyle = value;
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the color for the control.")]
- public Color SeperatorColor
- {
- get { return _SeperatorColor; }
- set
- {
- _SeperatorColor = value;
- Invalidate();
- }
- }
- #endregion
- #region Constructors
- public YoutubeSeperator()
- {
- SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
- DoubleBuffered = true;
- UpdateStyles();
- BackColor = Color.Transparent;
- _SeperatorStyle = Style.Horizental;
- _SeperatorColor = Colors.Silver;
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- using (Pen P = new Pen(SeperatorColor))
- {
- switch (SeperatorStyle)
- {
- case Style.Horizental:
- G.DrawLine(P, 0, 1, Width, 1);
- break;
- case Style.Vertiacal:
- G.DrawLine(P, 1, 0, 1, Height);
- break;
- }
- }
- }
- #endregion
- #region Events
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- if (SeperatorStyle == Style.Horizental)
- {
- Height = 4;
- }
- else
- {
- Width = 4;
- }
- }
- #endregion
- }
- #endregion
- #region Label
- [DefaultEvent("TextChanged")]
- public class YoutubeLabel : Control
- {
- #region Draw Cotnrol
- protected override void OnPaint(PaintEventArgs e)
- {
- e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- using (SolidBrush TB = new SolidBrush(ForeColor))
- {
- e.Graphics.DrawString(Text, Font, TB, ClientRectangle);
- }
- }
- #endregion
- #region Constructors
- public YoutubeLabel()
- {
- SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
- DoubleBuffered = true;
- UpdateStyles();
- BackColor = Color.Transparent;
- ForeColor = Color.Silver;
- Font = new Font("Myriad Pro", 10);
- }
- #endregion
- #region Events
- public new event TextChangedEventHandler TextChanged;
- public delegate void TextChangedEventHandler(object sender);
- protected override void OnResize(EventArgs e)
- {
- Height = Font.Height;
- }
- protected override void OnTextChanged(EventArgs e)
- {
- base.OnTextChanged(e);
- TextChanged?.Invoke(this);
- Invalidate();
- }
- #endregion
- }
- #endregion
- #region Link Label
- class YoutubeLinkLabel : LinkLabel
- {
- #region Constructors
- public YoutubeLinkLabel()
- {
- Font = new Font("Myriad Pro", 10);
- BackColor = Color.Transparent;
- LinkColor = Colors.Blue;
- ActiveLinkColor = Color.FromArgb(40, 113, 164);
- VisitedLinkColor = Color.FromArgb(29, 83, 120);
- LinkBehavior = LinkBehavior.HoverUnderline;
- }
- #endregion
- }
- #endregion
- #region Progress
- [DefaultEvent("ValueChanged"), DefaultProperty("Value")]
- public class YoutubeProgressBar : Control
- {
- #region Declarations
- private int _Value;
- private int _Maximum;
- public event ValueChangedEventHandler ValueChanged;
- public delegate void ValueChangedEventHandler(object sender);
- private iStyle _Style;
- #endregion
- #region Constructors
- public YoutubeProgressBar()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
- DoubleBuffered = true;
- UpdateStyles();
- BackColor = Color.Transparent;
- _Maximum = 100;
- _Value = 0;
- _Style = iStyle.Red;
- }
- #endregion
- #region Properties
- [Category("Custom"), Description("Gets or sets the current position of the progressbar.")]
- public int Value
- {
- get
- {
- if (_Value < 0)
- {
- return 0;
- }
- else
- {
- return _Value;
- }
- }
- set
- {
- if (value > Maximum)
- {
- value = Maximum;
- }
- _Value = value;
- ValueChanged?.Invoke(this);
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the maximum value of the progressbar.")]
- public int Maximum
- {
- get { return _Maximum; }
- set
- {
- if (value < _Value)
- {
- _Value = Value;
- }
- _Maximum = value;
- Invalidate();
- }
- }
- [Category("Custom"), Description("Gets or sets the style for the control.")]
- public iStyle Style
- {
- get { return _Style; }
- set
- {
- _Style = value;
- Invalidate();
- }
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- GraphicsPath GP = new GraphicsPath();
- int CurrentValue = Convert.ToInt32((double)Value / Maximum * Width);
- Rectangle Rect = new Rectangle(0, 0, Width, Height);
- G.FillRectangle(Brushes.LightGray, Rect);
- if (CurrentValue != 0)
- {
- G.FillRectangle(Style == iStyle.Red ? Brushes.Red : Brushes.Blue, new Rectangle(Rect.X, Rect.Y, CurrentValue, Rect.Height));
- }
- GP.Dispose();
- }
- #endregion
- #region Enumerators
- public enum iStyle
- {
- Red,
- Blue
- }
- #endregion
- }
- #endregion
- #region CheckBox
- [DefaultEvent("CheckedChanged"), DefaultProperty("Checked")]
- public class YoutubeCheckBox : Control
- {
- #region Declarations
- private static readonly HelperMethods H = new HelperMethods();
- private bool _Checked;
- protected MouseMode State = MouseMode.Normal;
- #endregion
- #region Properties
- [Category("Custom"), Description("Gets or set a value indicating whether the control is in the checked state.")]
- public bool Checked
- {
- get { return _Checked; }
- set
- {
- _Checked = value;
- CheckedChanged?.Invoke(this);
- Invalidate();
- }
- }
- #endregion
- #region Constructors
- public YoutubeCheckBox()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
- DoubleBuffered = true;
- Cursor = Cursors.Hand;
- BackColor = Color.Transparent;
- ForeColor = Color.FromArgb(121, 121, 121);
- Font = new Font("Segoe UI", 9);
- UpdateStyles();
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
- Rectangle rect = new Rectangle(0, 0, 18, 17);
- using (Font F = new Font("Marlett", 14))
- {
- G.FillRectangle(Brushes.LightSilver, rect);
- if (Checked)
- { G.DrawString("b", F, Brushes.Gray, new Rectangle(-2, 0, Width, Height));}
- G.DrawRectangle(Pens.Silver, new Rectangle(0, 0, 17, 16));
- G.DrawString(Text, Font, Brushes.Gray, new Rectangle(18, 1, Width, Height - 4), H.SetPosition(StringAlignment.Near));
- }
- }
- #endregion
- #region Events
- public event CheckedChangedEventHandler CheckedChanged;
- public delegate void CheckedChangedEventHandler(object sender);
- protected override void OnClick(EventArgs e)
- {
- _Checked = !Checked;
- CheckedChanged?.Invoke(this);
- base.OnClick(e);
- Invalidate();
- }
- protected override void OnTextChanged(System.EventArgs e)
- {
- Invalidate();
- base.OnTextChanged(e);
- }
- protected override void OnResize(System.EventArgs e)
- {
- base.OnResize(e);
- Height = 17;
- Invalidate();
- }
- protected override void OnMouseHover(EventArgs e)
- {
- base.OnMouseHover(e);
- State = MouseMode.Hovered;
- Invalidate();
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- base.OnMouseLeave(e);
- State = MouseMode.Normal;
- Invalidate();
- }
- protected override void OnHandleCreated(EventArgs e)
- {
- base.OnHandleCreated(e);
- }
- #endregion
- }
- #endregion
- #region RadioButton
- [DefaultEvent("CheckedChanged"), DefaultProperty("Checked")]
- public class YoutubeRadioButton : Control
- {
- #region Declarations
- private static readonly HelperMethods H = new HelperMethods();
- private bool _Checked;
- protected int _Group;
- #endregion
- #region Properties
- [Category("Custom"), Description("Gets or set a value indicating whether the control is in the checked state.")]
- public bool Checked
- {
- get { return _Checked; }
- set
- {
- _Checked = value;
- CheckedChanged?.Invoke(this);
- Invalidate();
- }
- }
- [Category("Custom")]
- public int Group
- {
- get { return _Group; }
- set
- {
- _Group = value;
- Invalidate();
- }
- }
- #endregion
- #region Constructors
- public YoutubeRadioButton()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
- DoubleBuffered = true;
- UpdateStyles();
- Cursor = Cursors.Hand;
- BackColor = Color.Transparent;
- ForeColor = Color.FromArgb(121, 121, 121);
- Font = new Font("Segoe UI", 9);
- Group = 1;
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- G.SmoothingMode = SmoothingMode.AntiAlias;
- G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- using (Font F = new Font("Marlett", 14))
- {
- G.FillEllipse(Brushes.LightSilver, new Rectangle(0, 0, 21, 21));
- if (Checked)
- { G.FillEllipse(Brushes.Gray, new Rectangle(5, 5, 10, 10)); }
- G.DrawString(Text, Font, Brushes.Gray, new Rectangle(21, 1, Width, Height - 2), H.SetPosition(StringAlignment.Near));
- G.DrawEllipse(Pens.Silver, new Rectangle(0, 0, 20, 20));
- }
- }
- #endregion
- #region Events
- public event CheckedChangedEventHandler CheckedChanged;
- public delegate void CheckedChangedEventHandler(object sender);
- private void UpdateState()
- {
- if (!IsHandleCreated || !Checked)
- return;
- foreach (Control C in Parent.Controls)
- {
- if (!ReferenceEquals(C, this) && C is YoutubeRadioButton && ((YoutubeRadioButton)C).Group == _Group)
- {
- ((YoutubeRadioButton)C).Checked = false;
- }
- }
- }
- protected override void OnClick(EventArgs e)
- {
- _Checked = !Checked;
- UpdateState();
- base.OnClick(e);
- Invalidate();
- }
- protected override void OnCreateControl()
- {
- UpdateState();
- base.OnCreateControl();
- }
- protected override void OnTextChanged(System.EventArgs e)
- {
- Invalidate();
- base.OnTextChanged(e);
- }
- protected override void OnResize(System.EventArgs e)
- {
- base.OnResize(e);
- Height = 22;
- Invalidate();
- }
- #endregion
- }
- #endregion
- #region ComboBox
- [DefaultEvent("SelectedIndexChanged")]
- public class YoutubeComboBox : ComboBox
- {
- #region Declarations
- private int _StartIndex = 0;
- private static readonly HelperMethods H = new HelperMethods();
- public new event SelectedIndexChangedEventHandler SelectedIndexChanged;
- public delegate void SelectedIndexChangedEventHandler(object sender);
- #endregion
- #region Constructors
- public YoutubeComboBox()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
- BackColor = Color.Transparent;
- Font = new Font("Segoe UI", 11);
- DrawMode = DrawMode.OwnerDrawFixed;
- DoubleBuffered = true;
- StartIndex = 0;
- DropDownStyle = ComboBoxStyle.DropDownList;
- UpdateStyles();
- }
- #endregion
- #region Properties
- [Category("Custom Properties"), Description("Gets or sets the index specifying the currently selected item.")]
- private int StartIndex
- {
- get { return _StartIndex; }
- set
- {
- _StartIndex = value;
- try
- {
- base.SelectedIndex = value;
- SelectedIndexChanged?.Invoke(this);
- }
- catch
- {
- }
- Invalidate();
- }
- }
- #endregion
- #region Draw Control
- protected override void OnDrawItem(DrawItemEventArgs e)
- {
- Graphics G = e.Graphics;
- G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- try
- {
- using (SolidBrush BG = new SolidBrush((e.State & DrawItemState.Selected) == DrawItemState.Selected ? Colors.Gray : Colors.White))
- using (SolidBrush TC = new SolidBrush((e.State & DrawItemState.Selected) == DrawItemState.Selected ? Colors.White : Colors.Gray))
- using (Font F = new Font(Font.Name, 9))
- {
- G.FillRectangle(BG, e.Bounds);
- G.DrawString(GetItemText(Items[e.Index]), F, TC, e.Bounds);
- }
- }
- catch
- {
- }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- GraphicsPath GP = new GraphicsPath();
- Rectangle Rect = new Rectangle(0, 0, Width - 1, Height - 1);
- GP.AddRectangle(Rect);
- GP.CloseFigure();
- using (PathGradientBrush B = new PathGradientBrush(GP) { CenterColor = Colors.White, SurroundColors = new Color[] { Colors.LightSilver }, FocusScales = new PointF(0.98f, 0.75f) })
- {
- G.FillPath(B, GP);
- G.DrawPath(Pens.Silver, GP);
- }
- G.SmoothingMode = SmoothingMode.AntiAlias;
- H.DrawTriangle(G, Colors.Silver, 2, new Point(Width - 20, 12), new Point(Width - 16, 16), new Point(Width - 16, 16), new Point(Width - 12, 12), new Point(Width - 16, 17), new Point(Width - 16, 16));
- G.SmoothingMode = SmoothingMode.None;
- using (Font F = new Font(Font.Name, 10))
- {
- G.DrawString(Text, F, Brushes.Silver, new Rectangle(7, 0, Width - 1, Height - 1), H.SetPosition(StringAlignment.Near));
- }
- GP.Dispose();
- }
- #endregion
- #region Events
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- Invalidate();
- }
- #endregion
- }
- #endregion
- #region GroupBox
- public class YouTubeGroupBox : ContainerControl
- {
- #region Declarations
- private static readonly HelperMethods H = new HelperMethods();
- private Rectangle R;
- private iStyle _Style;
- #endregion
- #region Properties
- [Category("Custom"), Description("Gets or sets the image of the control.")]
- public Image Image { get; set; }
- [Category("Custom"), Description("Gets or sets the style for the control.")]
- public iStyle Style
- {
- get { return _Style; }
- set
- {
- _Style = value;
- Invalidate();
- }
- }
- #endregion
- #region Constructors
- public YouTubeGroupBox()
- {
- SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
- DoubleBuffered = true;
- Font = new Font("Segoe UI", 10);
- BackColor = Color.Transparent;
- UpdateStyles();
- Image = null;
- _Style = iStyle.Blue;
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- G.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- Rectangle Rect = new Rectangle(0, 0, Width - 1, Height - 1);
- R = new Rectangle(Width - 30, 15, 20, 20);
- G.FillRectangle(Brushes.White, Rect);
- G.FillRectangle(Style == iStyle.Blue ? Brushes.Blue : Brushes.Red, new Rectangle(0, 0, Width - 1, 50));
- G.DrawString(Text, Font, Brushes.White, new Rectangle(Image == null ? 10 : 35, 0, Width - 1, 50), H.SetPosition(StringAlignment.Near));
- if (Image != null)
- { H.DrawImageWithColor(G, new Rectangle(12, 15, 18, 18), Image, Colors.White); }
- using (Font F = new Font(Font, FontStyle.Bold))
- {
- G.DrawString("x", F, Brushes.White, R, H.SetPosition());
- }
- G.DrawRectangle(Style == iStyle.Blue ? Pens.Blue : Pens.Red, Rect);
- }
- #endregion
- #region Events
- protected override void OnMouseMove(MouseEventArgs e)
- {
- base.OnMouseMove(e);
- if (R.Contains(e.Location))
- {
- Cursor = Cursors.Hand;
- }
- else
- {
- Cursor = Cursors.Default;
- }
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.OnMouseDown(e);
- if (e.Button == MouseButtons.Left && R.Contains(e.Location))
- {
- Parent.Controls.Remove(this);
- }
- }
- #endregion
- #region Enumerators
- public enum iStyle
- {
- Blue,
- Red
- }
- #endregion
- }
- #endregion
- #region Colors & Brushes Pens
- public sealed class Colors
- {
- public static Color Red
- {
- get { return Color.FromArgb(204, 24, 30); }
- }
- public static Color LightRed
- {
- get { return Color.FromArgb(230, 33, 23); }
- }
- public static Color DarkRed
- {
- get { return Color.FromArgb(179, 18, 23); }
- }
- public static Color Blue
- {
- get { return Color.FromArgb(18, 109, 179); }
- }
- public static Color LighterBlue
- {
- get { return Color.FromArgb(22, 122, 198); }
- }
- public static Color DarkBlue
- {
- get { return Color.FromArgb(9, 91, 153); }
- }
- public static Color White
- {
- get { return Color.White; }
- }
- public static Color Silver
- {
- get { return Color.FromArgb(211, 211, 211); }
- }
- public static Color LightSilver
- {
- get { return Color.FromArgb(241, 241, 241); }
- }
- public static Color LighterSilver
- {
- get { return Color.FromArgb(248, 248, 248); }
- }
- public static Color DarkGray
- {
- get { return Color.FromArgb(51, 51, 51); }
- }
- public static Color Gray
- {
- get { return Color.FromArgb(102, 102, 102); }
- }
- public static Color LightGray
- {
- get { return Color.FromArgb(198, 198, 198); }
- }
- public static Color LighterGray
- {
- get { return Color.FromArgb(233, 233, 233); }
- }
- }
- public sealed class Brushes
- {
- public static SolidBrush Red
- {
- get { return new SolidBrush(Colors.Red); }
- }
- public static SolidBrush LightRed
- {
- get { return new SolidBrush(Colors.LightRed); }
- }
- public static SolidBrush DarkRed
- {
- get { return new SolidBrush(Colors.DarkRed); }
- }
- public static SolidBrush Blue
- {
- get { return new SolidBrush(Colors.Blue); }
- }
- public static SolidBrush LighterBlue
- {
- get { return new SolidBrush(Colors.LighterBlue); }
- }
- public static SolidBrush DarkBlue
- {
- get { return new SolidBrush(Colors.DarkBlue); }
- }
- public static SolidBrush White
- {
- get { return new SolidBrush(Colors.White); }
- }
- public static SolidBrush Silver
- {
- get { return new SolidBrush(Colors.Silver); }
- }
- public static SolidBrush LightSilver
- {
- get { return new SolidBrush(Colors.LightSilver); }
- }
- public static SolidBrush LighterSilver
- {
- get { return new SolidBrush(Colors.LighterSilver); }
- }
- public static SolidBrush DarkGray
- {
- get { return new SolidBrush(Colors.DarkGray); }
- }
- public static SolidBrush Gray
- {
- get { return new SolidBrush(Colors.Gray); }
- }
- public static SolidBrush LightGray
- {
- get { return new SolidBrush(Colors.LightGray); }
- }
- public static SolidBrush LighterGray
- {
- get { return new SolidBrush(Colors.LighterGray); }
- }
- }
- public sealed class Pens
- {
- public static Pen Red
- {
- get { return new Pen(Colors.Red); }
- }
- public static Pen LightRed
- {
- get { return new Pen(Colors.LightRed); }
- }
- public static Pen DarkRed
- {
- get { return new Pen(Colors.DarkRed); }
- }
- public static Pen Blue
- {
- get { return new Pen(Colors.Blue); }
- }
- public static Pen LighterBlue
- {
- get { return new Pen(Colors.LighterBlue); }
- }
- public static Pen DarkBlue
- {
- get { return new Pen(Colors.DarkBlue); }
- }
- public static Pen White
- {
- get { return new Pen(Colors.White); }
- }
- public static Pen Silver
- {
- get { return new Pen(Colors.Silver); }
- }
- public static Pen LightSilver
- {
- get { return new Pen(Colors.Gray); }
- }
- public static Pen LighterSilver
- {
- get { return new Pen(Colors.LighterSilver); }
- }
- public static Pen DarkGray
- {
- get { return new Pen(Colors.DarkGray); }
- }
- public static Pen Gray
- {
- get { return new Pen(Colors.Gray); }
- }
- public static Pen LightGray
- {
- get { return new Pen(Colors.LightGray); }
- }
- public static Pen LighterGray
- {
- get { return new Pen(Colors.LighterGray); }
- }
- }
- #endregion
Add Comment
Please, Sign In to add comment