[英]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();
}
}
}
你的路線:
txProgressBar.Text = txProgressBar + "█";
應該
txProgressBar.Text = txProgressBar.Text + "█";
或者txProgressBar.Text &= "█";
我意識到問題是什么。 txProgressBar.Text = txProgressBar +“█”; 缺少* .Text。 這解決了問題並且也顯示了消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.