this.button1 = new System.Windows.Forms.Button(); this.textBox1 = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // button1 // this.button1.Location = new System.Drawing.Point(8, 16); this.button1.Name = button1; this.button1.Size = new System.Drawing.Size(80, 24); this.button1.TabIndex = 0; this.button1.Text = button1; // // textBox1 // this.textBox1.Location = new System.Drawing.Point(112, 16); this.textBox1.Name = textBox1; this.textBox1.Size = new System.Drawing.Size(160, 20); this.textBox1.TabIndex = 1; this.textBox1.Text = textBox1; // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 273); this.Controls.AddRange(new System.Windows.Forms.Control[] { this.textBox1, this.button1}); this.Name = Form1; this.Text = Form1; this.ResumeLayout(false); } #endregion [STAThread] static void Main() { Application.Run(new SimpleForm()); } } 十六、运行时显示自己定义的图标: //load icon and set to form System.Drawing.Icon ico = new System.Drawing.Icon(@c:\temp\app.ico); this.Icon = ico; 十七、添加组件到ListBox中: private void Form1_Load(object sender, System.EventArgs e) { string str = First item; int i = 23; float flt = 34.98f; listBox1.Items.Add(str); listBox1.Items.Add(i.ToString()); listBox1.Items.Add(flt.ToString()); listBox1.Items.Add(Last Item in the List Box); } 网络方面的: 十八、取得IP地址: using System; using System.Net; class GetIP { public static void Main() { IPHostEntry ipEntry = Dns.GetHostByName (localhost); IPAddress [] IpAddr = ipEntry.AddressList; for (int i = 0; i < IpAddr.Length; i++) { Console.WriteLine (IP Address {0}: {1} , i, IpAddr.ToString ()); } } } 十九、取得机器名称: using System; using System.Net; |