2017-03-10 65 views
1

我想了解如何製作如本視頻中所示的進度欄。如何在c#中製作自定義的進度條

我試圖複製其在VS C#,但我得到的錯誤:

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

如果我嘗試使用if (txProgressBar.Text.Length == 85),我會在文本框(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(); 
     } 
    } 
} 

回答

3

你行:

txProgressBar.Text = txProgressBar + "█";

應該

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

+0

太棒了!我做了改變。我也意識到它缺少* .Text。謝謝。 –

0

我意識到發生了什麼問題。 txProgressBar.Text = txProgressBar +「█」;缺少* .Text。這解決了問題,同時也顯示了信息。