Winform欢迎界面

欢迎界面的目的一方面是为了让界面好看,另外一方面可以让主界面的数据准备。

一、用timer实现

欢迎界面中控制界面的显示方式并使用 timer 控制欢迎界面的消失时间

ContractedBlock.gif ExpandedBlockStart.gif View Code
 
   
1 static class Program
2 {
3 /// <summary>
4 /// 应用程序的主入口点。
5 /// </summary>
6 [STAThread]
7 static void Main()
8 {
9 Application.EnableVisualStyles();
10 Application.SetCompatibleTextRenderingDefault( false );
11 Application.Run( new MainForm());
12 }
13 }
14
15 namespace WindowsFormsApplication1
16 {
17 public partial class MainForm : Form
18 {
19 public MainForm()
20 {
21
22 SplashForm form = new SplashForm();
23 form.ShowDialog();
24 InitializeComponent();
25 }
26 }
27 }
28
29 namespace WindowsFormsApplication1
30 {
31 public partial class SplashForm : Form
32 {
33 public SplashForm()
34 {
35 InitializeComponent();
36 }
37
38 private void SplashForm_Load( object sender, EventArgs e)
39 {
40 this .FormBorderStyle = FormBorderStyle.None;
41 this .timer1.Start();
42 this .timer1.Interval = 5000 ;
43 }
44
45 private void timer1_Tick( object sender, EventArgs e)
46 {
47 this .Close();
48 }
49
50 private void SplashForm_FormClosed( object sender, FormClosedEventArgs e)
51 {
52 this .timer1.Stop();
53 }
54 }
55 }

二、用Thread实现

第一步:准备欢迎界面Form1和主界面MainForm

第二步:在MainForm的初始事件中加入代码:

    Form1 form = new Form1();
         form.ShowDialog();

    在Form1的Load事件中加入代码:

    this.Show();
             while (this.Opacity < 1)
             {
                 this.Opacity += 0.01;
             }
             System.Threading.Thread.Sleep(1000);
             this.Close();

第三步:在Program.cs中启动MainForm,运行。


ContractedBlock.gif ExpandedBlockStart.gif View Code
 
   
1 form1:
2   namespace WindowsFormsApplication1
3 {
4 public partial class Form1 : Form
5 {
6 public Form1()
7 {
8
9 InitializeComponent();
10 }
11
12 private void Form1_Load( object sender, EventArgs e)
13 {
14 this .Show();
15 while ( this .Opacity < 1 )
16 {
17 this .Opacity += 0.01 ;
18 }
19 System.Threading.Thread.Sleep( 1000 );
20 this .Close();
21
22 }
23 }
24 }
25
26 MainForm:
27   namespace WindowsFormsApplication1
28 {
29 public partial class MainForm : Form
30 {
31 public MainForm()
32 {
33
34 Form1 form = new Form1();
35 form.ShowDialog();
36 InitializeComponent();
37 }
38 }
39 }

转载于:https://www.cnblogs.com/zelmeli/archive/2011/04/25/Welcome.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值