扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:阿虎 来源:yesky 2007年11月14日
关键字:
control.cs源代码如下: using System.Windows.Forms ; //定义封装此组件的名称空间 namespace MyControls { //LabledTextBox组件是继承了 UserControl组件的 public class LabeledTextBox : UserControl { //定义本组件的组成结构 private Label myLabel ; private TextBox myTextBox ; public LabeledTextBox ( ) { InitializeComponent ( ) ; } public void InitializeComponent ( ) { //定义一个标签 myLabel = new Label ( ) ; myLabel.Location = new System.Drawing.Point ( 0 , 0 ) ; myLabel.Size = new System.Drawing.Size ( 100 , 20 ) ; //定义一个文本框 myTextBox = new TextBox ( ) ; myTextBox.Location = new System.Drawing.Point ( 105 , 0 ) ; myTextBox.Size =new System.Drawing.Size ( 100 , 20 ) ; //同样要设定所希望的组件大小 this.Size =new System.Drawing.Size ( 205 , 20 ) ; //加入组件 this.Controls.Add ( myLabel ) ; this.Controls.Add ( myTextBox ) ; } //组件中的Text属性,是从文本框的Text的属性派生而来 public override string Text { get { return myTextBox.Text ; } set { myTextBox.Text = value ; } } //创建一个新的属性LabelText,并且此属性的值是通过继承此组件中的标签的 Text属性值 public string LabelText { get { return myLabel.Text ; } set { myLabel.Text = value ; } } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。