UserControl自定义控件系列一:Label+TextBox组合控件(二)

2014-11-24 08:13:45 · 作者: · 浏览: 1
tArgs e) { try { UTextChanged(sender, e); } catch { } } public delegate void DoubleClickHandler(object sender, System.EventArgs e); public event DoubleClickHandler UDoubleClick; private void txtValue_DoubleClick(object sender, EventArgs e) { try { UDoubleClick(sender, e); } catch { } } private Color color = Color.Black; private void TxtPlusLblLine_Paint(object sender, PaintEventArgs e) { g = this.CreateGraphics(); Pen Pen = new Pen(LineColor); if (lblFiled.Text.Trim() != "") { lblFiled.Visible = true; lblValue.Location = new Point(lblFiled.Location.X + lblFiled.Width + 1, 3); lblValue.Width = this.Width - lblFiled.Location.X - lblFiled.Width; txtValue.Location = new Point(lblFiled.Location.X + lblFiled.Width, 0); txtValue.Width = this.Width - lblFiled.Location.X - lblFiled.Width; g.DrawLine(Pen, lblFiled.Location.X + lblFiled.Width, 20, this.Width, 20); } else { lblFiled.Visible = false; lblValue.Location = new Point(1, 3); lblValue.Width = this.Width; txtValue.Location = new Point(0, 0); txtValue.Width = this.Width; g.DrawLine(Pen, 0, 20, this.Width, 20); } } public Color LineColor { get { return color; } set { color = value; } } public string LBLText { get { return lblFiled.Text; } set { lblFiled.Text = value; } } public ContentAlignment LBLTextAlign { get { return lblFiled.TextAlign; } set { lblFiled.TextAlign = value; } } public bool UEnabled { get { return txtValue.Enabled; } set { txtValue.Enabled = value; } } private void timer1_Tick(object sender, EventArgs e) { if (txtValue.Visible) { txtValue.Focus(); } } } }

代码中控件的属性我没有全部定义出来,如果需要可以加入,事件也是一样的,有需要的话就添加进来。

代码中的注释内容比较少嘿嘿,这些还是比较简单的,所以呢看不懂就去研究研究,看得懂的帮我想想看“如果这样做的话可能会更好”以这个话题展开讨论吧,不要看了下就默默的走开了,多少留点东西进来也好呀。


最后原创博文转载请注明出处谢谢http://blog.csdn.net/jsjyyjs07/article/details/18564099