I'm working on a tcp client that will send a message to the tcp sever and the tcp sever will display the message while scrolling it from left to right. I'm including my client and sever code
I need help with the text scrolling left to right in a label.
sever:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
namespace iSignSever
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void ListenButton_Click(object sender, EventArgs e)
{
string port = PortTextBox.Text;
int myParsedInt = Int32.Parse(port);
Socket listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
listenSocket.Bind(new IPEndPoint(IPAddress.Any, myParsedInt));
listenSocket.Listen(5);
Socket connection = listenSocket.Accept();
byte[] buffer = new byte[1024];
connection.Receive(buffer);
string text = System.Text.ASCIIEncoding.ASCII.GetString(buffer);
label1.Text = text;
string l = label1.Text;
int iScroll = iScroll + 1;
int iLmt = l.Length - iScroll;
if (iLmt < 20)
{
iScroll = 0;
}
string str = l.Substring(iScroll, 20);
}
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This is the CSCI 360 iSign Sever Application. Worked on by Team 5", "iSign Sever About");
}
private void timer1_Tick(object sender, EventArgs e)
{
}
}
}
client:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
namespace iSignClient
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void SendButton_Click(object sender, EventArgs e)
{
string host = SignHostTextBox.Text;
string port = PortTextBox.Text;
int myParsedInt = Int32.Parse(port);
string message = MessageTextBox.Text;
// string [] host2 = host.Split(',');
Socket connectSocket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
connectSocket.Connect(host, myParsedInt);
System.IO.StreamReader connectionRead = new System.IO.StreamReader(new NetworkStream(connectSocket));
//sendString(connectSocket, sendText);
connectSocket.Send(System.Text.Encoding.UTF8.GetBytes(message + "\r\n"));
connectSocket.Close();
}
private void closeToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("This is CSCI 360 iSign Client Program. The team members are JD, Tiffany, Mahendra, Fahad Alanazi", "iSign Client About");
}
private void button1_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
textBox1.Text = colorDialog1.Color.ToString();
}
private void button2_Click(object sender, EventArgs e)
{
colorDialog2.ShowDialog();
textBox2.Text = colorDialog2.Color.ToString();
}
private void button3_Click(object sender, EventArgs e)
{
fontDialog1.ShowDialog();
textBox3.Text = fontDialog1.Font.ToString();
}
private void ResetButton_Click(object sender, EventArgs e)
{
textBox1.Text = "";
textBox2.Text = "";
textBox3.Text = "";
MessageTextBox.Text = "";
PortTextBox.Text = "";
SignHostTextBox.Text = "";
}
}
}
here is the code that I thought about using to scroll the text, but I don't know how to use it for it to work how I want it to.
code:
/* private int iScroll;
private string strString = "This is scrollable text...This is scrollable text...This is scrollable text";
private void timer1_Tick(object sender, EventArgs e)
{
iScroll = iScroll + 1;
int iLmt = strString.Length - iScroll;
if (iLmt < 20)
{
iScroll = 0;
}
string str = strString.Substring(iScroll, 20);
label1.Text = str;
*/
// }
Thanks for the help.
-jdm