Click here to Skip to main content
15,896,912 members
Articles / Mobile Apps

Creating Desktop Application Remote Controls with the .NET Compact Framework (Part 1)

Rate me:
Please Sign up or sign in to vote.
4.65/5 (32 votes)
31 Jan 2004CPOL3 min read 237.9K   5K   105  
This article lays down the basic groundwork for creating desktop application remote controls with the .NET Compact Framework.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;


namespace TcpListenerSample
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Button cmdExit;
		private System.Windows.Forms.TextBox txtInfo;
		private System.Windows.Forms.Button cmdStart;
		private System.Windows.Forms.Button cmdClear;
		private System.Windows.Forms.Label lblServerPort;
		private System.Windows.Forms.TextBox txtServerPort;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox txtMessage;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Form1()
		{
			//
			// 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 )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			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.txtInfo = new System.Windows.Forms.TextBox();
			this.cmdExit = new System.Windows.Forms.Button();
			this.cmdStart = new System.Windows.Forms.Button();
			this.cmdClear = new System.Windows.Forms.Button();
			this.lblServerPort = new System.Windows.Forms.Label();
			this.txtServerPort = new System.Windows.Forms.TextBox();
			this.label1 = new System.Windows.Forms.Label();
			this.txtMessage = new System.Windows.Forms.TextBox();
			this.SuspendLayout();
			// 
			// txtInfo
			// 
			this.txtInfo.Location = new System.Drawing.Point(0, 0);
			this.txtInfo.Multiline = true;
			this.txtInfo.Name = "txtInfo";
			this.txtInfo.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.txtInfo.Size = new System.Drawing.Size(292, 192);
			this.txtInfo.TabIndex = 0;
			this.txtInfo.Text = "";
			// 
			// cmdExit
			// 
			this.cmdExit.Location = new System.Drawing.Point(4, 240);
			this.cmdExit.Name = "cmdExit";
			this.cmdExit.Size = new System.Drawing.Size(88, 23);
			this.cmdExit.TabIndex = 1;
			this.cmdExit.Text = "Exit";
			this.cmdExit.Click += new System.EventHandler(this.cmdExit_Click);
			// 
			// cmdStart
			// 
			this.cmdStart.Location = new System.Drawing.Point(204, 240);
			this.cmdStart.Name = "cmdStart";
			this.cmdStart.Size = new System.Drawing.Size(84, 23);
			this.cmdStart.TabIndex = 2;
			this.cmdStart.Text = "Start";
			this.cmdStart.Click += new System.EventHandler(this.cmdStart_Click);
			// 
			// cmdClear
			// 
			this.cmdClear.Location = new System.Drawing.Point(96, 240);
			this.cmdClear.Name = "cmdClear";
			this.cmdClear.Size = new System.Drawing.Size(88, 23);
			this.cmdClear.TabIndex = 3;
			this.cmdClear.Text = "Clear";
			this.cmdClear.Click += new System.EventHandler(this.cmdReset_Click);
			// 
			// lblServerPort
			// 
			this.lblServerPort.Location = new System.Drawing.Point(8, 196);
			this.lblServerPort.Name = "lblServerPort";
			this.lblServerPort.Size = new System.Drawing.Size(84, 16);
			this.lblServerPort.TabIndex = 4;
			this.lblServerPort.Text = "Server Port:";
			// 
			// txtServerPort
			// 
			this.txtServerPort.Location = new System.Drawing.Point(96, 192);
			this.txtServerPort.Name = "txtServerPort";
			this.txtServerPort.Size = new System.Drawing.Size(88, 20);
			this.txtServerPort.TabIndex = 5;
			this.txtServerPort.Text = "695";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 220);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(84, 16);
			this.label1.TabIndex = 6;
			this.label1.Text = "Response Text:";
			// 
			// txtMessage
			// 
			this.txtMessage.Location = new System.Drawing.Point(96, 216);
			this.txtMessage.Name = "txtMessage";
			this.txtMessage.Size = new System.Drawing.Size(192, 20);
			this.txtMessage.TabIndex = 7;
			this.txtMessage.Text = "test";
			// 
			// Form1
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.Controls.Add(this.txtMessage);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.txtServerPort);
			this.Controls.Add(this.lblServerPort);
			this.Controls.Add(this.cmdClear);
			this.Controls.Add(this.cmdStart);
			this.Controls.Add(this.cmdExit);
			this.Controls.Add(this.txtInfo);
			this.Name = "Form1";
			this.Text = "Remote Server";
			this.ResumeLayout(false);

		}
		#endregion

		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void cmdExit_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}

		private void cmdStart_Click(object sender, System.EventArgs e)
		{
			cmdStart.Enabled = false;
			RemoteServer remoteServer = new RemoteServer(Int32.Parse(txtServerPort.Text));
			remoteServer.myEvent += new RemoteServer.EventDelegate(this.RemoteServer_MessageReceived);
			// remoteServer.SendMessage("Server response sent at " + DateTime.Now.ToLongTimeString());
			remoteServer.SendMessage(txtMessage.Text);
		}

		private void RemoteServer_MessageReceived(object sender, RemoteServerEventArgs e)
		{
			txtInfo.Text += e.message + "\r\n";
		}

		private void cmdReset_Click(object sender, System.EventArgs e)
		{
			txtInfo.Text = String.Empty;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions