您的位置:首页 > 编程语言 > C#

C# 聊天室的框架设计实现源码

2013-05-13 09:31 316 查看
C#代码

要想QQ一样有聊天室,C#里是个可是编程的软件,呵呵,text和label可以拖就可以了,呵呵。和容易。可是怎样显示字符和怎样获得字符是个事情。嗯,我花了差不多一个是完成了,可是完成之后,好简单的,嗯。与java的差不多,代码如下:

C#代码

Java代码



namespace TcpIp通信

{

partial class Form1

{

/// <summary>

/// 必需的设计器变量。

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

/// <param name="disposing">如果应释放托管资源,为 true;否则为

false。</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.richTextBox2 = new System.Windows.Forms.RichTextBox();

this.button1 = new System.Windows.Forms.Button();

this.label1 = new System.Windows.Forms.Label();

this.label3 = new System.Windows.Forms.Label();

this.SuspendLayout();

this.richTextBox1 = new System.Windows.Forms.RichTextBox();

//

// richTextBox1

//

this.richTextBox1.Location = new System.Drawing.Point(26,

28);

this.richTextBox1.Name = "richTextBox1";

this.richTextBox1.Size = new System.Drawing.Size(395, 241);

this.richTextBox1.TabIndex = 7;

this.richTextBox1.Text = "";

//

// richTextBox2

//

this.richTextBox2.Location = new System.Drawing.Point(40,

299);

this.richTextBox2.Name = "richTextBox2";

this.richTextBox2.Size = new System.Drawing.Size(381, 133);

this.richTextBox2.TabIndex = 2;

this.richTextBox2.Text = "";

this.richTextBox2.TextChanged += new System.EventHandler

(this.seMsg);

//

// button1

//

this.button1.Location = new System.Drawing.Point(346, 438);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(75, 23);

this.button1.TabIndex = 3;

this.button1.Text = "send";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler

(this.button1_Click);

//

// label1

//

this.label1.AutoSize = true;

this.label1.Location = new System.Drawing.Point(183, 281);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(53, 12);

this.label1.TabIndex = 5;

this.label1.Text = "发送信息";

//

// label3

//

this.label3.AutoSize = true;

this.label3.Location = new System.Drawing.Point(185, 13);

this.label3.Name = "label3";

this.label3.Size = new System.Drawing.Size(53, 12);

this.label3.TabIndex = 6;

this.label3.Text = "接受信息";

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F,

12F);

this.AutoScaleMode =

System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(447, 466);

this.Controls.Add(this.label3);

this.Controls.Add(this.label1);

this.Controls.Add(this.button1);

this.Controls.Add(this.richTextBox2);

this.Controls.Add(this.richTextBox1);

this.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);

this.Name = "Form1";

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);

this.PerformLayout();

}

#endregion

private System.Windows.Forms.RichTextBox richTextBox1;

private System.Windows.Forms.RichTextBox richTextBox2;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label3;

}

}

namespace TcpIp通信

