C#實(shí)現(xiàn)網(wǎng)絡(luò)點(diǎn)對(duì)點(diǎn)具體步驟
C#有很多值得學(xué)習(xí)的地方,這里我們主要介紹C#實(shí)現(xiàn)網(wǎng)絡(luò)點(diǎn)對(duì)點(diǎn)具體步驟,包括介紹Visual Studio .Net集成開(kāi)發(fā)環(huán)境等方面。
C#實(shí)現(xiàn)網(wǎng)絡(luò)點(diǎn)對(duì)點(diǎn)具體步驟:
在了解、掌握了關(guān)鍵問(wèn)題及其解決方法,再實(shí)現(xiàn)用Visual C#實(shí)現(xiàn)網(wǎng)絡(luò)點(diǎn)對(duì)點(diǎn)通訊程序相對(duì)就容易許多,下面是具體的實(shí)現(xiàn)步驟:
1.啟動(dòng)Visual Studio .Net,并新建一個(gè)Visual C#項(xiàng)目,名稱為(Visual C#實(shí)現(xiàn)網(wǎng)絡(luò)點(diǎn)對(duì)點(diǎn)通訊程序)。
2.在Visual Studio .Net集成開(kāi)發(fā)環(huán)境中的(解決方案資源管理器)窗口中,雙擊Form1.cs文件,進(jìn)入Form1.cs文件的編輯界面。
3.在Form1.cs文件的開(kāi)頭,用下列導(dǎo)入命名空間代碼替代系統(tǒng)缺省的導(dǎo)入命名空間代碼。
- using System ;
- using System.Drawing ;
- using System.Collections ;
- using System.ComponentModel ;
- using System.Windows.Forms ;
- using System.Data ;
- using System.Net.Sockets ;
- using System.Net ;
- using System.IO ;
- using System.Text ;
- using System.Threading ;
4.再把Visual Studio.Net的當(dāng)前窗口切換到(Form1.cs(設(shè)計(jì)))窗口,并從(工具箱)中的(Windows窗體組件)選項(xiàng)卡中往窗體中拖入下列組件:
四個(gè)Button組件;二個(gè)ListBox組件;四個(gè)TextBox組件;一個(gè)StatusBar組件;五個(gè)Label組件。并在四個(gè)Button組件拖入窗體后,分別在窗體設(shè)計(jì)界面中雙擊它們,則系統(tǒng)會(huì)在Form1.cs文件中分別產(chǎn)生這四個(gè)組件的Click事件對(duì)應(yīng)的處理代碼。
5.在(解決方案資源管理器)窗口中,雙擊Form1.cs文件,進(jìn)入Form1.cs文件的編輯界面。以下面代碼替代系統(tǒng)產(chǎn)生的InitializeComponent過(guò)程。下面代碼是對(duì)上面添加的組件進(jìn)行初始化:
- private void InitializeComponent ( )
- {
- this.listBox1 = new System.Windows.Forms.ListBox ( ) ;
- this.textBox1 = new System.Windows.Forms.TextBox ( ) ;
- this.label3 = new System.Windows.Forms.Label ( ) ;
- this.label2 = new System.Windows.Forms.Label ( ) ;
- this.textBox3 = new System.Windows.Forms.TextBox ( ) ;
- this.button1 = new System.Windows.Forms.Button ( ) ;
- this.textBox2 = new System.Windows.Forms.TextBox ( ) ;
- this.label1 = new System.Windows.Forms.Label ( ) ;
- this.label4 = new System.Windows.Forms.Label ( ) ;
- this.label5 = new System.Windows.Forms.Label ( ) ;
- this.button2 = new System.Windows.Forms.Button ( ) ;
- this.button3 = new System.Windows.Forms.Button ( ) ;
- this.button4 = new System.Windows.Forms.Button ( ) ;
- this.textBox4 = new System.Windows.Forms.TextBox ( ) ;
- this.statusBar1 = new System.Windows.Forms.StatusBar ( ) ;
- this.statusBarPanel1 = new System.Windows.Forms.StatusBarPanel( );
- this.statusBarPanel2 = new System.Windows.Forms.StatusBarPanel( );
- this.label6 = new System.Windows.Forms.Label ( ) ;
- this.listBox2 = new System.Windows.Forms.ListBox ( ) ;
- ( ( System.ComponentModel.ISupportInitialize )
- ( this.statusBarPanel1 ) ).BeginInit ( ) ;
- ( ( System.ComponentModel.ISupportInitialize )
- ( this.statusBarPanel2 ) ).BeginInit ( ) ;
- this.SuspendLayout ( ) ;
- this.listBox1.ItemHeight = 12 ;
- this.listBox1.Location = new System.Drawing.Point ( 122 , 110 ) ;
- this.listBox1.Name = "listBox1" ;
- this.listBox1.Size = new System.Drawing.Size ( 212 , 88 ) ;
- this.listBox1.TabIndex = 4 ;
- this.textBox1.Location = new System.Drawing.Point ( 122 , 18 ) ;
- this.textBox1.Name = "textBox1" ;
- this.textBox1.Size = new System.Drawing.Size ( 210 , 21 ) ;
- this.textBox1.TabIndex = 1 ;
- this.textBox1.Text = "" ;
- this.label3.Location = new System.Drawing.Point ( 220 , 52 ) ;
- this.label3.Na
【編輯推薦】