1

わかりました、フォームにクロージング イベントがあります。その中のコードは、フォームをフェードアウトしてから、別のフォームを開きます。フェードが完了するまで待つ方法はありますか? これが私のコードです:

    private void form1_closing(object sender, FormClosingEventArgs e)
    {
        if (this.Opacity > 0.01f)
        {
            e.Cancel = true;
            timer1.Interval = 47;
            timer1.Enabled = true;
            timer1.Start();

        }
        else
        {
            timer1.Enabled = false;
        }
    }

    private void timer2_Tick(object sender, EventArgs e)
    {
        progressBar1.Increment(+1);
        label4.Text = progressBar1.Value.ToString() + "%"; 
        if (progressBar1.Value == 100)
        {
            progressBar1.Value = 100; 
            timer2.Stop();
            this.Close();
            Form2 frm2 = new Form2();
            frm2.Show(); 
        }
    }

基本的にはform2の方が早く開くので、フェード効果がかかってから待ってほしい。:)

4

2 に答える 2

2

このコードで十分だと思います。

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        for (double i = 1.0; i > 0.0; i-=0.01)
        {
            this.Opacity = i;
            Thread.Sleep(10);
        }

  //Handle whatever you want to do here. The control comes here only when the form is faded out.
    }
于 2012-05-18T16:46:27.650 に答える
0

コード :

void Wait(int Milliseconds)
{
    Stopwatch sw = new Stopwatch();
    sw.Start();
    while(sw.ElapsedMillisecods < Millisecods)
    {
        Application.DoEvents();
    }
    sw.Stop();
}

ここにWait関数があり、フェード中にかかる合計時間を次のように計算できる場合に使用できます。

Wait(Time)
于 2012-05-18T16:51:37.540 に答える