WPF 使用定时器:
<ProgressBar Height="10" HorizontalAlignment="Left" Margin="288,0,0,189" Name="progressBar1"
VerticalAlignment="Bottom" Width="100" />
后台:
private void button1_Click(object sender, RoutedEventArgs e)
{
Window_Loaded2();
}
private void Window_Loaded2()
{
DispatcherTimer _mainTimer = new DispatcherTimer();
_mainTimer.Interval = TimeSpan.FromSeconds(1);
_mainTimer.Tick += new EventHandler(_mainTimer_Tick);
_mainTimer.IsEnabled = true;
//Timer tmr = new Timer();
//tmr.Interval = 100;
//tmr.Enabled = true;
//tmr.Tick += new EventHandler(tmr_Tick);
}
void _mainTimer_Tick(object sender, EventArgs e)
{
if (progressBar1.Value == progressBar1.Maximum)
progressBar1.Value = 0;
progressBar1.Value++;
}
private void tmr_Tick(object sender, EventArgs e)
{
if (progressBar1.Value == progressBar1.Maximum) progressBar1.Value = 0;
progressBar1.Value++;
}