Rey*_*deh 6 c# winforms form-control
我有一个表单,应该通过点击主窗体中的按钮显示,我想当用户关闭第二个窗体时,主窗体再次显示在屏幕的中心.我使用下面的代码来做到这一点:
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 .
}
Run Code Online (Sandbox Code Playgroud)
这些命令做我想要的,但问题是关闭第二个窗体后,主窗体会显示一个小跳跃,就像眨眼一样!(它不是连续的,它只是在第一个.)我想要的是顺利完成,没有任何眨眼.这怎么可能?
提前致谢.
尝试平滑地设置不透明度(主窗体必须具有 属性AllowTransparency)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
Run Code Online (Sandbox Code Playgroud)
- - 编辑
请注意,您可以执行相同的操作来隐藏其他表单:只需将初始不透明度设置为 1.00 而不是 0.00,然后递减 ( -= ) 而不是在循环中递增:
form2.Opacity -= opacity
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
886 次 |
| 最近记录: |