[英]how to make a text boxes text move back and forth?
你好atm我有這個代碼
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;
}
}
}
目前,標簽的最大長度為15個字符,我希望它保持這種狀態。
但我希望它而不是使用“ hello”將我輸入的文本輸入文本框並執行此操作。
但是,它必須取15並減去文本框文本的長度,以使標簽的最大長度保持完整,同時在文本框中顯示整個單詞的長度為15,但我不知道該怎么做,我已經嘗試了很多事情,但是我不能弄清楚任何幫助將不勝感激。 :D
您使用單詞“ ping”和“ pong”,加上標題中的“來回移動”,使我相信可以通過在每個刻度上更改標簽的TextAlign屬性來實現所需的結果。
如果這是您想要的結果,則完全不必添加空格。 文本將在標簽中從左到右邊緣出現。 您可能會考慮使用TRIM()修剪text屬性,以確保兩邊都沒有空格使它看起來不正確對齊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.