一、设计器
二、设计器源码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace OPCClientDemo
{
public partial class ProcessFrom : Form
{
public ProcessFrom(int _Minimum, int _Maximum)
{
InitializeComponent();
progressBar1.Maximum = _Maximum;
progressBar1.Value = progressBar1.Minimum = _Minimum;
}
public void setPos(int iValue, string sTip = "系统启动中...")
{
if (iValue < this.progressBar1.Maximum)
{
progressBar1.Value = iValue;
lbl_status.Text = sTip;
lbl_percent.Text = (iValue * 100 / progressBar1.Maximum).ToString() + "%";
Thread.Sleep(1);
}
Application.DoEvents();
}
private void ProcessFrom_Load(object sender, EventArgs e)
{
this.Owner.Enabled = false;
}
private void ProcessFrom_FormClosed(object sender, FormClosedEventArgs e)
{
this.Owner.Enabled = true;
}
}
}
三、应用
1、主程序
int nProcessValue = 0;
ProcessFrom processForm;
1、窗体加载中
processForm = new ProcessFrom(10, 100);
processForm.StartPosition = FormStartPosition.CenterScreen;
InitiaSys();
2、InitiaSys方法
private void InitiaSys()
{
try
{
this.Show();
//this.WindowState = FormWindowState.Maximized;窗体最大化
this.Hide();
processForm.Show(this);
nProcessValue = 10;
SetPos(nProcessValue, "上位机启动中...");
nProcessValue = 15;
SetPos(nProcessValue, "加载配置文件...");
nProcessValue = 80;
SetPos(nProcessValue, "上位机加载成功...");
nProcessValue = 95;
SetPos(nProcessValue, "启动系统成功...");
}
catch (Exception ex)
{
}
finally
{
processForm.Close();
this.Show();
}
}
标签:ProcessFrom,using,System,processForm,progressBar1,nProcessValue,窗口,ProcessBar
From: https://www.cnblogs.com/sxdd/p/18375519