标题:各位帮个忙 帮逐句翻译下这段代码
取消只看楼主
mfkillua
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-12-22
结帖率:0
已结贴  问题点数:20 回复次数:1 
各位帮个忙 帮逐句翻译下这段代码

using System;
using System.Drawing;
using System.Collections;
using
using System.Windows.Forms;
using System.Data;
using System.Threading;
using
using

namespace 实验 
{

    public class MainForm : System.Windows.Forms.Form
    {

        private components = null;
        private Thread Listener;
        private System.Windows.Forms.Label label1;
        private System.Windows.Forms.RichTextBox richTextBox1;
        private System.Windows.Forms.Label label2;
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.RichTextBox richTextBox2;
        private System.Windows.Forms.Label label3;
        private System.Windows.Forms.GroupBox groupBox1;
        private System.Windows.Forms.TextBox IP;
        private System.Windows.Forms.Label label4;
        private System.Windows.Forms.TextBox NickName;
        private System.Windows.Forms.GroupBox groupBox2;
        private System.Windows.Forms.Splitter splitter1;
        private System.Windows.Forms.GroupBox groupBox3;
        private System.Windows.Forms.Splitter splitter2;
        private System.Windows.Forms.Button button2;
        private TcpListener TcpListener;
        private Thread sends;

        public MainForm()
        {

            InitializeComponent();


        }


        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose(disposing);
        }

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

