c# - 如何在c#中制作自定义进度条

标签 c#

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

我试图在 VS C# 中复制它,但出现错误:

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

如果我尝试使用 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/

相关文章:

c# - 将 Expression<T, string>> 转换为 Expression<T, bool>>

c# - 从派生类调用的虚拟方法中的 typeof this

c# - 无法在Visual Studio C#上运行项目/文件

c# - 从 SQL 命令返回的 DataTable "SHOW TABLE STATUS"

c# - 如何加快 Word Interop 处理速度?

c# - 在转发器控件中获取选定的下拉列表值

c# - 根据光标位置访问折线图的 Y 值

c# - 将 asp.net MVC 从 5.0.0-beta2 更新到 5.0.0-rc1

c# - 从 C# winforms 执行批处理文件忽略超时

c# - 最大化另一个正在运行的程序的窗口