【C#|C# WinFrom ProgressBar控件】
文章图片
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;
namespace _13._14__ProgressBar_控件
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
button2.Enabled = false;
button3.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
}
public void LogOut(string str)
{
textBox1.AppendText(DateTime.Now.ToString() +str+ "\n");
}
private void button1_Click(object sender, EventArgs e)
{
try
{
if(textBox2.Text.Trim()!="")
{
progressBar1.Minimum = 0;
progressBar1.Maximum = Convert.ToInt32(textBox2.Text);
progressBar1.Step = -1;
progressBar1.Value = https://www.it610.com/article/progressBar1.Maximum;
button1.Enabled = false;
button2.Enabled = true;
LogOut("时间正确设置,请按开始键继续...");
}
}
catch(Exception ex)
{
MessageBox.Show("请输入正确秒数(数值为正整数)");
}
}
private void groupBox1_Enter(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
button2.Enabled = false;
button3.Enabled = true;
button4.Enabled = true;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if(progressBar1.Value>progressBar1.Minimum)
{
progressBar1.PerformStep();
LogOut("进度条正在工作,已完成"+((1-Convert.ToDouble(progressBar1.Value)/Convert.ToDouble(progressBar1.Maximum))*100).ToString()+"%");
}
else
{
LogOut("进度已完成");
timer1.Stop();
button2.Enabled = false;
button3.Enabled = false;
button4.Enabled = false;
}
}
private void button3_Click(object sender, EventArgs e)
{
if(timer1.Enabled==true)
{
LogOut("进度已经被暂停");
button3.Text = "继续";
timer1.Stop();
}
else
{
LogOut("进度条继续工作");
button3.Text = "暂停";
timer1.Start();
}
}
private void button4_Click(object sender, EventArgs e)
{
LogOut("进度条停止工作\n");
textBox1.AppendText("========================================\n");
timer1.Enabled = false;
progressBar1.Value = https://www.it610.com/article/0;
button1.Enabled = true;
button3.Enabled = false;
button4.Enabled = false;
}
}
}
1.视图TextBox1控件设置MultiLine
2.视图Timer1控件设置:
文章图片
推荐阅读
- C#|C# 文件路径操作
- C# 接口实例
- C#|10、接口、抽象、密封、开放封闭原则
- c#|11、C#处理程序异常的技术
- C#|九、C#结构 类 属性
- C#|c# HashtableTo Json 字符串 HashtableToWxJson
- 分表分库(百亿级大数据存储)
- C#|微信小程序开发系列(六)——“处理请求时出错”怎么处理()
- c#做的一个简单的包含实时进度的进度条
- asp.net|c#文件写入与获取post请求数据