Advertisement
PatPositron

Untitled

Apr 16th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.29 KB | None | 0 0
  1. [DefaultEvent("TextChanged")]
  2. class EFVSTextBox : Control
  3. {
  4.     #region "Declares"
  5.  
  6.     private HorizontalAlignment _TextAlign = HorizontalAlignment.Left;
  7.     private int _MaxLength = 32767;
  8.     private bool _ReadOnly;
  9.     private bool _UseSystemPasswordChar;
  10.     private bool _Multiline;
  11.     private TextBox Base;
  12.  
  13.     private GraphicsPath GPBtn;
  14.     private Pen Border;
  15.     private PathGradientBrush InnerGradient;
  16.     private Graphics G;
  17.  
  18.  
  19.     public HorizontalAlignment TextAlign
  20.     {
  21.         get { return _TextAlign; }
  22.         set
  23.         {
  24.             _TextAlign = value;
  25.             if (Base != null)
  26.             {
  27.                 Base.TextAlign = value;
  28.             }
  29.         }
  30.     }
  31.  
  32.     public int MaxLength
  33.     {
  34.         get { return _MaxLength; }
  35.         set
  36.         {
  37.             _MaxLength = value;
  38.             if (Base != null)
  39.             {
  40.                 Base.MaxLength = value;
  41.             }
  42.         }
  43.     }
  44.  
  45.     public bool ReadOnly
  46.     {
  47.         get { return _ReadOnly; }
  48.         set
  49.         {
  50.             _ReadOnly = value;
  51.             if (Base != null)
  52.             {
  53.                 Base.ReadOnly = value;
  54.             }
  55.         }
  56.     }
  57.  
  58.     public bool UseSystemPasswordChar
  59.     {
  60.         get { return _UseSystemPasswordChar; }
  61.         set
  62.         {
  63.             _UseSystemPasswordChar = value;
  64.             if (Base != null)
  65.             {
  66.                 Base.UseSystemPasswordChar = value;
  67.             }
  68.         }
  69.     }
  70.  
  71.     public bool Multiline
  72.     {
  73.         get { return _Multiline; }
  74.         set
  75.         {
  76.             _Multiline = value;
  77.             if (Base != null)
  78.             {
  79.                 Base.Multiline = value;
  80.  
  81.                 if (value)
  82.                 {
  83.                     Base.Height = Height - 11;
  84.                 }
  85.                 else
  86.                 {
  87.                     Height = Base.Height + 11;
  88.                 }
  89.             }
  90.         }
  91.     }
  92.  
  93.     public override string Text
  94.     {
  95.         get { return base.Text; }
  96.         set
  97.         {
  98.             base.Text = value;
  99.             if (Base != null)
  100.             {
  101.                 Base.Text = value;
  102.             }
  103.         }
  104.     }
  105.  
  106.     public override Font Font
  107.     {
  108.         get { return base.Font; }
  109.         set
  110.         {
  111.             base.Font = value;
  112.             if (Base != null)
  113.             {
  114.                 Base.Font = value;
  115.                 Base.Location = new Point(5, 5);
  116.                 Base.Width = Width - 8;
  117.  
  118.                 if (!_Multiline)
  119.                 {
  120.                     Height = Base.Height + 11;
  121.                 }
  122.             }
  123.         }
  124.     }
  125.  
  126.     protected override void OnHandleCreated(EventArgs e)
  127.     {
  128.         if (!Controls.Contains(Base))
  129.         {
  130.             Controls.Add(Base);
  131.         }
  132.  
  133.         base.OnHandleCreated(e);
  134.     }
  135.  
  136.     private GraphicsPath CreateRoundPath;
  137.  
  138.     private Rectangle CreateRoundRectangle;
  139.     public GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
  140.     {
  141.         CreateRoundRectangle = new Rectangle(x, y, width, height);
  142.         return CreateRound(CreateRoundRectangle, slope);
  143.     }
  144.  
  145.     public GraphicsPath CreateRound(Rectangle r, int slope)
  146.     {
  147.         CreateRoundPath = new GraphicsPath(FillMode.Winding);
  148.         CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
  149.         CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
  150.         CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
  151.         CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
  152.         CreateRoundPath.CloseFigure();
  153.         return CreateRoundPath;
  154.     }
  155.  
  156.     #endregion
  157.  
  158.     public EFVSTextBox()
  159.     {
  160.         BackColor = Color.FromArgb(108,108,108);
  161.         ForeColor = Color.FromArgb(228, 228, 228);
  162.         Font = new Font("Segoe UI", 9);
  163.  
  164.         SetStyle((ControlStyles)139286, true);
  165.         SetStyle(ControlStyles.Selectable, true);
  166.  
  167.         Cursor = Cursors.IBeam;
  168.  
  169.         Base = new TextBox();
  170.         Base.Font = Font;
  171.         Base.Text = Text;
  172.         Base.MaxLength = _MaxLength;
  173.         Base.Multiline = _Multiline;
  174.         Base.ReadOnly = _ReadOnly;
  175.         Base.UseSystemPasswordChar = _UseSystemPasswordChar;
  176.  
  177.         Base.ForeColor = Color.FromArgb(51, 51, 51);
  178.         Base.BackColor = Color.FromArgb(140,140,140);
  179.  
  180.         Base.BorderStyle = BorderStyle.None;
  181.  
  182.         Base.Location = new Point(0, 0);
  183.         Base.Width = Width - 11;
  184.  
  185.         if (_Multiline)
  186.         {
  187.             Base.Height = Height - 8;
  188.         }
  189.         else
  190.         {
  191.             Height = Base.Height + 8;
  192.         }
  193.  
  194.         Base.TextChanged += OnBaseTextChanged;
  195.         Base.KeyDown += OnBaseKeyDown;
  196.  
  197.         Border = new Pen(Color.FromArgb(84, 84, 84));
  198.     }
  199.  
  200.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  201.     {
  202.         G = e.Graphics;
  203.  
  204.         G.Clear(BackColor);
  205.         G.SmoothingMode = SmoothingMode.HighQuality;
  206.  
  207.         GPBtn = CreateRound(new Rectangle(0, 0, Width - 1, Height - 2), 5);
  208.  
  209.         InnerGradient = new PathGradientBrush(GPBtn);
  210.         InnerGradient.CenterColor = Color.FromArgb(140, 140, 140);
  211.         InnerGradient.SurroundColors = new Color[] { Color.FromArgb(120, 120, 120) };
  212.         InnerGradient.FocusScales = new PointF(.95f, .7f);
  213.  
  214.         G.FillPath(InnerGradient, GPBtn);
  215.  
  216.         G.DrawPath(Border, GPBtn);
  217.     }
  218.  
  219.     private void OnBaseTextChanged(object s, EventArgs e)
  220.     {
  221.         Text = Base.Text;
  222.     }
  223.  
  224.     private void OnBaseKeyDown(object s, KeyEventArgs e)
  225.     {
  226.         if (e.Control && e.KeyCode == Keys.A)
  227.         {
  228.             Base.SelectAll();
  229.             e.SuppressKeyPress = true;
  230.         }
  231.     }
  232.  
  233.     protected override void OnResize(EventArgs e)
  234.     {
  235.         Base.Location = new Point(5, 5);
  236.  
  237.         Base.Width = Width - 10;
  238.         Base.Height = Height - 11;
  239.  
  240.         base.OnResize(e);
  241.     }
  242.  
  243.     protected override void OnMouseDown(MouseEventArgs e)
  244.     {
  245.         Base.Focus();
  246.         base.OnMouseDown(e);
  247.     }
  248.  
  249.     protected override void OnEnter(EventArgs e)
  250.     {
  251.         Base.Focus();
  252.         Invalidate();
  253.         base.OnEnter(e);
  254.     }
  255.  
  256.     protected override void OnLeave(EventArgs e)
  257.     {
  258.         Invalidate();
  259.         base.OnLeave(e);
  260.     }
  261.  
  262. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement