| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- namespace UAS_MES_NEW.CustomControl.TextBoxWithIcon
- {
- public partial class RoundTextBox : UserControl
- {
- TextBox box = new TextBox();
- public RoundTextBox()
- {
- InitializeComponent();
- box.BorderStyle = BorderStyle.None;
- box.Width = this.Width;
- box.KeyDown += Box_KeyDown;
- this.Controls.Add(box);
- }
- private void Box_KeyDown(object sender, KeyEventArgs e)
- {
- UserKeyDown?.Invoke(sender, e);
- }
- public new char PassWordChar
- {
- get { return box.PasswordChar; }
- set
- {
- box.PasswordChar = value;
- }
- }
- [DefaultValue("")]
- public new string Text
- {
- get { return box.Text; }
- set
- {
- box.Text = value;
- }
- }
- public delegate void OnUserKeyDown(object sender, KeyEventArgs e);
- //定义事件
- public event OnUserKeyDown UserKeyDown;
- int r = 6;
- [Category("布局"), Description("倒角半径。")]
- public int R
- {
- get { return r; }
- set
- {
- r = value;
- }
- }
- private void RoundTextBox_Paint(object sender, PaintEventArgs e)
- {
- int w = R * 2;
- base.OnPaintBackground(e);
- e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
- using (GraphicsPath path = new GraphicsPath())
- {
- path.AddArc(0, 0, w, w, 180, 90);
- path.AddArc(this.Width - w - 1, 0, w, w, -90, 90);
- path.AddArc(this.Width - w - 1, this.Height - w - 1, w, w, 0, 90);
- path.AddArc(0, this.Height - w - 1, w, w, 90, 90);
- path.CloseFigure();
- e.Graphics.FillPath(Brushes.White, path);
- using (Pen pen = new Pen(Color.Gray))
- {
- e.Graphics.DrawPath(pen, path);
- }
- }
- }
- private void RoundTextBox_Resize(object sender, EventArgs e)
- {
- box.Left = 5;
- box.Top = 3;
- }
- }
- }
|