一、从一个窗体显示另一个窗体
创建Form1
1、创建一个Windows窗体应用程序,将其命名为Form1.
2、讲Button控件添加到命名空间中去,并将其命名为button1.
3、将Form2类添加到命名空间中,并如以下代码设置button1的Click时间处理程序。
当单击该按钮时,Form2将显示。
private void button1_Click(object sender, System.EventArgs e)
{
Form2 frm = new Form2();
frm.Show();
}
// Create Form2.
public class Form2: Form
{
public Form2()
{
Text = "Form2";
}
}
二、窗体渐变显示特效
打开程序后,窗体由不透明逐渐显示出来。
实现方法:
1、添加一个Timer控件,然后在其Tick事件实现如下代码
private void timer1_Tick(object sender, EventArgs e)
{
if (b)
{
this.Opacity -= 0.1;
if (this.Opacity == 0)
{
b = false;
}
}
else
{
this.Opacity += 0.02;
if (this.Opacity == 1)
{
b = true;
}
}
//this.Opacity -= 0.2;
//if (this.Opacity==0)
//{
// timer1.Stop();
//}
}
2、在Load事件设置
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Interval = 2000;
this.timer1.Enabled = true;
this.timer1.Start();
MessageBox.Show(this.Opacity.ToString());
}