扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:阿虎 来源:yesky 2007年11月14日
关键字:
csc /r:system.windows.forms.dll /t:library control.cs |
using MyControls ; |
protected LabeledTextBox name , address , zip ; |
name = new LabeledTextBox ( ) ; name.Location = new System.Drawing.Point ( 5 , 5 ) ; name.LabelText = "姓名:" ; |
sample.cs源程序如下: using System.Windows.Forms ; using MyControls ;//导入组件的名称空间 using System ; public class Form1 : Form { //定义新构建的组件 protected LabeledTextBox name , address , zip ; protected Button show ; public Form1 ( ) { InitializeComponent ( ) ; } public static void Main ( ) { Application.Run ( new Form1 ( ) ) ; } public void InitializeComponent ( ) { //创建新的组件,此组件中就封装了标签和文本框 name = new LabeledTextBox ( ) ; address= new LabeledTextBox ( ) ; zip = new LabeledTextBox ( ) ; show= new Button ( ) ; //设定新组件的属性值,可以看看如何设定Text属性和LabelText属性 name.Location = new System.Drawing.Point ( 5 , 5 ) ; name.LabelText = "姓名:" ; address.Location = new System.Drawing.Point ( 5 , 35 ) ; address.LabelText = "住址:" ; zip.Location = new System.Drawing.Point ( 5 , 70 ) ; zip.LabelText = "邮编:" ; show.Location = new System.Drawing.Point ( 5 , 100 ) ; show.Text = "显示组件属性值" ; show.Size = new System.Drawing.Size (100, 25) ; show.Click += new System.EventHandler ( show_Click ) ; this.Text = "显示自建组件的LabelText属性和Text属性值!" ; this.Controls.Add ( name ) ; this.Controls.Add ( address ) ; this.Controls.Add ( zip ) ; this.Controls.Add ( show ) ; } protected void show_Click ( object sender , EventArgs e ) { string message = name.LabelText + " " + name.Text ; message+="\n" + address.LabelText + " " + address.Text ; message+="\n" + zip.LabelText + " " + zip.Text ; MessageBox.Show ( message ,"组件的LabelText属性和Text属性值如下:") ; } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者