Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在progressBar1上提取百分比? 这样,我看到PrimsBAR1中间的百分比,但它闪烁。 我尝试添加progressBar1.Refresh();在绘图之前和之后,尝试使progressBar1无效,但没有任何帮助—它正在闪烁_C#_.net_Winforms - Fatal编程技术网

C# 如何在progressBar1上提取百分比? 这样,我看到PrimsBAR1中间的百分比,但它闪烁。 我尝试添加progressBar1.Refresh();在绘图之前和之后,尝试使progressBar1无效,但没有任何帮助—它正在闪烁

C# 如何在progressBar1上提取百分比? 这样,我看到PrimsBAR1中间的百分比,但它闪烁。 我尝试添加progressBar1.Refresh();在绘图之前和之后,尝试使progressBar1无效,但没有任何帮助—它正在闪烁,c#,.net,winforms,C#,.net,Winforms,这个方法NewsUpdate我通过一个计时器滴答事件调用它,它的间隔设置为1000ms 我怎样才能使它平滑而不眨眼 编辑 这就是我所做的,我添加了一个OnPaint覆盖事件: private void NewsUpdate() { counter += 1; progressBar1.Value = counter; int percent = progressBar1.Value;

这个方法NewsUpdate我通过一个计时器滴答事件调用它,它的间隔设置为1000ms

我怎样才能使它平滑而不眨眼

编辑

这就是我所做的,我添加了一个OnPaint覆盖事件:

private void NewsUpdate()
        {
            counter += 1;
            progressBar1.Value = counter;
            int percent = progressBar1.Value;
            progressBar1.CreateGraphics().DrawString(
                percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular),
                Brushes.Black, new PointF(progressBar1.Width / 2 - 10, progressBar1.Height / 2 - 7));
            //progressBar1.Refresh();
            label9.Text = counter.ToString();
            label9.Visible = true;
            if (counter == 10)
            {
                Extractions();
                counter = 0;
            }
        }
我在失效时在计时器中更新的方法中出现错误:

protected override void OnPaint(PaintEventArgs e)
        {
            int percent = progressBar1.Value = counter;
            base.OnPaint(e);

            e.Graphics.DrawString(percent.ToString() + "%",
                SystemFonts.DefaultFont,
                Brushes.Black,
                new PointF(progressBar1.Width / 2 - (e.Graphics.MeasureString(percent.ToString() + "%",
                    SystemFonts.DefaultFont).Width / 2.0F),
                progressBar1.Height / 2 - (e.Graphics.MeasureString(percent.ToString() + "%",
                    SystemFonts.DefaultFont).Height / 2.0F)));

        }
现在的问题是,我在表格1的顶部看到了百分比。我怎样才能把百分比显示在中间的PrimeStar上?

编辑

我现在试过这个:

private void NewsUpdate()
        {
            counter += 1;
            this.Invalidate();

现在它在进度条上,但再次闪烁。百分比正在闪烁。

如果已将进度条的最大值设置为100,则无需根据进度条值计算百分比

protected override void OnPaint(PaintEventArgs e)
        {
            int percent = progressBar1.Value = counter;
            base.OnPaint(e);
            Graphics gr = e.Graphics;
            using (gr = progressBar1.CreateGraphics())
            {
                gr.DrawString(percent.ToString() + "%",
                    SystemFonts.DefaultFont,
                    Brushes.Black,
                    new PointF(progressBar1.Width / 2 - (gr.MeasureString(percent.ToString() + "%",
                        SystemFonts.DefaultFont).Width / 2.0F),
                    progressBar1.Height / 2 - (gr.MeasureString(percent.ToString() + "%",
                        SystemFonts.DefaultFont).Height / 2.0F)));
            }
        }
并将
progressbar1.Invalidate()
放置在更新
progressbar1.Value

private void progressbar1_Paint(object sender, PaintEventArgs e)
{
    StringFormat sf = new StringFormat();
    sf.Alignment = StringAlignment.Center;
    sf.LineAlignment = StringAlignment.Center;
    Font font = new Font("Arial", 8.25f, FontStyle.Bold, GraphicsUnit.Point);
    RectangleF rf = new RectangleF(0,0,progressbar1.Width, progressbar1.Height);
    e.Graphics.DrawString(progressbar1.Value.ToString("# %"), font, Brushes.Black,rf, sf);            
}

将WPF TextBlock(而不是Label)控件w/完成百分比置于ProgressBar控件之外。Rgds,@AlexBell:他没有使用WPF。你需要处理并绘制
Paint
事件。这是progressbar的OnPaint吗?Sara没有。我在表单1上手动创建了OnPaint,刚刚添加了一个名为OnPain的方法。progressBar没有任何油漆或onpain事件。如何使progressBar1在paint事件上运行?progressBar没有paint事件。
progressbar1.Value += 1;
progressbar1.Invalidate();