110,538
社区成员
发帖
与我相关
我的任务
分享
private int i = 0;
private delegate void InvokeLabel();
private delegate void InvokeMainForm();
private void Form_Load(object sender, EventArgs e){
Thread setLabelTextThread = new Thread(setLabelText);
setLabelTextThread.Start();
this.backgroundWorker.RunWorkerAsync();
}
private void setLabelText()
{
InvokeLabel il = delegate(){
this.lable1.Text = i++.toString();
};
this.Invoke(il);
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e){
while(true){
InvokeMainForm imf = delegate(){
mainForm = new MainForm();
};
this.Invoke(imf);
}
}
public partial class LoginLoading : Form
{
public static MainForm mainForm;
private Thread progressBarThread;
private int progressBarValue = 1;
private bool flag;
public delegate void InvokeMainForm();
public LoginLoading()
{
InitializeComponent();
}
private void LoginLoading_Load(object sender, EventArgs e)
{
progressBarThread = new Thread(RunProgressBar);
progressBarThread.Start();
this.backgroundWorker.RunWorkerAsync();
}
private void RunProgressBar()
{
flag = true;
while (flag)
{
if (progressBarValue < 99)
{
progressBarValue++;
}
this.progressBar.Value = progressBarValue;
Thread.Sleep(100);
}
}
private void initMainForm()
{
if (mainForm == null)
{
mainForm = new MainForm();
}
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
if (this.InvokeRequired)
{
InvokeMainForm invoke = new InvokeMainForm(this.initMainForm);
this.Invoke(invoke);
}
flag = false;
this.progressBar.Value = 100;
Thread.Sleep(100);
}
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
this.Hide();
Thread.Sleep(500);
mainForm.Show();
}
}
public class Form{
public static i = 0;
public static Label label;
private delegate void InvokeMainForm();
public Form(){
InitializeComponent();
label = new Label();
this.Controls.Add(label);
}
private void Form_Load(object sender, EventArgs e){
this.backgroundWorker.RunWorkerAsync();
}
private void backgroundWorker_DoWork(object sender, DoWorkEventArgs e){
InvokeMainForm imf = delegate(){
mainForm = new MainForm();
};
this.Invoke(imf);
}
}
}
public class MainForm(){
public MainForm(){
InitializeComponent();
void1();
void2();
void3();
void4();
}
}