📄 frmremoteclient.cs
字号:
using System;
using System.Text;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
namespace TcpClientSample
{
/// <summary>
/// Summary description for TcpClientForm.
/// </summary>
public class TcpClientForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox ResponseTextBox;
private System.Windows.Forms.TextBox ServerTextBox;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.Button cmdClear;
private System.Windows.Forms.Button cmdConnect;
private System.Windows.Forms.Label lblCommand;
private System.Windows.Forms.TextBox txtServerPort;
private System.Windows.Forms.Label lblServerPort;
private System.Windows.Forms.TextBox txtMessage;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.Label label1;
public TcpClientForm()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.cmdConnect = new System.Windows.Forms.Button();
this.ResponseTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.ServerTextBox = new System.Windows.Forms.TextBox();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.cmdClear = new System.Windows.Forms.Button();
this.lblCommand = new System.Windows.Forms.Label();
this.txtServerPort = new System.Windows.Forms.TextBox();
this.lblServerPort = new System.Windows.Forms.Label();
this.txtMessage = new System.Windows.Forms.TextBox();
//
// cmdConnect
//
this.cmdConnect.Location = new System.Drawing.Point(128, 244);
this.cmdConnect.Size = new System.Drawing.Size(108, 20);
this.cmdConnect.Text = "Connect";
this.cmdConnect.Click += new System.EventHandler(this.button1_Click);
//
// ResponseTextBox
//
this.ResponseTextBox.Location = new System.Drawing.Point(4, 76);
this.ResponseTextBox.Multiline = true;
this.ResponseTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.ResponseTextBox.Size = new System.Drawing.Size(232, 164);
this.ResponseTextBox.Text = "";
//
// label1
//
this.label1.Location = new System.Drawing.Point(4, 8);
this.label1.Size = new System.Drawing.Size(116, 16);
this.label1.Text = "Server IP Address:";
//
// ServerTextBox
//
this.ServerTextBox.Location = new System.Drawing.Point(128, 4);
this.ServerTextBox.Size = new System.Drawing.Size(108, 22);
this.ServerTextBox.Text = "192.168.1.102";
//
// mainMenu1
//
this.mainMenu1.MenuItems.Add(this.menuItem1);
//
// menuItem1
//
this.menuItem1.MenuItems.Add(this.menuItem2);
this.menuItem1.Text = "File";
//
// menuItem2
//
this.menuItem2.Text = "Exit";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// cmdClear
//
this.cmdClear.Location = new System.Drawing.Point(4, 244);
this.cmdClear.Size = new System.Drawing.Size(116, 20);
this.cmdClear.Text = "Clear";
this.cmdClear.Click += new System.EventHandler(this.cmdClear_Click);
//
// lblCommand
//
this.lblCommand.Location = new System.Drawing.Point(4, 56);
this.lblCommand.Size = new System.Drawing.Size(116, 16);
this.lblCommand.Text = "Message Text:";
//
// txtServerPort
//
this.txtServerPort.Location = new System.Drawing.Point(128, 28);
this.txtServerPort.Size = new System.Drawing.Size(108, 22);
this.txtServerPort.Text = "695";
//
// lblServerPort
//
this.lblServerPort.Location = new System.Drawing.Point(3, 32);
this.lblServerPort.Size = new System.Drawing.Size(116, 16);
this.lblServerPort.Text = "Server Port:";
//
// txtMessage
//
this.txtMessage.Location = new System.Drawing.Point(128, 52);
this.txtMessage.Size = new System.Drawing.Size(108, 22);
this.txtMessage.Text = "test";
//
// TcpClientForm
//
this.Controls.Add(this.txtMessage);
this.Controls.Add(this.txtServerPort);
this.Controls.Add(this.lblServerPort);
this.Controls.Add(this.lblCommand);
this.Controls.Add(this.cmdClear);
this.Controls.Add(this.ServerTextBox);
this.Controls.Add(this.label1);
this.Controls.Add(this.cmdConnect);
this.Controls.Add(this.ResponseTextBox);
this.MaximizeBox = false;
this.Menu = this.mainMenu1;
this.MinimizeBox = false;
this.Text = "Remote Client";
}
#endregion
static void Main()
{
Application.Run(new TcpClientForm());
}
private void button1_Click(object sender, System.EventArgs e)
{
cmdConnect.Enabled = false;
Cursor.Current = Cursors.WaitCursor;
RemoteClient remoteClient = new RemoteClient(ServerTextBox.Text, Int32.Parse(txtServerPort.Text));
remoteClient.myEvent += new RemoteClient.EventDelegate(this.RemoteClient_MessageReceived);
//remoteClient.SendMessage("Client response sent at " + DateTime.Now.ToLongTimeString());
remoteClient.SendMessage(txtMessage.Text);
Cursor.Current = Cursors.Default;
cmdConnect.Enabled = true;
}
private void RemoteClient_MessageReceived(object sender, RemoteClientEventArgs e)
{
ResponseTextBox.Text += e.message + "\r\n";
}
private void cmdClear_Click(object sender, System.EventArgs e)
{
ResponseTextBox.Text = String.Empty;
txtMessage.Text = String.Empty;
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -