6

I have a form that should be shown by clicking on a button in main form and I want when users close the second form, main form be shown again on center of the screen. I used below codes to do this:

private void button_Click(object sender, EventArgs e)
{
    this.Hide(); //Hides the main form .
    form2.ShowDialog(); //Shows the second form .
    this.Show(); // Re-shows the main form after closing the second form ( just in the taskbar , not on the screen ) .
    this.StartPosition = FormStartPosition.CenterScreen; // I write this code because I want to show the main form on the screen , not just in the taskbar .
}

these commands do what I want , but the problem is that after closing the second form , the main form be shown with a small jump, like a blink! (It's not continuous , it's just at the first.) What I want is do this smoothly, without any blink at the first. How is it possible?

Thanks in advance.

4

1 回答 1

3

尝试平滑设置不透明度(主窗体必须具有AllowTransparencyto 的属性true)。这是同步执行它的非常基本的方法(阻塞主线程),但是因为它会持续很短的时间,这应该没问题;不需要 Application.DoEvents():

double opacity = 0.00;
while (opacity < 1)
{
    Opacity = opacity; // update main form opacity - transparency
    opacity += 0.04; // this can be changed
}
Opacity = 1.00 // make sure Opacity is 100% at the end

- - 编辑

请注意,您可以执行相同的操作来隐藏其他形式:只需将初始不透明度设置为 1.00 而不是 0.00,然后递减( -= )而不是在循环中递增:

form2.Opacity -= opacity
于 2014-08-03T18:57:29.590 回答