Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [DefaultEvent("TextChanged")]
- class EFVSTextBox : Control
- {
- #region "Declares"
- private HorizontalAlignment _TextAlign = HorizontalAlignment.Left;
- private int _MaxLength = 32767;
- private bool _ReadOnly;
- private bool _UseSystemPasswordChar;
- private bool _Multiline;
- private TextBox Base;
- private GraphicsPath GPBtn;
- private Pen Border;
- private PathGradientBrush InnerGradient;
- private Graphics G;
- public HorizontalAlignment TextAlign
- {
- get { return _TextAlign; }
- set
- {
- _TextAlign = value;
- if (Base != null)
- {
- Base.TextAlign = value;
- }
- }
- }
- public int MaxLength
- {
- get { return _MaxLength; }
- set
- {
- _MaxLength = value;
- if (Base != null)
- {
- Base.MaxLength = value;
- }
- }
- }
- public bool ReadOnly
- {
- get { return _ReadOnly; }
- set
- {
- _ReadOnly = value;
- if (Base != null)
- {
- Base.ReadOnly = value;
- }
- }
- }
- public bool UseSystemPasswordChar
- {
- get { return _UseSystemPasswordChar; }
- set
- {
- _UseSystemPasswordChar = value;
- if (Base != null)
- {
- Base.UseSystemPasswordChar = value;
- }
- }
- }
- public bool Multiline
- {
- get { return _Multiline; }
- set
- {
- _Multiline = value;
- if (Base != null)
- {
- Base.Multiline = value;
- if (value)
- {
- Base.Height = Height - 11;
- }
- else
- {
- Height = Base.Height + 11;
- }
- }
- }
- }
- public override string Text
- {
- get { return base.Text; }
- set
- {
- base.Text = value;
- if (Base != null)
- {
- Base.Text = value;
- }
- }
- }
- public override Font Font
- {
- get { return base.Font; }
- set
- {
- base.Font = value;
- if (Base != null)
- {
- Base.Font = value;
- Base.Location = new Point(5, 5);
- Base.Width = Width - 8;
- if (!_Multiline)
- {
- Height = Base.Height + 11;
- }
- }
- }
- }
- protected override void OnHandleCreated(EventArgs e)
- {
- if (!Controls.Contains(Base))
- {
- Controls.Add(Base);
- }
- base.OnHandleCreated(e);
- }
- private GraphicsPath CreateRoundPath;
- private Rectangle CreateRoundRectangle;
- public GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
- {
- CreateRoundRectangle = new Rectangle(x, y, width, height);
- return CreateRound(CreateRoundRectangle, slope);
- }
- public GraphicsPath CreateRound(Rectangle r, int slope)
- {
- CreateRoundPath = new GraphicsPath(FillMode.Winding);
- CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
- CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
- CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
- CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
- CreateRoundPath.CloseFigure();
- return CreateRoundPath;
- }
- #endregion
- public EFVSTextBox()
- {
- BackColor = Color.FromArgb(108,108,108);
- ForeColor = Color.FromArgb(228, 228, 228);
- Font = new Font("Segoe UI", 9);
- SetStyle((ControlStyles)139286, true);
- SetStyle(ControlStyles.Selectable, true);
- Cursor = Cursors.IBeam;
- Base = new TextBox();
- Base.Font = Font;
- Base.Text = Text;
- Base.MaxLength = _MaxLength;
- Base.Multiline = _Multiline;
- Base.ReadOnly = _ReadOnly;
- Base.UseSystemPasswordChar = _UseSystemPasswordChar;
- Base.ForeColor = Color.FromArgb(51, 51, 51);
- Base.BackColor = Color.FromArgb(140,140,140);
- Base.BorderStyle = BorderStyle.None;
- Base.Location = new Point(0, 0);
- Base.Width = Width - 11;
- if (_Multiline)
- {
- Base.Height = Height - 8;
- }
- else
- {
- Height = Base.Height + 8;
- }
- Base.TextChanged += OnBaseTextChanged;
- Base.KeyDown += OnBaseKeyDown;
- Border = new Pen(Color.FromArgb(84, 84, 84));
- }
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- G = e.Graphics;
- G.Clear(BackColor);
- G.SmoothingMode = SmoothingMode.HighQuality;
- GPBtn = CreateRound(new Rectangle(0, 0, Width - 1, Height - 2), 5);
- InnerGradient = new PathGradientBrush(GPBtn);
- InnerGradient.CenterColor = Color.FromArgb(140, 140, 140);
- InnerGradient.SurroundColors = new Color[] { Color.FromArgb(120, 120, 120) };
- InnerGradient.FocusScales = new PointF(.95f, .7f);
- G.FillPath(InnerGradient, GPBtn);
- G.DrawPath(Border, GPBtn);
- }
- private void OnBaseTextChanged(object s, EventArgs e)
- {
- Text = Base.Text;
- }
- private void OnBaseKeyDown(object s, KeyEventArgs e)
- {
- if (e.Control && e.KeyCode == Keys.A)
- {
- Base.SelectAll();
- e.SuppressKeyPress = true;
- }
- }
- protected override void OnResize(EventArgs e)
- {
- Base.Location = new Point(5, 5);
- Base.Width = Width - 10;
- Base.Height = Height - 11;
- base.OnResize(e);
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- Base.Focus();
- base.OnMouseDown(e);
- }
- protected override void OnEnter(EventArgs e)
- {
- Base.Focus();
- Invalidate();
- base.OnEnter(e);
- }
- protected override void OnLeave(EventArgs e)
- {
- Invalidate();
- base.OnLeave(e);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement