C# 聊天室的框架设计实现源码
C#代码
要想QQ一样有聊天室,C#里是个可是编程的软件,呵呵,text和label可以拖就可以了,呵呵。和容易。可是怎样显示字符和怎样获得字符是个事情。嗯,我花了差不多一个是完成了,可是完成之后,好简单的,嗯。与java的差不多,代码如下:
C#代码
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;
}
}
}
<!--EndFragment-->
推荐阅读
-
Python Django框架实现商城项目源码加设计文档和注释
-
解析C#设计模式编程中适配器模式的实现
-
express框架实现基于Websocket建立的简易聊天室
-
Laravel框架实现简单的学生信息管理平台案例【附源码下载】
-
C#实现的Windows剪贴板监视器功能实例【附demo源码下载】
-
C#实现导出List数据到xml文件的方法【附demo源码下载】
-
ASP.NET MVC+EF框架+EasyUI实现权限管理系列(2)-数据库访问层的设计Demo
-
iOS实现换肤功能的简单处理框架(附源码)
-
C# 实现简易的串口监视上位机功能附源码下载
-
构建NetCore应用框架之实战篇(五):BitAdminCore框架1.0登录功能设计实现及源码