日期:2014-05-19  浏览次数:20874 次

如何实现一个继承于TextBox基类的控件,包含一个Label标签?
label+TextBox

但是是继承TExtBox的,谢谢

------解决方案--------------------
自定义控件比较容易实现
------解决方案--------------------
有必要么?

用UserControl直接实现一个CustomTextBox啦
------解决方案--------------------
做一个用户控件,上面放一个label和一个textbox
public partial class MyLabelTextBox : UserControl
{
public MyLabelTextBox()
{
InitializeComponent();
}
public override string Text
{
get
{
return textBox1.Text;
}
set
{
textBox1.Text = value;
}
}
public string Title {
get {
return label1.Text;
}
set {
label1.Text = value;
}
}
}
------解决方案--------------------
用usercontrol 需要手工将 TextBox的属性传递给Usercontrol,太多了
------------------------------
不用,可以直接这样
public TextBox myTextbox{
get {
return textBox1;
}
set {
textBox1 = value;
}
}
public Label myLabel{
//同上....大概如此,设置的时候需要展开
}