Creating a GUI in C#

Creating a dynamic GUI with real-time information

Page 1 of 1

2 Replies - 15880 Views - Last Post: 14 July 2007 - 11:28 PM Rate Topic: -----

#1 ankman00  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-July 07

Creating a GUI in C#

Post icon  Posted 13 July 2007 - 08:21 PM

I am trying to create a GUI with C# that would open a port and listen for real-time information on that port. As the information comes in, I would like to update the GUI with the information.

The GUI would have rows and columns and it will just keep on appending information to it. I am not an expert on Object Oriented Programming. I have downloaded C# 2005 from MSDN website. Can anyone help me please? Thanks in advance for your help!

Is This A Good Question/Topic? 0
  • +

Replies To: Creating a GUI in C#

#2 MorphiusFaydal  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 43
  • View blog
  • Posts: 1,376
  • Joined: 12-May 05

Re: Creating a GUI in C#

Posted 13 July 2007 - 11:49 PM

View Postankman00, on 13 Jul, 2007 - 08:21 PM, said:

I am trying to create a GUI with C# that would open a port and listen for real-time information on that port. As the information comes in, I would like to update the GUI with the information.

The GUI would have rows and columns and it will just keep on appending information to it. I am not an expert on Object Oriented Programming. I have downloaded C# 2005 from MSDN website. Can anyone help me please? Thanks in advance for your help!


Google for Windows.Forms and System.Net

Or use MSDN.

You'll use Windows.Forms for the UI, and System.Net to interface with the network.
Was This Post Helpful? 0
  • +
  • -

#3 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4307
  • View blog
  • Posts: 12,085
  • Joined: 18-April 07

Re: Creating a GUI in C#

Posted 14 July 2007 - 11:28 PM

Hello Ankman00,

I understand your trouble trying to find some nice solid connection code. It isn't an easy task at times since even MSDN has several depreciated methods for establishing a tcpClient connection.

To help I have written a nice little snippet below that will show you some tricks on setting up something like a port listener. The idea here is that I simply had an application (GUI) that had a button an a multiline text box to display data. By clicking the button (btnStart) will send the application into a listening mode on port 80 using a loopback address (to your own computer hence the 127.0.0.1).

Then by simply pointing a browser to your address, the application would capture the browser attempting to connect your application. Hope that makes sense.

private void btnStart_Click(object sender, EventArgs e)
		{
			// Listen to our own port 80 (HTTP protocol port).
			IPAddress localAddr = IPAddress.Parse("127.0.0.1");
			TcpListener listen = new TcpListener(localAddr,80);

			try {
				// Start listening
				listen.Start();

				Byte[] bytes = new byte[256];

				// Block until we get a connection, then get the stream of data.
				TcpClient client = listen.AcceptTcpClient();
				NetworkStream stream = client.GetStream();

				int i;
				String data = null;

				// While data is available on the line, fetch it.
				// Then store it in our textbox called "txtMessages"
				while (stream.DataAvailable) {
					i = stream.Read(bytes, 0, bytes.Length);
					data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
					txtMessages.Text += data.ToString();
				}

				// Once done, close the connection.
				client.Close();

			}
			catch (SocketException exceptionerror) {
				MessageBox.Show("Socket error: " + exceptionerror.Message);
			}
			finally {
				// Stop listening for new clients.
				listen.Stop();
			}
		}



Below is a screenshot of the output. Of course you are going to have to adapt this code to your own application and with columns and stuff.

Posted Image

As Morphius so wisely pointed out, you will have to read up on how to program and decipher what I have written above. Then you will be on your way.

Enjoy!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1