⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form1.cs

📁 一个聊天程序
💻 CS
字号:
namespace RemotingChat
{
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.WinForms;
    using System.Data;

    /// <summary>
    ///    Summary description for Form1.
    /// </summary>
    public class Form1 : System.WinForms.Form
    {
        /// <summary>
        ///    Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components;
		private System.WinForms.Label label1;
		private System.WinForms.TextBox textBox2;
		private System.WinForms.TextBox textBox1;
		private System.WinForms.Button button3;
		private System.WinForms.Button button2;
		private System.WinForms.Button button1;
		private System.WinForms.RichTextBox richTextBox1;
		private ChatImpl ci=null;
		private bool login=false;
		protected void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
		{
			ci=null;
			System.GC.RunFinalizers();
			Application.ExitThread();
			Application.Exit();

		}
        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();
			ci=new ChatImpl(this);
			
            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        ///    Clean up any resources being used.
        /// </summary>
        public override void Dispose()
        {
            base.Dispose();
            components.Dispose();
        }

        /// <summary>
        ///    Required method for Designer support - do not modify
        ///    the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container ();
			this.button1 = new System.WinForms.Button ();
			this.richTextBox1 = new System.WinForms.RichTextBox ();
			this.button3 = new System.WinForms.Button ();
			this.button2 = new System.WinForms.Button ();
			this.textBox1 = new System.WinForms.TextBox ();
			this.textBox2 = new System.WinForms.TextBox ();
			this.label1 = new System.WinForms.Label ();
			//@this.TrayHeight = 0;
			//@this.TrayLargeIcon = false;
			//@this.TrayAutoArrange = true;
			button1.Location = new System.Drawing.Point (424, 248);
			button1.Size = new System.Drawing.Size (64, 24);
			button1.TabIndex = 1;
			button1.Text = "Quit";
			button1.Click += new System.EventHandler (this.button1_Click);
			richTextBox1.Size = new System.Drawing.Size (480, 200);
			richTextBox1.TabIndex = 0;
			richTextBox1.Location = new System.Drawing.Point (8, 8);
			button3.Location = new System.Drawing.Point (424, 216);
			button3.Size = new System.Drawing.Size (64, 24);
			button3.TabIndex = 3;
			button3.Text = "ListAll";
			button3.Click += new System.EventHandler (this.button3_Click);
			button2.Location = new System.Drawing.Point (360, 216);
			button2.Size = new System.Drawing.Size (64, 24);
			button2.TabIndex = 2;
			button2.Text = "Send";
			button2.Click += new System.EventHandler (this.button2_Click);
			textBox1.Location = new System.Drawing.Point (8, 216);
			textBox1.TabIndex = 4;
			textBox1.Size = new System.Drawing.Size (344, 20);
			textBox2.Location = new System.Drawing.Point (200, 248);
			textBox2.Text = "LocalHost";
			textBox2.TabIndex = 5;
			textBox2.Size = new System.Drawing.Size (152, 20);
			label1.Location = new System.Drawing.Point (120, 248);
			label1.Text = "Server Name";
			label1.Size = new System.Drawing.Size (72, 24);
			label1.TabIndex = 6;
			this.Text = "Form1";
			this.MaximizeBox = false;
			this.StartPosition = System.WinForms.FormStartPosition.CenterScreen;
			this.AutoScaleBaseSize = new System.Drawing.Size (5, 13);
			this.ClientSize = new System.Drawing.Size (496, 277);
			this.Closing += new System.ComponentModel.CancelEventHandler (this.Form1_Closing);
			this.Controls.Add (this.label1);
			this.Controls.Add (this.textBox2);
			this.Controls.Add (this.textBox1);
			this.Controls.Add (this.button3);
			this.Controls.Add (this.button2);
			this.Controls.Add (this.button1);
			this.Controls.Add (this.richTextBox1);
		}
		public void UpdateStatus(string strMessage)
		{
			richTextBox1.Text+=strMessage;
		}

		protected void button2_Click (object sender, System.EventArgs e)
		{
			//Add User
			if(!login)
			{
				ci.Server=textBox2.Text;
				ci.Name=textBox1.Text;
				ci.registerChatter();
				textBox2.Enabled=false;
				login=true;
			}
			else
			//Send Message
			{
				ci.handleEvent(ChatImpl.myActions.SEND_MESSAGE,textBox1.Text);	
			}
		}

		protected void button3_Click (object sender, System.EventArgs e)
		{
			//List All User
			ci.handleEvent(ChatImpl.myActions.SEND_LISTALL,"");
		}

		protected void button1_Click (object sender, System.EventArgs e)
		{
			//Disconnect
			ci.handleEvent(ChatImpl.myActions.SEND_QUIT,"");
			login=false;
			this.Close();
		}
		
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public static void Main(string[] args) 
        {
            Application.Run(new Form1());
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -