我尝试让我的 Windows 窗体应用程序将不透明度从 1 更改为 0(不可见形式),然后在按下按钮时从 0 不透明度更改为 1(正常、可见形式)。
每个不透明度更改步骤都与计时器相关联。它会在每个 timer1_tick 中改变不透明度 (-/+0,10)。
我从不透明度 = 1 (100%) 开始
现在我有类似的东西:
public partial class Form1 : Form
{
double OpacityStep;
public Form1()
{
OpacityStep = 0.10;
InitializeComponent();
updateButton1();
updateButton2();
}
private void updateButton1()
{
if (Opacity < 1.00) button1.Enabled = true;
else
{
button1.Enabled = false;
}
}
private void updateButton2()
{
if (Opacity > 0.0) button2.Enabled = true;
else
{
button1.Focus();
button2.Enabled = false;
}
}
private void button1_Click(object sender, EventArgs e)
{
double NewOpacity = Opacity + OpacityStep;
if (NewOpacity > 1.0) Opacity = 1.0;
else Opacity = NewOpacity;
updateButton2();
updateButton1();
}
private void button2_Click(object sender, EventArgs e)
{
double NewOpacity = Opacity - OpacityStep;
if (NewOpacity < 0.0) Opacity = 0.0;
else Opacity = NewOpacity;
updateButton1();
updateButton2();
}
private void button3_Click(object sender, EventArgs e) // app start
{
this.timer1.Interval = 1000;
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
button2_Click(sender, e);
}
}
此代码使我的应用程序不可见,但如何使其恢复可见 (opacity = 1) ?? ?