hello atm I have this code
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
x = 0;
timer1.Enabled = true;
timer1.Start();
}
else
{
timer1.Enabled = false;
}
}
private int x = 0;
private int y = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if (x <= 10)
{
x++;
string ping = new string(' ', x) + "hello";
label1.Text = ping;
if (x == 10)
{
y = 10;
}
}
else if (y > 0)
{
y--;
string pong = new string(' ', y) + "hello";
label1.Text = pong;
if (y == 0)
{
x = 0;
}
}
}
at the moment the label has a maximum length of 15 characters and i want it to stay that way.
but i want it to instead of using “hello” to take the text i input into a textbox and do it.
however it has to take 15 and subtract the length of the textboxes text in order to keep the labels max length of 15 intact while displaying the entire word in the textbox aswell but i cant figure out how to do it i have tried plenty of things but i cannot figure it out any help would be greatly appreciated. 😀
Your use of the words “ping” and “pong”, plus your title saying “move back and forth” leads me to believe the result you want can be achieved by changing the TextAlign property of the label upon each tick.
If this is the result you want, you won’t have to add spaces at all. The text will appear to go from left to right edges in the label. You might consider trimming the text property with TRIM() to ensure no spaces exist on either side that would make it appear aligned incorrectly.