gpt4 book ai didi

c# - 如何让标签来回滚动一个词?

转载 作者:行者123 更新时间:2023-11-30 17:13:57 25 4
gpt4 key购买 nike

我想到了让标签将单词滚动到一侧然后更改单词并滚动回另一侧的想法

   "ping           "
" ping "
" ping "
" ping "
" ping "
" ping "
" ping "
" ping "
" ping "
" ping "
" ping "
" ping"
" pong"
" pong "
" pong "
" pong "
" pong "
" pong "
" pong "
" pong "
" pong "
" pong "
" pong "
"pong "

我希望它只在一个恒定的循环中执行 ^^ 但我不知道我将如何开始这样做,如果有人可以帮助我,我将非常感激。文本的最大长度必须为 15 个字符。

我不关心它是否平滑滚动。

我希望它是一个 Winforms 应用程序并使用 .Net framework 4.0。

最佳答案

这就是我要做的,当我测试它时它似乎工作得很好,我创建了一个带有计时器和标签的 Windows 窗体。确保在打开表单时调用 timer.Start() ,它会开始在屏幕上弹跳。如果您将 iUBound 更改为更大的值,它将在屏幕上移动更多空间。

    string _sPing = "ping";
string _sPong = "pong";
bool bGoingUp = true;
int iUBound = 15;
int iCnt = 1;

public Form1()
{
InitializeComponent();
timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{

if (bGoingUp)
{
label1.Text = " " + label1.Text;
iCnt++;
}
else
{
label1.Text = label1.Text.Substring(1,label1.Text.Length - 1);
iCnt--;
}

if (iCnt == iUBound)
{
bGoingUp = false;
label1.Text = label1.Text.Replace(_sPing, _sPong);
}
else if (iCnt == 1)
{
bGoingUp = true;
label1.Text = label1.Text.Replace(_sPong, _sPing);
}

}

关于c# - 如何让标签来回滚动一个词?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9244800/

25 4 0