110,536
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace WinForm
{
public partial class ProgressBarFrm : Form
{
public ProgressBarFrm()
{
InitializeComponent();
}
private void ProgressBarFrm_Load(object sender, EventArgs e)
{
timer1.Start();
}
public static ProgressBarFrm _ProgressBarFrm;
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Value++;
if (progressBar1.Value == 10)
timer1.Stop();
}
public static void Run()
{
_ProgressBarFrm = new ProgressBarFrm();
_ProgressBarFrm.Show();
}
public static void CloseFrm()
{
if (_ProgressBarFrm != null)
{
_ProgressBarFrm.Stop();
_ProgressBarFrm = null;
}
}
public void Start()
{
Show();
timer1.Start();
}
public void Stop()
{
timer1.Stop();
for (int i = progressBar1.Value; i < 100; i++)
{
progressBar1.Value++;
}
Thread.Sleep(500);
this.Hide();
this.Close();
}
}
}
namespace WinForm
{
partial class ProgressBarFrm
{
/// <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);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.timer1 = new System.Windows.Forms.Timer(this.components);
this.SuspendLayout();
//
// progressBar1
//
this.progressBar1.Location = new System.Drawing.Point(12, 67);
this.progressBar1.Name = "progressBar1";
this.progressBar1.Size = new System.Drawing.Size(570, 40);
this.progressBar1.TabIndex = 0;
//
// timer1
//
this.timer1.Interval = 250;
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
//
// ProgressBarFrm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.LightBlue;
this.ClientSize = new System.Drawing.Size(594, 162);
this.Controls.Add(this.progressBar1);
this.DoubleBuffered = true;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
this.Name = "ProgressBarFrm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "ProgressBarFrm";
this.TopMost = true;
this.Load += new System.EventHandler(this.ProgressBarFrm_Load);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Timer timer1;
}
}
可以试着调用这个。winform的。
ProgressBarFrm.Run();
private void Form1_Load(object sender, EventArgs e)
{
Thread thread = new Thread(threadFrom);//创建新线程
thread.Start();
/***开始加载任务**/
/***结束时销毁线程***/
thread .Abort();
}
public void threadFrom()
{
MethodInvoker MethInvo = new MethodInvoker(ShowForm2);
BeginInvoke(MethInvo);
}
public void ShowForm()
{
Form2 f2 = new Form2();
f2.Show();
}