简体   繁体   中英

C# Forms, drawing a progress line

I have the following code:

public async void startCountdown()
{
    do
    {               
        label9.Text = frsL.ToString();

        frsL -= frsLStep;

        g = tabPage1.CreateGraphics();
        g.DrawLine(pen1, 5, 7, (int)frsL + 5, 7);

        await Task.Delay(1000);

    } while (timeToSeconds());
}

I'm trying to refresh a progress line every second, but the line isn't changing. I used label9 just to check if frsL value is changing and it is, but the line isn't redrawn and it stays at it's starting length.

Yeah, the problem was that the line is decreasing and I have to remove the old line before drawing the new one. Inserting 'g.Clear(Color.White);' before 'g.DrawLine' fixed the problem. The bad thing is that sometimes the whole line flashes.

Hi I suggest you to put a timer in your form , set it's interval on 1000 and paste your code in it's tick function.

good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM