如何在c#中创建自定义进度条(How to make a customized progressbar in c#)

我想学习如何制作像本视频中所示的进度条。

我试图在VS C#中复制它,但是我得到了错误:

C#属性或索引器无法分配 - 它是只读的

如果我尝试使用if (txProgressBar.Text.Length == 85) ,我将在TextBox(txProgressBar)中得到它

System.Windows.Forms.TextBox,Text:System.Windows.Forms.TextBox,Text: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(); } } }

I would like to learn how to make a progressbar like the one shown in this video.

I tried to replicate it in VS C#, but I get the error:

C# Property or indexer cannot be assigned to -- it is read only

If I try using if (txProgressBar.Text.Length == 85), I will get this in the TextBox (txProgressBar)

System.Windows.Forms.TextBox, Text: System.Windows.Forms.TextBox, Text: 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 &= "█";

Your line:

txProgressBar.Text = txProgressBar + "█";

should be

txProgressBar.Text = txProgressBar.Text + "█"; or txProgressBar.Text &= "█";

如何在c#中创建自定义进度条(How to make a customized progressbar in c#)

我想学习如何制作像本视频中所示的进度条。

我试图在VS C#中复制它,但是我得到了错误:

C#属性或索引器无法分配 - 它是只读的

如果我尝试使用if (txProgressBar.Text.Length == 85) ,我将在TextBox(txProgressBar)中得到它

System.Windows.Forms.TextBox,Text:System.Windows.Forms.TextBox,Text: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(); } } }

I would like to learn how to make a progressbar like the one shown in this video.

I tried to replicate it in VS C#, but I get the error:

C# Property or indexer cannot be assigned to -- it is read only

If I try using if (txProgressBar.Text.Length == 85), I will get this in the TextBox (txProgressBar)

System.Windows.Forms.TextBox, Text: System.Windows.Forms.TextBox, Text: 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 &= "█";

Your line:

txProgressBar.Text = txProgressBar + "█";

should be

txProgressBar.Text = txProgressBar.Text + "█"; or txProgressBar.Text &= "█";