{

partial class Form1

{

/// <summary>

/// 必需的设计器变量。

/// </summary>

private System.ComponentModel.IContainer components = null;

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

/// <param name="disposing">如果应释放托管资源,为 true;否则为

false。</param>

protected override void Dispose(bool disposing)

{

if (disposing && (components != null))

{

components.Dispose();

}

base.Dispose(disposing);

}

#region Windows 窗体设计器生成的代码

/// <summary>

/// 设计器支持所需的方法 - 不要

/// 使用代码编辑器修改此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.richTextBox2 = new System.Windows.Forms.RichTextBox();

this.button1 = new System.Windows.Forms.Button();

this.label1 = new System.Windows.Forms.Label();

this.label3 = new System.Windows.Forms.Label();

this.SuspendLayout();

this.richTextBox1 = new System.Windows.Forms.RichTextBox();

//

// richTextBox1

//

this.richTextBox1.Location = new System.Drawing.Point(26,

28);

this.richTextBox1.Name = "richTextBox1";

this.richTextBox1.Size = new System.Drawing.Size(395, 241);

this.richTextBox1.TabIndex = 7;

this.richTextBox1.Text = "";

//

// richTextBox2

//

this.richTextBox2.Location = new System.Drawing.Point(40,

299);

this.richTextBox2.Name = "richTextBox2";

this.richTextBox2.Size = new System.Drawing.Size(381, 133);

this.richTextBox2.TabIndex = 2;

this.richTextBox2.Text = "";

this.richTextBox2.TextChanged += new System.EventHandler

(this.seMsg);

//

// button1

//

this.button1.Location = new System.Drawing.Point(346, 438);

this.button1.Name = "button1";

this.button1.Size = new System.Drawing.Size(75, 23);

this.button1.TabIndex = 3;

this.button1.Text = "send";

this.button1.UseVisualStyleBackColor = true;

this.button1.Click += new System.EventHandler

(this.button1_Click);

//

// label1

//

this.label1.AutoSize = true;

this.label1.Location = new System.Drawing.Point(183, 281);

this.label1.Name = "label1";

this.label1.Size = new System.Drawing.Size(53, 12);

this.label1.TabIndex = 5;

this.label1.Text = "发送信息";

//

// label3

//

this.label3.AutoSize = true;

this.label3.Location = new System.Drawing.Point(185, 13);

this.label3.Name = "label3";

this.label3.Size = new System.Drawing.Size(53, 12);

this.label3.TabIndex = 6;

this.label3.Text = "接受信息";

//

// Form1

//

this.AutoScaleDimensions = new System.Drawing.SizeF(6F,

12F);

this.AutoScaleMode =

System.Windows.Forms.AutoScaleMode.Font;

this.ClientSize = new System.Drawing.Size(447, 466);

this.Controls.Add(this.label3);

this.Controls.Add(this.label1);

this.Controls.Add(this.button1);

this.Controls.Add(this.richTextBox2);

this.Controls.Add(this.richTextBox1);

this.Margin = new System.Windows.Forms.Padding(2, 3, 2, 3);

this.Name = "Form1";

this.Text = "Form1";

this.Load += new System.EventHandler(this.Form1_Load);

this.ResumeLayout(false);

this.PerformLayout();

}

#endregion

private System.Windows.Forms.RichTextBox richTextBox1;

private System.Windows.Forms.RichTextBox richTextBox2;

private System.Windows.Forms.Button button1;

private System.Windows.Forms.Label label1;

private System.Windows.Forms.Label label3;

}

}

C#代码

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

namespace TcpIp通信

{

public partial class Form1 : Form

{

string semsg;

string name;

public Form1()

{

InitializeComponent();

ChatServer();

}

private void button1_Click(object sender, EventArgs e)

{

name = ((Button)sender).Name;

if (name.Equals("button1"))

{

this.richTextBox1.AppendText("服务器说:\n");

this.richTextBox1.AppendText(semsg+"\n");

this.richTextBox2.Text="";

Console.WriteLine("打印成功" + semsg);

}

}

private void Form1_Load(object sender, EventArgs e)

{

}

private void seMsg(object sender, EventArgs e)

{

semsg = ((RichTextBox)sender).Text;

}

}

}

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Net;

using System.Net.Sockets;

namespace TcpIp通信

{

public partial class Form1 : Form

{

string semsg;

string name;

public Form1()

{

InitializeComponent();

ChatServer();

}

private void button1_Click(object sender, EventArgs e)

{

name = ((Button)sender).Name;

if (name.Equals("button1"))

{

this.richTextBox1.AppendText("服务器说:\n");

this.richTextBox1.AppendText(semsg+"\n");

this.richTextBox2.Text="";

Console.WriteLine("打印成功" + semsg);

}

}

private void Form1_Load(object sender, EventArgs e)

{

}

private void seMsg(object sender, EventArgs e)

{

semsg = ((RichTextBox)sender).Text;

}

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