Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4346634
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T12:11:56+00:00 2026-05-21T12:11:56+00:00

I have noticied that when using the PorgressBar. If I set the value to

  • 0

I have noticied that when using the PorgressBar. If I set the value to x, the value displayed is not immediately updated, it takes a small amount of time to draw it as the bar is animated from its current value to the new value.

This is easy to see in the following code:

Private Async Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Label1.Text = ""
    Dim progressHandler = New Progress(Of Integer)(Sub(value) ProgressBar1.Value = value)
    Dim progress = CType(progressHandler, IProgress(Of Integer))
    Await Task.Run(Sub()
                       For i = 1 To 100
                           progress.Report(i)
                           Thread.Sleep(10)
                       Next
                   End Sub)
    Label1.Text = "Value Now at 100%"
    Await Task.Delay(650) 'it takes this long for the bar to be rendered
    Label1.Text += " - Finished drawing"
End Sub

You will notice running this code that the Value Now at 100% appears a long time before the bar has actually reached 100%.

Is there any way that I can detect when the bar has finished rendering?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T12:11:57+00:00Added an answer on May 21, 2026 at 12:11 pm

    I just tried this out and can see exactly what you mean. Unfortunately after spending a little while seeing if the DrawToBitmap functions on the progress bar might help, I’ve come up short.

    The next step would be to create a custom progress bar that exposes events for when rendering has completed.

    For a reasonable example on how to create a custom progress bar, try here:
    http://msdn.microsoft.com/en-us/library/system.windows.forms.progressbarrenderer(v=VS.100).aspx

    A quick scan over the code looks like you should be able to plug in an ‘OnRendered’ event or similar on or around the calls to ‘DrawHorizontalChunks’ (or ‘DrawVerticalChunks’).

    Probably not the answer you was after, but at least gives you the control you need if you pursue it?

    Note: I haven’t tried this myself, so please don’t send me hate mail if you spend all day on this to find you get the same results…

    Good Luck!

    EDIT:

    Wasn’t happy with my response, seemed a bit lazy… The following uses a custom progress bar as I described. It has a couple basic properties for setting Max/Min values, Performing steps, and setting the value directly. I’ve tested this by changing the sleep interval to various amounts, in all cases the form displayed the progress bar as full before closing. Note the new OnRendered event.

    Imports System
    Imports System.Drawing
    Imports System.Windows.Forms
    Imports System.Windows.Forms.VisualStyles
    
    Public Class Form1
        Inherits Form
        Private WithEvents bar1 As ProgressBarWithRender = New ProgressBarWithRender()
    
    
        Public Sub New()
            InitializeComponent()
            Me.Size = New Size(500, 500)
            bar1.Location = New Point(100, 100)
            bar1.Width = 300
            bar1.Height = 50
            bar1.Maximum = 30
            bar1.Step = 1
            Controls.Add(bar1)
        End Sub
    
        Public Sub OnRendered(ByVal valueRendered As Integer) Handles bar1.OnRendered
            If valueRendered = bar1.Maximum Then
                ' We know everything has been drawn
                Me.Close()
            End If
        End Sub
    
    
        <STAThread()> _
        Public Shared Sub Main()
            ' The call to EnableVisualStyles below does not affect
            ' whether ProgressBarRenderer.IsSupported is true; as 
            ' long as visual styles are enabled by the operating system, 
            ' IsSupported is true.
            Application.EnableVisualStyles()
            Application.Run(New Form1())
    
        End Sub 'Main
    
        Private Sub Form1_Click(sender As Object, e As System.EventArgs) Handles Me.Click
            For i = 1 To 30
                bar1.PerformStep()
                Threading.Thread.Sleep(10)
            Next
        End Sub
    
    End Class 'Form1
    
    Public Class ProgressBarWithRender
        Inherits Control
    
        Public Delegate Sub RenderedEventArgs(ByVal valueRendered As Integer)
        Public Event OnRendered As RenderedEventArgs
    
        Private ProgressBarRectangles() As Rectangle
    
        Public Property [Step] As Integer
    
        Public Property InnerPadding As Integer = 3
    
        Private _Maximum As Integer
        Public Property Maximum As Integer
            Get
                Return _Maximum
            End Get
            Set(value As Integer)
                _Maximum = value
                CalculateTickSizes()
            End Set
        End Property
    
        Private _Minimum As Integer
        Public Property Minimum As Integer
            Get
                Return _Minimum
            End Get
            Set(value As Integer)
                _Minimum = value
                CalculateTickSizes()
            End Set
        End Property
    
        Private _Value As Integer
        Public Property Value As Integer
            Get
                Return _Value
            End Get
            Set(newValue As Integer)
                If newValue < Me.Value AndAlso newValue > 0 Then
                    Throw New NotImplementedException("ProgressBarWithRender does not support decrementing the value")
                End If
                Me._Value = newValue
            End Set
        End Property
    
        Public Sub PerformStep()
            ' Ensure step doesn't exceed boundaries
            If Value + [Step] > Maximum Then
                Value = Maximum
            ElseIf Value + [Step] < Minimum Then
                Value = Minimum
            Else
                Value += [Step]
            End If
    
            ' We are limited by the Renderers Chunk Width, so we possibly can't draw every step if there is a high maximum
            Dim g As Graphics = Me.CreateGraphics
            ProgressBarRenderer.DrawHorizontalChunks(g, ProgressBarRectangles(Value - Minimum))
            RaiseEvent OnRendered(Value)
    
        End Sub
    
        Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
            MyBase.OnPaint(e)
            If Not ProgressBarRenderer.IsSupported Then
                Throw New NotImplementedException("Progress Bar Rendering is not supported")
            End If
            ProgressBarRenderer.DrawHorizontalBar(e.Graphics, ClientRectangle)
        End Sub
    
        Private Sub CalculateTickSizes()
            ' Changing the Maximum will change the tick rectangle size
            ProgressBarRectangles = New Rectangle(Maximum) {}
            Dim chunkThickness As Integer = ProgressBarRenderer.ChunkThickness + (ProgressBarRenderer.ChunkSpaceThickness * 2)
            Dim tickThickness As Double = ((ClientRectangle.Width - (InnerPadding * 2)) - (ProgressBarRenderer.ChunkSpaceThickness * 2)) / (Maximum - Minimum)
            If tickThickness < chunkThickness Then
                Debug.Print("This will go wrong because we can't draw small enough chunks...")
            End If
            For i As Integer = 0 To Maximum
                Dim filledRectangle As Integer = CInt(tickThickness * i)
                ProgressBarRectangles(i) = New Rectangle(ClientRectangle.X + InnerPadding,
                                                         ClientRectangle.Y + InnerPadding,
                                                         filledRectangle,
                                                         ClientRectangle.Height - (InnerPadding * 2))
            Next
        End Sub
    
    End Class
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been using php from some time and I have noticed that it
I have noticed that when using actionBar.setSelectedNavigationItem(x) in the onCreate() method of my Activity,
Using Dalvic Debug Monitor I have noticed that slight pauses in my game coincide
We're using the LightweightBrowserCache provided by RESTEasy 2.2.3.GA but have noticed that when the
I'm using the i18n feature of Django. I have noticed that even though I
In using PHP's DOM classes (DOMNode, DOMEElement, etc) I have noticed that they possess
I noticed that the launching of Java applets using deployJava.js seems to have stopped
I just started using Qt and noticed that all the example class definitions have
How do I have a UITableView be notified that the data it is using
I'm using protobuf-net r278 in C#, and I just noticed that if I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.