Jump to content

Criar um Timer


Recommended Posts

jpaulino

ainda não consegui :s só queria um timer, para passado um x tempo abrir outra window..

mas está complicado

Mostra o que já tens feito e o que não funciona, porque os link que te deram, têm lá tudo passo a passo ;)

Link to post
Share on other sites

public LogoStartup()
	{
		this.InitializeComponent();
            System.Windows.Threading.DispatcherTimer dTimer = new System.Windows.Threading.DispatcherTimer();
            dTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dTimer.Interval = TimeSpan.FromMilliseconds(1000);
            dTimer.Start();
            
        }

        private void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            MainWindow newWindow1 = new MainWindow();
            newWindow1.Show();
            this.Close();
        }

já consegui, agora não estou a ver como fazer o stop() do timer

Link to post
Share on other sites

já consegui

deixo aqui então o timer, que após 10 segundos abre uma window :s

cumpz

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;


namespace WpfApplication3
{
/// <summary>
/// Interaction logic for Window1.xaml
/// </summary>
public partial class LogoStartup : Window
{
        
	public LogoStartup()
	{
		this.InitializeComponent();
            System.Windows.Threading.DispatcherTimer dTimer = new System.Windows.Threading.DispatcherTimer();
            dTimer.Tick += new EventHandler(dispatcherTimer_Tick);
            dTimer.Interval = TimeSpan.FromSeconds(10);
            dTimer.Start();
            
        }

        
        public void dispatcherTimer_Tick(object sender, EventArgs e)
        {
            MainWindow newWindow1 = new MainWindow();
            newWindow1.Show();
            this.Close();
            System.Windows.Threading.DispatcherTimer thisTimer = (System.Windows.Threading.DispatcherTimer)sender;
            thisTimer.Stop();
        }
        
    

    

	}
}

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.