C#有很多值得学习的地方,这里我们主要介绍C#实现网络点对点具体步骤,包括介绍Visual Studio .Net集成开发环境等方面。
C#实现网络点对点具体步骤:
在了解、掌握了关键问题及其解决方法,再实现用Visual C#实现网络点对点通讯程序相对就容易许多,下面是具体的实现步骤:
1.启动Visual Studio .Net,并新建一个Visual C#项目,名称为(Visual C#实现网络点对点通讯程序)。
2.在Visual Studio .Net集成开发环境中的(解决方案资源管理器)窗口中,双击Form1.cs文件,进入Form1.cs文件的编辑界面。
3.在Form1.cs文件的开头,用下列导入命名空间代码替代系统缺省的导入命名空间代码。
- 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的当前窗口切换到(Form1.cs(设计))窗口,并从(工具箱)中的(Windows窗体组件)选项卡中往窗体中拖入下列组件:
四个Button组件;二个ListBox组件;四个TextBox组件;一个StatusBar组件;五个Label组件。并在四个Button组件拖入窗体后,分别在窗体设计界面中双击它们,则系统会在Form1.cs文件中分别产生这四个组件的Click事件对应的处理代码。
5.在(解决方案资源管理器)窗口中,双击Form1.cs文件,进入Form1.cs文件的编辑界面。以下面代码替代系统产生的InitializeComponent过程。下面代码是对上面添加的组件进行初始化:
- 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
【编辑推荐】