就像我希望标题栏具有这种类型的打字机效果,其中每个字母在两秒延迟后出现。
H e l l o P r o g r a m
Run Code Online (Sandbox Code Playgroud)
有两秒的延迟
private void timer2_Tick(object sender, EventArgs e)
{
this.Text = "H";
timer2.Stop();
this.Text = "He";
}
Run Code Online (Sandbox Code Playgroud)
我试过这个..
你在正确的轨道上
using System.Windows.Threading; //add reference to WindowsBase. this gives you access to the DispatcherTimer
DispatcherTimer timer { get; set; } //i used this because it runs on the UI thread which allows it to update.
int letterCount { get; set; } //i used this to keep track of how many loops ran
string message { get; set; } // set the message you want to display
public Form1()
{
InitializeComponent();
this.Text = ""; //clear the text. this can be done in the designer
letterCount = 0; // set the count to 0
timer = new DispatcherTimer(); //configure the timer
timer.Interval = TimeSpan.FromSeconds(1);
timer.Tick += timer_Tick;
message = "Hello World!"; //set the message
timer.Start(); //start the timer
}
void timer_Tick(object sender, EventArgs e)
{
this.Text += message[letterCount]; // add the letter to the title bar
letterCount++; // increment the count
if (letterCount > message.Length -1) // stop the timer once the message finishes to avoid getting an error
{
timer.Stop(); // use this to stop after once
// use this to clear and restart
letterCount = 0;
this.Text = "";
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
850 次 |
| 最近记录: |