一、從一個窗體顯示另一個窗體
建立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());
}