我想学习如何制作一个如本视频所示的进度条。
我试图在VS C#中复制它,但出现错误:
无法将C#属性或索引器分配给它-只读
如果尝试使用if (txProgressBar.Text.Length == 85)
,我将在TextBox(txProgressBar)中得到它
System.Windows.Forms.TextBox,文本:System.Windows.Forms.TextBox,文本:Syst ...██
Textbox Progressbar Tutorial VB 2010
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 CustomizedProgressBar
{
public partial class Form1 : Form
{
int last = 1;
public Form1()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (txProgressBar.Text.Length = "85")
{
timer1.Stop();
MessageBox.Show("Counted!");
}else
{
if (last == 1)
{
txProgressBar.Text = txProgressBar + "█";
last = 2;
}
else
{
txProgressBar.Text = txProgressBar.Text + "█";
last = 1;
}
}
}
private void btnClear_Click(object sender, EventArgs e)
{
txProgressBar.Text = "";
}
private void btnStart_Click(object sender, EventArgs e)
{
timer1.Start();
}
private void btnStop_Click(object sender, EventArgs e)
{
timer1.Stop();
}
}
}
最佳答案
您的专线:txProgressBar.Text = txProgressBar + "█";
应该txProgressBar.Text = txProgressBar.Text + "█";
或txProgressBar.Text &= "█";
关于c# - 如何在C#中制作自定义进度条,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42709441/