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

来源:互联网 发布:淘宝卖的最奇葩的东西 编辑:程序博客网 时间:2024/05/01 19:45

C#代码    

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

  C#代码  

Java代码  收藏代码
  1. namespace TcpIp通信     
  2. {     
  3.     partial class Form1     
  4.     {     
  5.         /// <summary>     
  6.         /// 必需的设计器变量。     
  7.         /// </summary>     
  8.         private System.ComponentModel.IContainer components = null;     
  9.     
  10.         /// <summary>     
  11.         /// 清理所有正在使用的资源。     
  12.         /// </summary>     
  13.         /// <param name="disposing">如果应释放托管资源,为 true;否则为      
  14.     
  15. false。</param>     
  16.         protected override void Dispose(bool disposing)     
  17.         {     
  18.             if (disposing && (components != null))     
  19.             {     
  20.                 components.Dispose();     
  21.             }     
  22.             base.Dispose(disposing);     
  23.         }    
  24.    
  25.         #region Windows 窗体设计器生成的代码     
  26.     
  27.         /// <summary>     
  28.         /// 设计器支持所需的方法 - 不要     
  29.         /// 使用代码编辑器修改此方法的内容。     
  30.         /// </summary>     
  31.         private void InitializeComponent()     
  32.         {     
  33.                 
  34.             this.richTextBox2 = new System.Windows.Forms.RichTextBox();     
  35.             this.button1 = new System.Windows.Forms.Button();     
  36.             this.label1 = new System.Windows.Forms.Label();     
  37.             this.label3 = new System.Windows.Forms.Label();     
  38.             this.SuspendLayout();     
  39.             this.richTextBox1 = new System.Windows.Forms.RichTextBox();     
  40.     
  41.             //      
  42.             // richTextBox1     
  43.             //      
  44.                 
  45.             this.richTextBox1.Location = new System.Drawing.Point(26,      
  46.     
  47. 28);     
  48.             this.richTextBox1.Name = "richTextBox1";     
  49.             this.richTextBox1.Size = new System.Drawing.Size(395241);     
  50.             this.richTextBox1.TabIndex = 7;     
  51.             this.richTextBox1.Text = "";       
  52.             //      
  53.             // richTextBox2     
  54.             //      
  55.             this.richTextBox2.Location = new System.Drawing.Point(40,      
  56.     
  57. 299);     
  58.             this.richTextBox2.Name = "richTextBox2";     
  59.             this.richTextBox2.Size = new System.Drawing.Size(381133);     
  60.             this.richTextBox2.TabIndex = 2;     
  61.             this.richTextBox2.Text = "";     
  62.             this.richTextBox2.TextChanged += new System.EventHandler     
  63.     
  64. (this.seMsg);     
  65.             //      
  66.             // button1     
  67.             //      
  68.             this.button1.Location = new System.Drawing.Point(346438);     
  69.             this.button1.Name = "button1";     
  70.             this.button1.Size = new System.Drawing.Size(7523);     
  71.             this.button1.TabIndex = 3;     
  72.             this.button1.Text = "send";     
  73.             this.button1.UseVisualStyleBackColor = true;     
  74.             this.button1.Click += new System.EventHandler     
  75.     
  76. (this.button1_Click);     
  77.             //      
  78.             // label1     
  79.             //      
  80.             this.label1.AutoSize = true;     
  81.             this.label1.Location = new System.Drawing.Point(183281);     
  82.             this.label1.Name = "label1";     
  83.             this.label1.Size = new System.Drawing.Size(5312);     
  84.             this.label1.TabIndex = 5;     
  85.             this.label1.Text = "发送信息";     
  86.             //      
  87.             // label3     
  88.             //      
  89.             this.label3.AutoSize = true;     
  90.             this.label3.Location = new System.Drawing.Point(18513);     
  91.             this.label3.Name = "label3";     
  92.             this.label3.Size = new System.Drawing.Size(5312);     
  93.             this.label3.TabIndex = 6;     
  94.             this.label3.Text = "接受信息";     
  95.             //      
  96.             // Form1     
  97.             //      
  98.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F,      
  99.     
  100. 12F);     
  101.             this.AutoScaleMode =      
  102.     
  103. System.Windows.Forms.AutoScaleMode.Font;     
  104.             this.ClientSize = new System.Drawing.Size(447466);     
  105.             this.Controls.Add(this.label3);     
  106.             this.Controls.Add(this.label1);     
  107.             this.Controls.Add(this.button1);     
  108.             this.Controls.Add(this.richTextBox2);     
  109.             this.Controls.Add(this.richTextBox1);     
  110.             this.Margin = new System.Windows.Forms.Padding(2323);     
  111.             this.Name = "Form1";     
  112.             this.Text = "Form1";     
  113.             this.Load += new System.EventHandler(this.Form1_Load);     
  114.             this.ResumeLayout(false);     
  115.             this.PerformLayout();     
  116.     
  117.         }    
  118.    
  119.         #endregion     
  120.     
  121.         private System.Windows.Forms.RichTextBox richTextBox1;     
  122.         private System.Windows.Forms.RichTextBox richTextBox2;     
  123.         private System.Windows.Forms.Button button1;     
  124.              
  125.         private System.Windows.Forms.Label label1;     
  126.         private System.Windows.Forms.Label label3;     
  127.     }     
  128. }    
  129.   
  130. namespace TcpIp通信  
  131. {  
  132.     partial class Form1  
  133.     {  
  134.         /// <summary>  
  135.         /// 必需的设计器变量。  
  136.         /// </summary>  
  137.         private System.ComponentModel.IContainer components = null;  
  138.   
  139.         /// <summary>  
  140.         /// 清理所有正在使用的资源。  
  141.         /// </summary>  
  142.         /// <param name="disposing">如果应释放托管资源,为 true;否则为   
  143.   
  144. false。</param>  
  145.         protected override void Dispose(bool disposing)  
  146.         {  
  147.             if (disposing && (components != null))  
  148.             {  
  149.                 components.Dispose();  
  150.             }  
  151.             base.Dispose(disposing);  
  152.         }  
  153.   
  154.         #region Windows 窗体设计器生成的代码  
  155.   
  156.         /// <summary>  
  157.         /// 设计器支持所需的方法 - 不要  
  158.         /// 使用代码编辑器修改此方法的内容。  
  159.         /// </summary>  
  160.         private void InitializeComponent()  
  161.         {  
  162.              
  163.             this.richTextBox2 = new System.Windows.Forms.RichTextBox();  
  164.             this.button1 = new System.Windows.Forms.Button();  
  165.             this.label1 = new System.Windows.Forms.Label();  
  166.             this.label3 = new System.Windows.Forms.Label();  
  167.             this.SuspendLayout();  
  168.             this.richTextBox1 = new System.Windows.Forms.RichTextBox();  
  169.   
  170.             //   
  171.             // richTextBox1  
  172.             //   
  173.              
  174.             this.richTextBox1.Location = new System.Drawing.Point(26,   
  175.   
  176. 28);  
  177.             this.richTextBox1.Name = "richTextBox1";  
  178.             this.richTextBox1.Size = new System.Drawing.Size(395241);  
  179.             this.richTextBox1.TabIndex = 7;  
  180.             this.richTextBox1.Text = "";    
  181.             //   
  182.             // richTextBox2  
  183.             //   
  184.             this.richTextBox2.Location = new System.Drawing.Point(40,   
  185.   
  186. 299);  
  187.             this.richTextBox2.Name = "richTextBox2";  
  188.             this.richTextBox2.Size = new System.Drawing.Size(381133);  
  189.             this.richTextBox2.TabIndex = 2;  
  190.             this.richTextBox2.Text = "";  
  191.             this.richTextBox2.TextChanged += new System.EventHandler  
  192.   
  193. (this.seMsg);  
  194.             //   
  195.             // button1  
  196.             //   
  197.             this.button1.Location = new System.Drawing.Point(346438);  
  198.             this.button1.Name = "button1";  
  199.             this.button1.Size = new System.Drawing.Size(7523);  
  200.             this.button1.TabIndex = 3;  
  201.             this.button1.Text = "send";  
  202.             this.button1.UseVisualStyleBackColor = true;  
  203.             this.button1.Click += new System.EventHandler  
  204.   
  205. (this.button1_Click);  
  206.             //   
  207.             // label1  
  208.             //   
  209.             this.label1.AutoSize = true;  
  210.             this.label1.Location = new System.Drawing.Point(183281);  
  211.             this.label1.Name = "label1";  
  212.             this.label1.Size = new System.Drawing.Size(5312);  
  213.             this.label1.TabIndex = 5;  
  214.             this.label1.Text = "发送信息";  
  215.             //   
  216.             // label3  
  217.             //   
  218.             this.label3.AutoSize = true;  
  219.             this.label3.Location = new System.Drawing.Point(18513);  
  220.             this.label3.Name = "label3";  
  221.             this.label3.Size = new System.Drawing.Size(5312);  
  222.             this.label3.TabIndex = 6;  
  223.             this.label3.Text = "接受信息";  
  224.             //   
  225.             // Form1  
  226.             //   
  227.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F,   
  228.   
  229. 12F);  
  230.             this.AutoScaleMode =   
  231.   
  232. System.Windows.Forms.AutoScaleMode.Font;  
  233.             this.ClientSize = new System.Drawing.Size(447466);  
  234.             this.Controls.Add(this.label3);  
  235.             this.Controls.Add(this.label1);  
  236.             this.Controls.Add(this.button1);  
  237.             this.Controls.Add(this.richTextBox2);  
  238.             this.Controls.Add(this.richTextBox1);  
  239.             this.Margin = new System.Windows.Forms.Padding(2323);  
  240.             this.Name = "Form1";  
  241.             this.Text = "Form1";  
  242.             this.Load += new System.EventHandler(this.Form1_Load);  
  243.             this.ResumeLayout(false);  
  244.             this.PerformLayout();  
  245.   
  246.         }  
  247.   
  248.         #endregion  
  249.   
  250.         private System.Windows.Forms.RichTextBox richTextBox1;  
  251.         private System.Windows.Forms.RichTextBox richTextBox2;  
  252.         private System.Windows.Forms.Button button1;  
  253.           
  254.         private System.Windows.Forms.Label label1;  
  255.         private System.Windows.Forms.Label label3;  
  256.     }  
  257. }   
  258. C#代码    
  259. using System;     
  260. using System.Collections.Generic;     
  261. using System.ComponentModel;     
  262. using System.Data;     
  263. using System.Drawing;     
  264. using System.Linq;     
  265. using System.Text;     
  266. using System.Windows.Forms;     
  267. using System.Net;     
  268. using System.Net.Sockets;     
  269.     
  270. namespace TcpIp通信     
  271. {     
  272.     public partial class Form1 : Form     
  273.     {     
  274.     
  275.         string semsg;     
  276.         string name;     
  277.             
  278.         public Form1()     
  279.         {     
  280.             InitializeComponent();     
  281.             ChatServer();     
  282.         }     
  283.         private void button1_Click(object sender, EventArgs e)     
  284.         {     
  285.     
  286.             name = ((Button)sender).Name;     
  287.     
  288.                 
  289.             if (name.Equals("button1"))     
  290.             {     
  291.                 this.richTextBox1.AppendText("服务器说:\n");     
  292.                 this.richTextBox1.AppendText(semsg+"\n");     
  293.                 this.richTextBox2.Text="";     
  294.                 Console.WriteLine("打印成功" + semsg);     
  295.             }     
  296.     
  297.         }     
  298.         private void Form1_Load(object sender, EventArgs e)     
  299.         {     
  300.     
  301.         }     
  302.              
  303.         private void seMsg(object sender, EventArgs e)     
  304.         {     
  305.     
  306.             semsg = ((RichTextBox)sender).Text;     
  307.     
  308.                 
  309.         }     
  310.    }     
  311. }    
  312.   
  313. using System;  
  314. using System.Collections.Generic;  
  315. using System.ComponentModel;  
  316. using System.Data;  
  317. using System.Drawing;  
  318. using System.Linq;  
  319. using System.Text;  
  320. using System.Windows.Forms;  
  321. using System.Net;  
  322. using System.Net.Sockets;  
  323.   
  324. namespace TcpIp通信  
  325. {  
  326.     public partial class Form1 : Form  
  327.     {  
  328.   
  329.         string semsg;  
  330.         string name;  
  331.          
  332.         public Form1()  
  333.         {  
  334.             InitializeComponent();  
  335.             ChatServer();  
  336.         }  
  337.         private void button1_Click(object sender, EventArgs e)  
  338.         {  
  339.   
  340.             name = ((Button)sender).Name;  
  341.   
  342.              
  343.             if (name.Equals("button1"))  
  344.             {  
  345.                 this.richTextBox1.AppendText("服务器说:\n");  
  346.                 this.richTextBox1.AppendText(semsg+"\n");  
  347.                 this.richTextBox2.Text="";  
  348.                 Console.WriteLine("打印成功" + semsg);  
  349.             }  
  350.   
  351.         }  
  352.         private void Form1_Load(object sender, EventArgs e)  
  353.         {  
  354.   
  355.         }  
  356.           
  357.         private void seMsg(object sender, EventArgs e)  
  358.         {  
  359.   
  360.             semsg = ((RichTextBox)sender).Text;  
  361.   
  362.              
  363.         }  
  364.    }  
  365. }  
原创粉丝点击