2013-02-15 66 views
0

我在這裏閱讀了一篇單獨的文章,解釋瞭如何在Windows窗體應用程序中製作簡單的文本動畫。下面的代碼完美地工作在一個表格中。但是,我正在創建一個Windows應用商店應用程序,它不起作用。定時器類不被識別,並因此,代碼不起作用。我是否需要制定計時課程,還是需要使用其他課程?如果我需要制定計時課程,我該怎麼做?謝謝。計時器對象Windows應用程序

public partial class Form1 : Form 
    { 
    public Form1() 
    { 
     InitializeComponent(); 
     t = new Timer(); 
     t.Interval = 40; 
     t.Tick += new EventHandler(t_Tick); 
    } 

    private void textBox1_TextChanged(object sender, EventArgs e) 
    { 

    } 

    string stuff = "This is some text that looks like it is being typed."; 
    int pos = 0; 
    Timer t; 



    void t_Tick(object sender, EventArgs e) 
    { 
     if (pos < stuff.Length) 
     { 
      textBox1.AppendText(stuff.Substring(pos, 1)); 
      ++pos; 
     } 
     else 
     { 
      t.Stop(); 
     } 
    } 


    private void button1_Click_1(object sender, EventArgs e) 
    { 
     pos = 0; 
     textBox1.Clear(); 
     t.Start(); 
    } 




    } 

回答

0

WinForms Timer在Windows應用商店應用中不可用。您可以改用DispatcherTime

dispatcherTimer = new DispatcherTimer(); 
dispatcherTimer.Tick += dispatcherTimer_Tick; 
dispatcherTimer.Interval = new TimeSpan(0, 0, 1); 
dispatcherTimer.Start(); 

void dispatcherTimer_Tick(object sender, object e) { 

} 
+0

上述代碼被編譯器接受。但是,我不確定接下來要做什麼。我嘗試將if和else語句的內容放在dispatcherTimer_Tick方法中,但編譯器不接受「.AppendText」。我嘗試使用「.Text」,但創建了一次顯示一個字母的動畫。我想讓動畫看起來像輸入文字一樣,字母不斷添加到文本塊中。感謝您回覆我的問題。 – Kooltone 2013-02-16 15:53:23

相關問題