        private void InitializeComponent()
        {
            this.label1 = new System.Windows.Forms.Label();
            this.richTextBox1 = new System.Windows.Forms.RichTextBox();
            this.label2 = new System.Windows.Forms.Label();
            this.button1 = new System.Windows.Forms.Button();
            this.richTextBox2 = new System.Windows.Forms.RichTextBox();
            this.label3 = new System.Windows.Forms.Label();
            this.groupBox1 = new System.Windows.Forms.GroupBox();
            this.NickName = new System.Windows.Forms.TextBox();
            this.label4 = new System.Windows.Forms.Label();
            this.IP = new System.Windows.Forms.TextBox();
            this.groupBox2 = new System.Windows.Forms.GroupBox();
            this.splitter1 = new System.Windows.Forms.Splitter();
            this.groupBox3 = new System.Windows.Forms.GroupBox();
            this.splitter2 = new System.Windows.Forms.Splitter();
            this.button2 = new System.Windows.Forms.Button();
            this.groupBox1.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.SuspendLayout();
            //
            // label1
            //
            this.label1.ForeColor = System.Drawing.Color.Blue;
            this.label1.Location = new System.Drawing.Point(8, 16);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(80, 16);
            this.label1.TabIndex = 0;
            this.label1.Text = "对方IP地址:";
            //
            // richTextBox1
            //
            this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.richTextBox1.Location = new System.Drawing.Point(3, 36);
            this.richTextBox1.Name = "richTextBox1";
            this.richTextBox1.Size = new System.Drawing.Size(346, 113);
            this.richTextBox1.TabIndex = 1;
            this.richTextBox1.Text = "";
            //
            // label2
            //
            this.label2.Dock = System.Windows.Forms.DockStyle.Top;
            this.label2.ForeColor = System.Drawing.Color.Blue;
            this.label2.Location = new System.Drawing.Point(3, 17);
            this.label2.Name = "label2";
            this.label2.Size = new System.Drawing.Size(346, 16);
            this.label2.TabIndex = 2;
            this.label2.Text = "输入框:";
            //
            // button1
            //
            this.button1.ForeColor = System.Drawing.Color.Black;
            this.button1.Location = new System.Drawing.Point(0, 352);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 3;
            this.button1.Text = "发送";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // richTextBox2
            //
            this.richTextBox2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.richTextBox2.Location = new System.Drawing.Point(3, 36);
            this.richTextBox2.Name = "richTextBox2";
            this.richTextBox2.Size = new System.Drawing.Size(346, 121);
            this.richTextBox2.TabIndex = 4;
            this.richTextBox2.Text = "";
            //
            // label3
            //
            this.label3.Dock = System.Windows.Forms.DockStyle.Top;
            this.label3.ForeColor = System.Drawing.Color.Blue;
            this.label3.Location = new System.Drawing.Point(3, 17);
            this.label3.Name = "label3";
            this.label3.Size = new System.Drawing.Size(346, 16);
            this.label3.TabIndex = 5;
            this.label3.Text = "聊天信息:";
            //
            // groupBox1
            //
            this.groupBox1.Controls.Add(this.NickName);
            this.groupBox1.Controls.Add(this.label4);
            this.groupBox1.Controls.Add(this.IP);
            this.groupBox1.Controls.Add(this.label1);
            this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
            this.groupBox1.Location = new System.Drawing.Point(0, 0);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new System.Drawing.Size(352, 40);
            this.groupBox1.TabIndex = 6;
            this.groupBox1.TabStop = false;
            //
            // NickName
            //
            this.NickName.Location = new System.Drawing.Point(232, 16);
            this.NickName.Name = "NickName";
            this.NickName.Size = new System.Drawing.Size(100, 21);
            this.NickName.TabIndex = 3;
            //
            // label4
            //
            this.label4.ForeColor = System.Drawing.Color.Blue;
            this.label4.Location = new System.Drawing.Point(184, 16);
            this.label4.Name = "label4";
            this.label4.Size = new System.Drawing.Size(48, 16);
            this.label4.TabIndex = 2;
            this.label4.Text = "昵称:";
            //
            // IP
            //
            this.IP.Location = new System.Drawing.Point(80, 16);
            this.IP.Name = "IP";
            this.IP.Size = new System.Drawing.Size(100, 21);
            this.IP.TabIndex = 1;
            //
            // groupBox2
            //
            this.groupBox2.Controls.Add(this.richTextBox2);
            this.groupBox2.Controls.Add(this.splitter1);
            this.groupBox2.Controls.Add(this.label3);
            this.groupBox2.Dock = System.Windows.Forms.DockStyle.Top;
            this.groupBox2.Location = new System.Drawing.Point(0, 40);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new System.Drawing.Size(352, 160);
            this.groupBox2.TabIndex = 7;
            this.groupBox2.TabStop = false;
            //
            // splitter1
            //
            this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
            this.splitter1.Location = new System.Drawing.Point(3, 33);
            this.splitter1.Name = "splitter1";
            this.splitter1.Size = new System.Drawing.Size(346, 3);
            this.splitter1.TabIndex = 6;
            this.splitter1.TabStop = false;
            //
            // groupBox3
            //
            this.groupBox3.Controls.Add(this.richTextBox1);
            this.groupBox3.Controls.Add(this.splitter2);
            this.groupBox3.Controls.Add(this.label2);
            this.groupBox3.Dock = System.Windows.Forms.DockStyle.Top;
            this.groupBox3.Location = new System.Drawing.Point(0, 200);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new System.Drawing.Size(352, 152);
            this.groupBox3.TabIndex = 8;
            this.groupBox3.TabStop = false;
            //
            // splitter2
            //
            this.splitter2.Dock = System.Windows.Forms.DockStyle.Top;
            this.splitter2.Location = new System.Drawing.Point(3, 33);
            this.splitter2.Name = "splitter2";
            this.splitter2.Size = new System.Drawing.Size(346, 3);
            this.splitter2.TabIndex = 3;
            this.splitter2.TabStop = false;
            //
            // button2
            //
            this.button2.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(128)))), ((int)(((byte)(128)))), ((int)(((byte)(255)))));
            this.button2.Location = new System.Drawing.Point(272, 352);
            this.button2.Name = "button2";
            this.button2.Size = new System.Drawing.Size(75, 23);
            this.button2.TabIndex = 9;
            this.button2.Text = "关于";
            this.button2.Click += new System.EventHandler(this.button2_Click);
            //
            // MainForm
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
            this.ClientSize = new System.Drawing.Size(352, 382);
            this.Controls.Add(this.button2);
            this.Controls.Add(this.groupBox3);
            this.Controls.Add(this.groupBox2);
            this.Controls.Add(this.groupBox1);
            this.Controls.Add(this.button1);
            this.MaximumSize = new System.Drawing.Size(500, 416);
            this.Name = "MainForm";
            this.RightToLeftLayout = true;
            this.Text = "简易聊天";
            this.Closed += new System.EventHandler(this.MainForm_Closed);
            this.Load += new System.EventHandler(this.MainForm_Load);
            this.groupBox1.ResumeLayout(false);
            this.groupBox1.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.ResumeLayout(false);

        }
        #endregion


        [STAThread]
        static void Main()
        {
            Application.Run(new MainForm());
        }
        private void StartListen()
        {
            this.TcpListener = new TcpListener(19808);
            this.TcpListener.Start();
            while (true)
            {
                TcpClient TcpClient = this.TcpListener.AcceptTcpClient();
                NetworkStream MyStream = TcpClient.GetStream();
                byte[] bytes = new byte[2048];
                int bytesRead = MyStream.Read(bytes, 0, bytes.Length);
                string message = System.Text.Encoding.UTF8.GetString(bytes, 0, bytesRead);
                this.richTextBox2.Text += message + "\n";
            }
        }

        private void MainForm_Load(object sender, System.EventArgs e)
        {
            this.Listener = new Thread(new ThreadStart(StartListen));
            this.Listener.Start();
        }

        private void MainForm_Closed(object sender, System.EventArgs e)
        {
            if (this.Listener != null)
                this.Listener.Abort();
            if (this.TcpListener != null)
                this.TcpListener.Stop();
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            if (sends == null || !sends.IsAlive)
            {
                sends = new Thread(new ThreadStart(send));
                sends.Start();
            }
            else
                MessageBox.Show("发送过快!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
            MessageBox.Show("本程序由 KILLUA 设计  \n输入对方IP地址,只要双方都打开本程序即可聊天", "警告:", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }

        private void send()
        {
            if (this.IP.Text.Length < 7)
            {
                MessageBox.Show("IP地址错误!", "错误信息:", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (this.richTextBox1.Text.Length < 1)
            {
                return;
            }
            try
            {
                string Message = this.NickName.Text + ":" + this.richTextBox1.Text;
                TcpClient TcpClient = new TcpClient(this.IP.Text, 19808);
                NetworkStream tcpStream = TcpClient.GetStream();
                StreamWriter stream = new StreamWriter(tcpStream);
                stream.Flush();
                stream.Write(Message);
                stream.Close();
                TcpClient.Close();
                this.richTextBox2.AppendText(Message + "\n");
            }
            catch (Exception Err)
            {
                MessageBox.Show(Err.Message, "错误信息:", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            finally
            {
                sends.Abort();
            }
        }
    }
}
搜索更多相关主题的帖子: 翻译 代码 
2010-12-22 14:34
mfkillua
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2010-12-22
得分:0 
实训的老师要我解释......我看不是很懂阿
大家帮帮我把
2010-12-22 18:16



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-329597-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.056760 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved