C\#채 팅 방 의 프레임 워 크 디자인 실현 소스 코드
13631 단어 C\#채 팅 방 과정
QQ 처럼 채 팅 방 이 있 으 려 면 C\#안 은 프로 그래 밍 소프트웨어 입 니 다.하하,text 와 label 은 끌 수 있 으 면 됩 니 다.하하.쉽다하지만 문 자 를 어떻게 표시 하고 문 자 를 어떻게 얻 는 지 는 일이 다.응,내 가 거의 한 개 를 써 서 완 성 했 는데,완 성 된 후에 아주 간단 해,응?자바 와 차이 가 많 지 않 습 니 다.코드 는 다음 과 같 습 니 다.
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(" :
");
this.richTextBox1.AppendText(semsg+"
");
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(" :
");
this.richTextBox1.AppendText(semsg+"
");
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;
}
}
}