2014-10-03 64 views
-1

我有三種形式,從1是主窗體,Form2是閃屏,Form3是一個迷你窗體。 所以我想要做的是當我發送一封郵件時,這個From3會彈出,其中有一個gif圖像 和一個標籤。所以我成功地將From3發射了5秒,其中標籤 每秒都會改變爲不同的words每秒顯示不同的標籤文本

在窗體3 我使用timer1只運行迷你形式5秒。定時器2只運行1秒。

我想我們可以用更好的方式做到這一點這是非常簡單和容易..任何好主意和 幫助是最受歡迎的!

注: - 此外,當我再次按下該按鈕發送郵件。該標籤從開始 - 從Connecting to smtp server..但第二次開始其從Done!!盯着然後去標籤.. Done!!任何幫助..它首次啓動到Connecting to smtp server..等等! 這裏是我的代碼:

Form1中

private void sendmail_Click(object sender, EventArgs e) 
    { 
    //mail basic function here!!!! 
    smtp.Send(msg); 
    _f3.ShowDialog();//- - ->> goes to mini form Form3 
    smtp.Dispose(); 
    MessageBox.Show("Email Successfully Sent!!!", "Mail!!!."); 
    } 

Form3

private void Form3_Load(object sender, EventArgs e) 
{ 
    timer1.Interval = 5000; 
    timer1.Enabled = true; 
    timer1.Tick += new EventHandler(timer1_Tick); 

    timer2.Interval = 1000; 
    timer2.Start(); 
} 


private void timer1_Tick(object sender, EventArgs e) 
{ 
    this.DialogResult = DialogResult.OK; 
    timer1.Stop(); 
} 

int StopTime = 0; 
private void timer2_Tick(object sender, EventArgs e) 
{ 
    StopTime++; 
    if (StopTime == 1) 
    { 
     label1.Text = " Connecting to smtp server.."; 
    } 
    if (StopTime == 2) 
    { 
     label1.Text = "  Fetching recipients.."; 
    } 
    if (StopTime == 3) 
    { 
     label1.Text = " Attaching G-code files.."; 
    } 
    if (StopTime == 4) 
    { 
     label1.Text = "    Done!!"; 
     StopTime = 0; 
     timer2.Stop(); 
    } 
} 
+1

這個問題似乎是題外話,因爲它正在請求的功能代碼 – 2014-10-03 20:29:22

+0

代碼審查@DavidHeffernan請參閱編輯的問題。編碼之前..太感謝 – 2014-10-03 20:31:26

+0

@no我有一個錯誤...當我再次按下按鈕..它是從'完成!'標籤 – 2014-10-03 20:32:37

回答

2

是否後Form3接近完成將顯示?你可以做這樣的事情:

private void Form3_Load(object sender, EventArgs e) 
    { 
     SetLabel1Text(); //reset label text 
     timer1.Interval = 5000; 
     timer1.Enabled = true; 
     timer1.Tick += new EventHandler(timer1_Tick); 

     timer2.Interval = 1000; 
     timer2.Start(); 
    } 

    private void timer1_Tick(object sender, EventArgs e) 
    { 
     this.DialogResult = DialogResult.OK; 
     timer1.Stop(); 
    } 

    int StopTime = 0; 
    private void timer2_Tick(object sender, EventArgs e) 
    { 
     StopTime++; 
     SetLabel1Text(); 
     if (StopTime == 4) 
     { 
      StopTime = 0; 
      timer2.Stop(); 
     } 
    } 

    private void SetLabel1Text() 
    { 
     string[] label1Text = { " Connecting to smtp server..", " Connecting to smtp server..", "  Fetching recipients..", " Attaching G-code files..", "    Done!!" }; 
     label1.Text = label1Text[StopTime]; //populate label from array of values 
    } 
+0

表單3正在關閉。但我不知道它的關閉優雅或不..但在我的情況.. 5秒後..表格關閉,並以主要形式 – 2014-10-03 23:48:55

+0

和其中是timer1 ..你還沒有提到 – 2014-10-04 00:01:15

+0

@please告訴我我應該給定時器1還是不...我可以在定時器2或兩者都做..請讓我知道 – 2014-10-04 00:03:46