📄 frmclient.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Net;
using System.Net.Sockets;
namespace Example_2
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class frmClient : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnServerConnect;
private System.Windows.Forms.Label lblMessage;
private System.Windows.Forms.Button btnExit;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
//user defined variables
private TcpClient objTcpClient;
public frmClient()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnServerConnect = new System.Windows.Forms.Button();
this.lblMessage = new System.Windows.Forms.Label();
this.btnExit = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// btnServerConnect
//
this.btnServerConnect.Location = new System.Drawing.Point(120, 138);
this.btnServerConnect.Name = "btnServerConnect";
this.btnServerConnect.Size = new System.Drawing.Size(72, 25);
this.btnServerConnect.TabIndex = 0;
this.btnServerConnect.Text = "连接(&C)";
this.btnServerConnect.Click += new System.EventHandler(this.btnServerConnect_Click);
//
// lblMessage
//
this.lblMessage.Location = new System.Drawing.Point(6, 8);
this.lblMessage.Name = "lblMessage";
this.lblMessage.Size = new System.Drawing.Size(288, 120);
this.lblMessage.TabIndex = 1;
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(216, 138);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(69, 25);
this.btnExit.TabIndex = 2;
this.btnExit.Text = "退出(&E)";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click);
//
// frmClient
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(304, 169);
this.Controls.Add(this.btnExit);
this.Controls.Add(this.lblMessage);
this.Controls.Add(this.btnServerConnect);
this.MaximizeBox = false;
this.Name = "frmClient";
this.Text = "客户端应用程序";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new frmClient());
}
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void btnServerConnect_Click(object sender, System.EventArgs e)
{
try
{
objTcpClient = new TcpClient();
this.lblMessage.Text = "正在连接中..............";
objTcpClient.Connect("192.168.2.77",8221);
this.lblMessage.Text = "服务器已调用";
}
catch(Exception ex)
{
this.lblMessage.Text = ex.Message;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -