?? chatclient.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;
using System.Threading;
namespace ChatClient
{
public class ChatClientForm : System.Windows.Forms.Form
{
private System.Windows.Forms.Button btnSend;
private System.Windows.Forms.ListBox lstUsers;
private System.Windows.Forms.Label label2;
/// <summary>
/// 必需的設計器變量。
/// </summary>
private System.ComponentModel.Container components = null;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.TextBox txtHost;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtPort;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Button btnLogin;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox tbSendContent;
private System.Windows.Forms.RichTextBox rtbMsg;
private System.Windows.Forms.Button btnColor;
//與服務器的連接
TcpClient tcpClient;
//與服務器數據交互的流通道
private NetworkStream Stream;
//客戶端的狀態
private static string CLOSED = "closed";
private static string CONNECTED = "connected";
private System.Windows.Forms.TextBox tbUserName;
private System.Windows.Forms.CheckBox cbPrivate;
private string state = CLOSED;
private bool stopFlag;
private Color color;
public ChatClientForm()
{
//
// Windows 窗體設計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調用后添加任何構造函數代碼
//
}
/// <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.tbSendContent = new System.Windows.Forms.TextBox();
this.btnSend = new System.Windows.Forms.Button();
this.lstUsers = new System.Windows.Forms.ListBox();
this.cbPrivate = new System.Windows.Forms.CheckBox();
this.label2 = new System.Windows.Forms.Label();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.btnExit = new System.Windows.Forms.Button();
this.btnLogin = new System.Windows.Forms.Button();
this.tbUserName = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.txtPort = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.txtHost = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.rtbMsg = new System.Windows.Forms.RichTextBox();
this.btnColor = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// tbSendContent
//
this.tbSendContent.Location = new System.Drawing.Point(280, 448);
this.tbSendContent.Multiline = true;
this.tbSendContent.Name = "tbSendContent";
this.tbSendContent.Size = new System.Drawing.Size(472, 112);
this.tbSendContent.TabIndex = 0;
this.tbSendContent.Text = "";
//
// btnSend
//
this.btnSend.Location = new System.Drawing.Point(760, 448);
this.btnSend.Name = "btnSend";
this.btnSend.TabIndex = 1;
this.btnSend.Text = "發送(&A)";
this.btnSend.Click += new System.EventHandler(this.btnSend_Click);
//
// lstUsers
//
this.lstUsers.Location = new System.Drawing.Point(16, 112);
this.lstUsers.Name = "lstUsers";
this.lstUsers.ScrollAlwaysVisible = true;
this.lstUsers.Size = new System.Drawing.Size(248, 459);
this.lstUsers.TabIndex = 2;
//
// cbPrivate
//
this.cbPrivate.Location = new System.Drawing.Point(280, 408);
this.cbPrivate.Name = "cbPrivate";
this.cbPrivate.Size = new System.Drawing.Size(87, 22);
this.cbPrivate.TabIndex = 7;
this.cbPrivate.Text = "悄悄話";
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 88);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(120, 21);
this.label2.TabIndex = 9;
this.label2.Text = "當前在線用戶列表:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.btnExit);
this.groupBox1.Controls.Add(this.btnLogin);
this.groupBox1.Controls.Add(this.tbUserName);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.txtPort);
this.groupBox1.Controls.Add(this.label4);
this.groupBox1.Controls.Add(this.txtHost);
this.groupBox1.Controls.Add(this.label5);
this.groupBox1.Location = new System.Drawing.Point(16, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(816, 72);
this.groupBox1.TabIndex = 21;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "聊天服務器設置";
//
// btnExit
//
this.btnExit.Location = new System.Drawing.Point(712, 32);
this.btnExit.Name = "btnExit";
this.btnExit.Size = new System.Drawing.Size(62, 22);
this.btnExit.TabIndex = 25;
this.btnExit.Text = "離開";
this.btnExit.Click += new System.EventHandler(this.btnExit_Click_1);
//
// btnLogin
//
this.btnLogin.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnLogin.Location = new System.Drawing.Point(640, 32);
this.btnLogin.Name = "btnLogin";
this.btnLogin.Size = new System.Drawing.Size(62, 21);
this.btnLogin.TabIndex = 24;
this.btnLogin.Text = "登入";
this.btnLogin.Click += new System.EventHandler(this.btnLogin_Click);
//
// tbUserName
//
this.tbUserName.Location = new System.Drawing.Point(448, 32);
this.tbUserName.Name = "tbUserName";
this.tbUserName.Size = new System.Drawing.Size(84, 20);
this.tbUserName.TabIndex = 22;
this.tbUserName.Text = "";
//
// label3
//
this.label3.Location = new System.Drawing.Point(368, 32);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(83, 21);
this.label3.TabIndex = 23;
this.label3.Text = "用戶名:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtPort
//
this.txtPort.Location = new System.Drawing.Point(296, 32);
this.txtPort.Name = "txtPort";
this.txtPort.Size = new System.Drawing.Size(46, 20);
this.txtPort.TabIndex = 21;
this.txtPort.Text = "1234";
//
// label4
//
this.label4.Location = new System.Drawing.Point(216, 32);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 22);
this.label4.TabIndex = 20;
this.label4.Text = "端口號:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// txtHost
//
this.txtHost.Location = new System.Drawing.Point(96, 32);
this.txtHost.Name = "txtHost";
this.txtHost.Size = new System.Drawing.Size(104, 20);
this.txtHost.TabIndex = 19;
this.txtHost.Text = "127.0.0.1";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 32);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(83, 22);
this.label5.TabIndex = 18;
this.label5.Text = "服務器地址:";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label1
//
this.label1.Location = new System.Drawing.Point(280, 88);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 21);
this.label1.TabIndex = 22;
this.label1.Text = "系統消息:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// rtbMsg
//
this.rtbMsg.Location = new System.Drawing.Point(280, 112);
this.rtbMsg.Name = "rtbMsg";
this.rtbMsg.Size = new System.Drawing.Size(552, 288);
this.rtbMsg.TabIndex = 25;
this.rtbMsg.Text = "";
//
// btnColor
//
this.btnColor.Location = new System.Drawing.Point(760, 488);
this.btnColor.Name = "btnColor";
this.btnColor.TabIndex = 28;
this.btnColor.Text = "顏色";
this.btnColor.Click += new System.EventHandler(this.btnColor_Click);
//
// ChatClientForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(848, 589);
this.Controls.Add(this.btnColor);
this.Controls.Add(this.rtbMsg);
this.Controls.Add(this.label1);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -