加载窗体(SplashForm)

LoadingForm.Designer.cs 代码: 

namespace  SplashForm
{
    
partial class LoadingForm
    
{
        
/// <summary>
        
/// Required designer variable.
        
/// </summary>

        private System.ComponentModel.IContainer components = null;

        
/// <summary>
        
/// Clean up any resources being used.
        
/// </summary>
        
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

        protected override void Dispose(bool disposing)
        
{
            
if (disposing && (components != null))
            
{
                components.Dispose();
            }

            
base.Dispose(disposing);
        }


        
Windows Form Designer generated code

        
private System.Windows.Forms.ProgressBar progressBar1;
        
private System.Windows.Forms.Label label1;
        
private System.Windows.Forms.Panel panel1;
        
private System.Windows.Forms.Label lblpercent;
    }

}

LoadingForm.cs代码:

using  System;
using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Text;
using  System.Windows.Forms;

namespace  SplashForm
{
    
public partial class LoadingForm : Form
    
{
        
public LoadingForm()
        
{
            InitializeComponent();
        }

        
public void SetProgressValue(int Value)
        
{
            progressBar1.Value
++;
            lblpercent.Text 
= Convert.ToString(progressBar1.Value) + '%';
            Application.DoEvents();
        }


        
private void LoadingForm_FormClosing(object sender, FormClosingEventArgs e)
        
{
            
if (Program.Flag == false)
            
{
                e.Cancel 
= true;
            }

            
else if ((Program.Flag ==true))
            
{
                e.Cancel 
= false;
            }

        }


    }

}

MainForm.Designer.cs代码:

 

namespace  SplashForm
{
    
partial class MainForm
    
{
     
        
/// <summary>
        
/// Required designer variable.
        
/// </summary>

        private System.ComponentModel.IContainer components = null;

        
/// <summary>
        
/// Clean up any resources being used.
        
/// </summary>
        
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

        protected override void Dispose(bool disposing)
        
{
            
if (disposing && (components != null))
            
{
                components.Dispose();
            }

            
base.Dispose(disposing);
        }


        
Windows Form Designer generated code

        
private System.Windows.Forms.Button button1;
        
private System.Windows.Forms.MenuStrip menuStrip1;
        
private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
        
private System.Windows.Forms.ToolStripMenuItem exitToolStripMenuItem;
    }

}


MainForm.cs代码:

 

using  System;
using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Text;
using  System.Windows.Forms;

namespace  SplashForm
{
    
public partial class MainForm : Form
    
{
        
public MainForm()
        
{
            InitializeComponent();
        }


        
private void Form1_Load(object sender, EventArgs e)
        
{
            
for(int i=0;i<100;i++)
            
{    
                Program.loadingForm.SetProgressValue(i);
                System.Threading.Thread.Sleep(
20);
            }

        }

        
protected override void OnShown(EventArgs e)
        
{
           
            
if (Program.loadingForm != null)
            
{
                Program.Flag 
= true;
                Program.loadingForm.Close();
                Program.loadingForm 
= null;
            }

            
base.OnShown(e);
        }


        
private void button1_Click(object sender, EventArgs e)
        
{
            HelloForm ShowForm 
= new HelloForm();
            
if (ShowForm.ShowDialog() == DialogResult.Cancel)
            
{
                ShowForm.Close();
            }

        }


        
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        
{
            Application.Exit();
        }

    }

}

HelloForm.Designer.cs代码:

using  System;
namespace  SplashForm
{
    
partial class HelloForm
    
{
        
/// <summary>
        
/// Required designer variable.
        
/// </summary>

        private System.ComponentModel.IContainer components = null;

        
/// <summary>
        
/// Clean up any resources being used.
        
/// </summary>
        
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

        protected override void Dispose(bool disposing)
        
{
            
if (disposing && (components != null))
            
{
                components.Dispose();
            }

            
base.Dispose(disposing);
        }


        
Windows Form Designer generated code

        
private System.Windows.Forms.Label label1;
        
private System.Windows.Forms.Button button1;
        
private Boolean Flags = false;
    }

}

HelloForm.cs代码:

using  System;
using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Text;
using  System.Windows.Forms;

namespace  SplashForm
{
    
public partial class HelloForm : Form
    
{
        
public HelloForm()
        
{
          
            InitializeComponent();
        }


        
private void button1_Click(object sender, EventArgs e)
        
{
            Flags 
= true;
            
this.Close();
        }


        
private void Form3_FormClosing(object sender, FormClosingEventArgs e)
        
{
            
if (Flags == false)
            
{
                e.Cancel 
= true;
            }

            
else if (Flags == true)
            
{
                e.Cancel 
= false;
            }

        }


       
    }

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值