(三十五)c#Winform自定义控件-下拉框

前提

入行已经7,8年了,一直想做一套漂亮点的自定义控件,于是就有了本系列文章。

GitHub:https://github.com/kwwwvagaa/NetWinformControl

码云:https://gitee.com/kwwwvagaa/net_winform_custom_control.git

如果觉得写的还行,请点个 star 支持一下吧

欢迎前来交流探讨: 企鹅群568015492 企鹅群568015492

目录

https://blog.csdn.net/kwwwvagaa/article/details/100586547

准备工作

此控件用到了停靠窗体和日期控件的一个面板,以及基类控件,如果你还对此不了解,请移步

(一)c#Winform自定义控件-基类控件

(十九)c#Winform自定义控件-停靠窗体

(三十三)c#Winform自定义控件-日期控件

开始

添加一个用户控件,命名UCComboBox,继承自UCControlBase

属性

复制代码

  1 Color _ForeColor = Color.FromArgb(64, 64, 64);
  2         [Description("文字颜色"), Category("自定义")]
  3         public override Color ForeColor
  4         {
  5             get
  6             {
  7                 return _ForeColor;
  8             }
  9             set
 10             {
 11                 _ForeColor = value;
 12                 lblInput.ForeColor = value;
 13                 txtInput.ForeColor = value;
 14             }
 15         }
 16 
 17         public event EventHandler SelectedChangedEvent;
 18         public event EventHandler TextChangedEvent;
 19 
 20         private ComboBoxStyle _BoxStyle = ComboBoxStyle.DropDown;
 21 
 22         [Description("控件样式"), Category("自定义")]
 23         public ComboBoxStyle BoxStyle
 24         {
 25             get { return _BoxStyle; }
 26             set
 27             {
 28                 _BoxStyle = value;
 29                 if (value == ComboBoxStyle.DropDownList)
 30                 {
 31                     lblInput.Visible = true;
 32                     txtInput.Visible = false;
 33                 }
 34                 else
 35                 {
 36                     lblInput.Visible = false;
 37                     txtInput.Visible = true;
 38                 }
 39 
 40                 if (this._BoxStyle == ComboBoxStyle.DropDownList)
 41                 {
 42                     txtInput.BackColor = _BackColor;
 43                     base.FillColor = _BackColor;
 44                     base.RectColor = _BackColor;
 45                 }
 46                 else
 47                 {
 48                     txtInput.BackColor = Color.White;
 49                     base.FillColor = Color.White;
 50                     base.RectColor = Color.FromArgb(220, 220, 220);
 51                 }
 52             }
 53         }
 54 
 55         private Font _Font = new Font("微软雅黑", 12);
 56         [Description("字体"), Category("自定义")]
 57         public new Font Font
 58         {
 59             get { return _Font; }
 60             set
 61             {
 62                 _Font = value;
 63                 lblInput.Font = value;
 64                 txtInput.Font = value;
 65                 txtInput.PromptFont = value;
 66                 this.txtInput.Location = new Point(this.txtInput.Location.X, (this.Height - txtInput.Height) / 2);
 67                 this.lblInput.Location = new Point(this.lblInput.Location.X, (this.Height - lblInput.Height) / 2);
 68             }
 69         }
 70 
 71 
 72         [Obsolete("不再可用的属性")]
 73         [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
 74         private new Color FillColor
 75         {
 76             get;
 77             set;
 78         }
 79 
 80         [Obsolete("不再可用的属性")]
 81         [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
 82         private new Color RectColor
 83         {
 84             get;
 85             set;
 86         }
 87 
 88         private string _TextValue;
 89 
 90         public string TextValue
 91         {
 92             get { return _TextValue; }
 93             set
 94             {
 95                 _TextValue = value;
 96                 if (lblInput.Text != value)
 97                     lblInput.Text = value;
 98                 if (txtInput.Text != value)
 99                     txtInput.Text = value;
100             }
101         }
102 
103         private List<KeyValuePair<string, string>> _source = null;
104 
105         public List<KeyValuePair<string, string>> Source
106         {
107             get { return _source; }
108             set
109             {
110                 _source = value;
111                 _selectedIndex = -1;
112                 _selectedValue = "";
113                 _selectedItem = new KeyValuePair<string, string>();
114                 _selectedText = "";
115                 lblInput.Text = "";
116                 txtInput.Text = "";
117             }
118         }
119 
120         private KeyValuePair<string, string> _selectedItem = new KeyValuePair<string, string>();
121 
122         private int _selectedIndex = -1;
123 
124         public int SelectedIndex
125         {
126             get
127             {
128                 return _selectedIndex;
129             }
130             set
131             {
132                 if (value < 0 || _source == null || _source.Count <= 0 || value >= _source.Count)
133                 {
134                     _selectedIndex = -1;
135                     _selectedValue = "";
136                     _selectedItem = new KeyValuePair<string, string>();
137                     SelectedText = "";
138                 }
139                 else
140                 {
141                     _selectedIndex = value;
142                     _selectedItem = _source[value];
143                     _selectedValue = _source[value].Key;
144                     SelectedText = _source[value].Value;
145                 }
146             }
147         }
148 
149         private string _selectedValue = "";
150 
151         public string SelectedValue
152         {
153             get
154             {
155                 return _selectedValue;
156             }
157             set
158             {
159                 if (_source == null || _source.Count <= 0)
160                 {
161                     SelectedText = "";
162                     _selectedValue = "";
163                     _selectedIndex = -1;
164                     _selectedItem = new KeyValuePair<string, string>();
165                 }
166                 else
167                 {
168                     for (int i = 0; i < _source.Count; i++)
169                     {
170                         if (_source[i].Key == value)
171                         {
172                             _selectedValue = value;
173                             _selectedIndex = i;
174                             _selectedItem = _source[i];
175                             SelectedText = _source[i].Value;
176                             return;
177                         }
178                     }
179                     _selectedValue = "";
180                     _selectedIndex = -1;
181                     _selectedItem = new KeyValuePair<string, string>();
182                     SelectedText = "";
183                 }
184             }
185         }
186 
187         private string _selectedText = "";
188 
189         public string SelectedText
190         {
191             get { return _selectedText; }
192             private set
193             {
194                 _selectedText = value;
195                 lblInput.Text = _selectedText;
196                 txtInput.Text = _selectedText;
197                 if (SelectedChangedEvent != null)
198                 {
199                     SelectedChangedEvent(this, null);
200                 }
201             }
202         }
203 
204         private int _ItemWidth = 70;
205 
206         public int ItemWidth
207         {
208             get { return _ItemWidth; }
209             set { _ItemWidth = value; }
210         }
211 
212         private int _dropPanelHeight = -1;
213 
214         public int DropPanelHeight
215         {
216             get { return _dropPanelHeight; }
217             set { _dropPanelHeight = value; }
218         }
219         [Obsolete("不再可用的属性,如需要改变背景色,请使用BackColorExt")]
220         [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
221         private new Color BackColor
222         {
223             get
224             {
225                 return base.BackColor;
226             }
227             set
228             {
229                 base.BackColor = Color.Transparent;
230             }
231         }
232 
233         private Color _BackColor = Color.FromArgb(240, 240, 240);
234 
235         public Color BackColorExt
236         {
237             get
238             {
239                 return _BackColor;
240             }
241             set
242             {
243                 if (value == Color.Transparent)
244                     return;
245                 _BackColor = value;
246                 lblInput.BackColor = value;
247 
248                 if (this._BoxStyle == ComboBoxStyle.DropDownList)
249                 {
250                     txtInput.BackColor = value;
251                     base.FillColor = value;
252                     base.RectColor = value;
253                 }
254                 else
255                 {
256                     txtInput.BackColor = Color.White;
257                     base.FillColor = Color.White;
258                     base.RectColor = Color.FromArgb(220, 220, 220);
259                 }
260             }
261         }

复制代码

构造函数初始化处理

复制代码

 1  public UCComboBox()
 2         {
 3             InitializeComponent();
 4             lblInput.BackColor = _BackColor;
 5             if (this._BoxStyle == ComboBoxStyle.DropDownList)
 6             {
 7                 txtInput.BackColor = _BackColor;
 8                 base.FillColor = _BackColor;
 9                 base.RectColor = _BackColor;
10             }
11             else
12             {
13                 txtInput.BackColor = Color.White;
14                 base.FillColor = Color.White;
15                 base.RectColor = Color.FromArgb(220, 220, 220);
16             }
17             base.BackColor = Color.Transparent;
18         }

复制代码

一些事件处理

复制代码

 1 private void UCComboBox_SizeChanged(object sender, EventArgs e)
 2         {
 3             this.txtInput.Location = new Point(this.txtInput.Location.X, (this.Height - txtInput.Height) / 2);
 4             this.lblInput.Location = new Point(this.lblInput.Location.X, (this.Height - lblInput.Height) / 2);
 5         }
 6 
 7         private void txtInput_TextChanged(object sender, EventArgs e)
 8         {
 9             TextValue = txtInput.Text;
10             if (TextChangedEvent != null)
11             {
12                 TextChangedEvent(this, null);
13             }
14         }
15 
16         private void click_MouseDown(object sender, MouseEventArgs e)
17         {
18             if (_frmAnchor == null || _frmAnchor.IsDisposed || _frmAnchor.Visible == false)
19             {
20 
21                 if (this.Source != null && this.Source.Count > 0)
22                 {
23                     int intRow = 0;
24                     int intCom = 1;
25                     var p = this.PointToScreen(this.Location);
26                     while (true)
27                     {
28                         int intScreenHeight = Screen.PrimaryScreen.Bounds.Height;
29                         if ((p.Y + this.Height + this.Source.Count / intCom * 50 < intScreenHeight || p.Y - this.Source.Count / intCom * 50 > 0)
30                             && (_dropPanelHeight <= 0 ? true : (this.Source.Count / intCom * 50 <= _dropPanelHeight)))
31                         {
32                             intRow = this.Source.Count / intCom + (this.Source.Count % intCom != 0 ? 1 : 0);
33                             break;
34                         }
35                         intCom++;
36                     }
37                     UCTimePanel ucTime = new UCTimePanel();
38                     ucTime.IsShowBorder = true;
39                     int intWidth = this.Width / intCom;
40                     if (intWidth < _ItemWidth)
41                         intWidth = _ItemWidth;
42                     Size size = new Size(intCom * intWidth, intRow * 50);
43                     ucTime.Size = size;
44                     ucTime.FirstEvent = true;
45                     ucTime.SelectSourceEvent += ucTime_SelectSourceEvent;
46                     ucTime.Row = intRow;
47                     ucTime.Column = intCom;
48                     List<KeyValuePair<string, string>> lst = new List<KeyValuePair<string, string>>();
49                     foreach (var item in this.Source)
50                     {
51                         lst.Add(new KeyValuePair<string, string>(item.Key, item.Value));
52                     }
53                     ucTime.Source = lst;
54 
55                     ucTime.SetSelect(_selectedValue);
56 
57                     _frmAnchor = new Forms.FrmAnchor(this, ucTime);
58                     _frmAnchor.Load += (a, b) => { (a as Form).Size = size; };
59 
60                     _frmAnchor.Show(this.FindForm());
61 
62                 }
63             }
64             else
65             {
66                 _frmAnchor.Close();
67             }
68         }
69 
70 
71         Forms.FrmAnchor _frmAnchor;
72         void ucTime_SelectSourceEvent(object sender, EventArgs e)
73         {
74             if (_frmAnchor != null && !_frmAnchor.IsDisposed && _frmAnchor.Visible)
75             {
76                 SelectedValue = sender.ToString();
77                 _frmAnchor.Close();
78             }
79         }
80 
81         private void UCComboBox_Load(object sender, EventArgs e)
82         {
83             if (this._BoxStyle == ComboBoxStyle.DropDownList)
84             {
85                 txtInput.BackColor = _BackColor;
86                 base.FillColor = _BackColor;
87                 base.RectColor = _BackColor;
88             }
89             else
90             {
91                 txtInput.BackColor = Color.White;
92                 base.FillColor = Color.White;
93                 base.RectColor = Color.FromArgb(220, 220, 220);
94             }
95 
96             //if (this.Parent != null && BackColor == Color.Transparent)
97         }
98     }
99 }

复制代码

完整代码如下

// 版权所有  黄正辉  交流群:568015492   QQ:623128629
// 文件名称:UCComboBox.cs
// 创建日期:2019-08-15 15:58:51
// 功能描述:ComboBox
// 项目地址:https://gitee.com/kwwwvagaa/net_winform_custom_control
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HZH_Controls.Controls
{
    [DefaultEvent("SelectedChangedEvent")]
    public partial class UCComboBox : UCControlBase
    {
        Color _ForeColor = Color.FromArgb(64, 64, 64);
        [Description("文字颜色"), Category("自定义")]
        public override Color ForeColor
        {
            get
            {
                return _ForeColor;
            }
            set
            {
                _ForeColor = value;
                lblInput.ForeColor = value;
                txtInput.ForeColor = value;
            }
        }

        public event EventHandler SelectedChangedEvent;
        public event EventHandler TextChangedEvent;

        private ComboBoxStyle _BoxStyle = ComboBoxStyle.DropDown;

        [Description("控件样式"), Category("自定义")]
        public ComboBoxStyle BoxStyle
        {
            get { return _BoxStyle; }
            set
            {
                _BoxStyle = value;
                if (value == ComboBoxStyle.DropDownList)
                {
                    lblInput.Visible = true;
                    txtInput.Visible = false;
                }
                else
                {
                    lblInput.Visible = false;
                    txtInput.Visible = true;
                }

                if (this._BoxStyle == ComboBoxStyle.DropDownList)
                {
                    txtInput.BackColor = _BackColor;
                    base.FillColor = _BackColor;
                    base.RectColor = _BackColor;
                }
                else
                {
                    txtInput.BackColor = Color.White;
                    base.FillColor = Color.White;
                    base.RectColor = Color.FromArgb(220, 220, 220);
                }
            }
        }

        private Font _Font = new Font("微软雅黑", 12);
        [Description("字体"), Category("自定义")]
        public new Font Font
        {
            get { return _Font; }
            set
            {
                _Font = value;
                lblInput.Font = value;
                txtInput.Font = value;
                txtInput.PromptFont = value;
                this.txtInput.Location = new Point(this.txtInput.Location.X, (this.Height - txtInput.Height) / 2);
                this.lblInput.Location = new Point(this.lblInput.Location.X, (this.Height - lblInput.Height) / 2);
            }
        }


        [Obsolete("不再可用的属性")]
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        private new Color FillColor
        {
            get;
            set;
        }

        [Obsolete("不再可用的属性")]
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        private new Color RectColor
        {
            get;
            set;
        }

        private string _TextValue;

        public string TextValue
        {
            get { return _TextValue; }
            set
            {
                _TextValue = value;
                if (lblInput.Text != value)
                    lblInput.Text = value;
                if (txtInput.Text != value)
                    txtInput.Text = value;
            }
        }

        private List<KeyValuePair<string, string>> _source = null;

        public List<KeyValuePair<string, string>> Source
        {
            get { return _source; }
            set
            {
                _source = value;
                _selectedIndex = -1;
                _selectedValue = "";
                _selectedItem = new KeyValuePair<string, string>();
                _selectedText = "";
                lblInput.Text = "";
                txtInput.Text = "";
            }
        }

        private KeyValuePair<string, string> _selectedItem = new KeyValuePair<string, string>();

        private int _selectedIndex = -1;

        public int SelectedIndex
        {
            get
            {
                return _selectedIndex;
            }
            set
            {
                if (value < 0 || _source == null || _source.Count <= 0 || value >= _source.Count)
                {
                    _selectedIndex = -1;
                    _selectedValue = "";
                    _selectedItem = new KeyValuePair<string, string>();
                    SelectedText = "";
                }
                else
                {
                    _selectedIndex = value;
                    _selectedItem = _source[value];
                    _selectedValue = _source[value].Key;
                    SelectedText = _source[value].Value;
                }
            }
        }

        private string _selectedValue = "";

        public string SelectedValue
        {
            get
            {
                return _selectedValue;
            }
            set
            {
                if (_source == null || _source.Count <= 0)
                {
                    SelectedText = "";
                    _selectedValue = "";
                    _selectedIndex = -1;
                    _selectedItem = new KeyValuePair<string, string>();
                }
                else
                {
                    for (int i = 0; i < _source.Count; i++)
                    {
                        if (_source[i].Key == value)
                        {
                            _selectedValue = value;
                            _selectedIndex = i;
                            _selectedItem = _source[i];
                            SelectedText = _source[i].Value;
                            return;
                        }
                    }
                    _selectedValue = "";
                    _selectedIndex = -1;
                    _selectedItem = new KeyValuePair<string, string>();
                    SelectedText = "";
                }
            }
        }

        private string _selectedText = "";

        public string SelectedText
        {
            get { return _selectedText; }
            private set
            {
                _selectedText = value;
                lblInput.Text = _selectedText;
                txtInput.Text = _selectedText;
                if (SelectedChangedEvent != null)
                {
                    SelectedChangedEvent(this, null);
                }
            }
        }

        private int _ItemWidth = 70;

        public int ItemWidth
        {
            get { return _ItemWidth; }
            set { _ItemWidth = value; }
        }

        private int _dropPanelHeight = -1;

        public int DropPanelHeight
        {
            get { return _dropPanelHeight; }
            set { _dropPanelHeight = value; }
        }
        [Obsolete("不再可用的属性,如需要改变背景色,请使用BackColorExt")]
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        private new Color BackColor
        {
            get
            {
                return base.BackColor;
            }
            set
            {
                base.BackColor = Color.Transparent;
            }
        }

        private Color _BackColor = Color.FromArgb(240, 240, 240);

        public Color BackColorExt
        {
            get
            {
                return _BackColor;
            }
            set
            {
                if (value == Color.Transparent)
                    return;
                _BackColor = value;
                lblInput.BackColor = value;

                if (this._BoxStyle == ComboBoxStyle.DropDownList)
                {
                    txtInput.BackColor = value;
                    base.FillColor = value;
                    base.RectColor = value;
                }
                else
                {
                    txtInput.BackColor = Color.White;
                    base.FillColor = Color.White;
                    base.RectColor = Color.FromArgb(220, 220, 220);
                }
            }
        }

        public UCComboBox()
        {
            InitializeComponent();
            lblInput.BackColor = _BackColor;
            if (this._BoxStyle == ComboBoxStyle.DropDownList)
            {
                txtInput.BackColor = _BackColor;
                base.FillColor = _BackColor;
                base.RectColor = _BackColor;
            }
            else
            {
                txtInput.BackColor = Color.White;
                base.FillColor = Color.White;
                base.RectColor = Color.FromArgb(220, 220, 220);
            }
            base.BackColor = Color.Transparent;
        }

        private void UCComboBox_SizeChanged(object sender, EventArgs e)
        {
            this.txtInput.Location = new Point(this.txtInput.Location.X, (this.Height - txtInput.Height) / 2);
            this.lblInput.Location = new Point(this.lblInput.Location.X, (this.Height - lblInput.Height) / 2);
        }

        private void txtInput_TextChanged(object sender, EventArgs e)
        {
            TextValue = txtInput.Text;
            if (TextChangedEvent != null)
            {
                TextChangedEvent(this, null);
            }
        }

        private void click_MouseDown(object sender, MouseEventArgs e)
        {
            if (_frmAnchor == null || _frmAnchor.IsDisposed || _frmAnchor.Visible == false)
            {

                if (this.Source != null && this.Source.Count > 0)
                {
                    int intRow = 0;
                    int intCom = 1;
                    var p = this.PointToScreen(this.Location);
                    while (true)
                    {
                        int intScreenHeight = Screen.PrimaryScreen.Bounds.Height;
                        if ((p.Y + this.Height + this.Source.Count / intCom * 50 < intScreenHeight || p.Y - this.Source.Count / intCom * 50 > 0)
                            && (_dropPanelHeight <= 0 ? true : (this.Source.Count / intCom * 50 <= _dropPanelHeight)))
                        {
                            intRow = this.Source.Count / intCom + (this.Source.Count % intCom != 0 ? 1 : 0);
                            break;
                        }
                        intCom++;
                    }
                    UCTimePanel ucTime = new UCTimePanel();
                    ucTime.IsShowBorder = true;
                    int intWidth = this.Width / intCom;
                    if (intWidth < _ItemWidth)
                        intWidth = _ItemWidth;
                    Size size = new Size(intCom * intWidth, intRow * 50);
                    ucTime.Size = size;
                    ucTime.FirstEvent = true;
                    ucTime.SelectSourceEvent += ucTime_SelectSourceEvent;
                    ucTime.Row = intRow;
                    ucTime.Column = intCom;
                    List<KeyValuePair<string, string>> lst = new List<KeyValuePair<string, string>>();
                    foreach (var item in this.Source)
                    {
                        lst.Add(new KeyValuePair<string, string>(item.Key, item.Value));
                    }
                    ucTime.Source = lst;

                    ucTime.SetSelect(_selectedValue);

                    _frmAnchor = new Forms.FrmAnchor(this, ucTime);
                    _frmAnchor.Load += (a, b) => { (a as Form).Size = size; };

                    _frmAnchor.Show(this.FindForm());

                }
            }
            else
            {
                _frmAnchor.Close();
            }
        }


        Forms.FrmAnchor _frmAnchor;
        void ucTime_SelectSourceEvent(object sender, EventArgs e)
        {
            if (_frmAnchor != null && !_frmAnchor.IsDisposed && _frmAnchor.Visible)
            {
                SelectedValue = sender.ToString();
                _frmAnchor.Close();
            }
        }

        private void UCComboBox_Load(object sender, EventArgs e)
        {
            if (this._BoxStyle == ComboBoxStyle.DropDownList)
            {
                txtInput.BackColor = _BackColor;
                base.FillColor = _BackColor;
                base.RectColor = _BackColor;
            }
            else
            {
                txtInput.BackColor = Color.White;
                base.FillColor = Color.White;
                base.RectColor = Color.FromArgb(220, 220, 220);
            }
        }
    }
}
namespace HZH_Controls.Controls
{
    partial class UCComboBox
    {
        /// <summary> 
        /// 必需的设计器变量。
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// 清理所有正在使用的资源。
        /// </summary>
        /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region 组件设计器生成的代码

        /// <summary> 
        /// 设计器支持所需的方法 - 不要
        /// 使用代码编辑器修改此方法的内容。
        /// </summary>
        private void InitializeComponent()
        {
            this.panel1 = new System.Windows.Forms.Panel();
            this.txtInput = new HZH_Controls.Controls.TextBoxEx();
            this.lblInput = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // panel1
            // 
            this.panel1.BackColor = System.Drawing.Color.Transparent;
            this.panel1.BackgroundImage = global::HZH_Controls.Properties.Resources.ComboBox;
            this.panel1.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Center;
            this.panel1.Dock = System.Windows.Forms.DockStyle.Right;
            this.panel1.Location = new System.Drawing.Point(136, 0);
            this.panel1.Name = "panel1";
            this.panel1.Size = new System.Drawing.Size(37, 32);
            this.panel1.TabIndex = 0;
            this.panel1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.click_MouseDown);
            // 
            // txtInput
            // 
            this.txtInput.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right)));
            this.txtInput.BackColor = System.Drawing.Color.White;
            this.txtInput.BorderStyle = System.Windows.Forms.BorderStyle.None;
            this.txtInput.DecLength = 2;
            this.txtInput.Font = new System.Drawing.Font("微软雅黑", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
            this.txtInput.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            this.txtInput.InputType = TextInputType.NotControl;
            this.txtInput.Location = new System.Drawing.Point(3, 4);
            this.txtInput.Margin = new System.Windows.Forms.Padding(3, 3, 10, 3);
            this.txtInput.MaxValue = new decimal(new int[] {
            1000000,
            0,
            0,
            0});
            this.txtInput.MinValue = new decimal(new int[] {
            1000000,
            0,
            0,
            -2147483648});
            this.txtInput.MyRectangle = new System.Drawing.Rectangle(0, 0, 0, 0);
            this.txtInput.Name = "txtInput";
            this.txtInput.OldText = null;
            this.txtInput.PromptColor = System.Drawing.Color.Silver;
            this.txtInput.PromptFont = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
            this.txtInput.PromptText = "";
            this.txtInput.RegexPattern = "";
            this.txtInput.Size = new System.Drawing.Size(133, 24);
            this.txtInput.TabIndex = 1;
            this.txtInput.TextChanged += new System.EventHandler(this.txtInput_TextChanged);
            // 
            // lblInput
            // 
            this.lblInput.AutoSize = true;
            this.lblInput.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(64)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));
            this.lblInput.Location = new System.Drawing.Point(3, 6);
            this.lblInput.Name = "lblInput";
            this.lblInput.Size = new System.Drawing.Size(0, 20);
            this.lblInput.TabIndex = 2;
            this.lblInput.Visible = false;
            this.lblInput.MouseDown += new System.Windows.Forms.MouseEventHandler(this.click_MouseDown);
            // 
            // UCComboBox
            // 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
            this.BackColor = System.Drawing.Color.Transparent;
            this.ConerRadius = 5;
            this.Controls.Add(this.panel1);
            this.Controls.Add(this.txtInput);
            this.Controls.Add(this.lblInput);
            this.FillColor = System.Drawing.Color.Gainsboro;
            this.IsShowRect = true;
            this.Name = "UCComboBox";
            this.Size = new System.Drawing.Size(173, 32);
            this.Load += new System.EventHandler(this.UCComboBox_Load);
            this.SizeChanged += new System.EventHandler(this.UCComboBox_SizeChanged);
            this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.click_MouseDown);
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion

        private System.Windows.Forms.Panel panel1;
        public TextBoxEx txtInput;
        private System.Windows.Forms.Label lblInput;
    }
}

用处及效果

最后的话

如果你喜欢的话,请到 https://gitee.com/kwwwvagaa/net_winform_custom_control 点个星 星吧

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值