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

Scroll() {
    lable1.Text = lable1.Text.Substring(1) + lable1.Text[0];
}

I'd set a timer to call the scroll function at some interval that doesn't make it look like a blur :)

commented: Momerath was very helpful and helped me with the code I needed. +2

Sorry about the first post. Just ignore it.

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 in a label. I'm including my client and sever code

There are a few things I need help with and I would appreciate the help.

I need help with: having the sever application be able to scroll the text in the label, have the client connect to multiple hosts at once, and being able to send background color, text color, and font from the client to the sever and having the sever use that data when displaying the message.

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 on the sever application, but I don't know how to use it for it to work how I want it to. It works if I store a message into a string, but I need to wait until a message comes in from the client and use that message.

timer / scroll 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

Thank you Momerath for that code. It helped me out. I got it to scroll when it receives the message and when not running. Also it is kinda weird, it scrolls by moving from the text left then going down a line and coming from the right to left.

ex. this is a test

is a test
th

Is there a way to tell it to wait until a message comes from the tcp client then scroll and also how would i get this message to work on a single line like that?

ex. this is a test.
is is a test. th

thanks for the help.

Sincerely yours;

jdm

Scroll() {
    lable1.Text = lable1.Text.Substring(1) + lable1.Text[0];
}

I'd set a timer to call the scroll function at some interval that doesn't make it look like a blur :)

It appears your line has a carriage return on the end, which is why you are seeing it split across two lines. I'd remove them from the line :)

It appears your line has a carriage return on the end, which is why you are seeing it split across two lines. I'd remove them from the line :)

Thank you Momerath for the help. I got it to work on the same line and to only scroll now when it recieves a message. I now have to get the client to be able to connect to multiple hosts at once and be able to send the message text color, the label background color, and the font size of the message from the client and have the sever recieve it and use it. If you have any ideas I would appreciate them.

sever code:

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;
using System.Threading;

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;
            timer1.Enabled = true;

        }

        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)
        {
            
        }

        private void scroll()
        {
            label1.Text = label1.Text.Substring(1) + label1.Text[0];
        }

        private void timer1_Tick_1(object sender, EventArgs e)
        {
            scroll();
        }
    }
}

Thanks for the help

Sincerely yours;

jdm

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.