PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
[VB .NET] [Controls] [Extension] SmoothProgressBar-VBForums
Results 1 to 1 of 1

Thread: [VB .NET] [Controls] [Extension] SmoothProgressBar

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2009
    Posts
    629

    Post [VB .NET] [Controls] [Extension] SmoothProgressBar

    I made an extended progressbar which will change it's percentage based on a given time scale (in milliseconds).
    vb Code:
    1. Public Class SmoothProgressBar
    2.     Inherits ProgressBar
    3.  
    4.     Private _t As Threading.Thread
    5.     Private _trunning As Boolean
    6.     Private _time As Integer
    7.     Private oldproc As Integer
    8.     Private newproc As Integer
    9.     Private starttime As Date
    10.  
    11.     Public Sub SetProgress(ByVal percentage As Integer, Optional ByVal time As Integer = 200)
    12.         Me.Time = time
    13.         Me.Value = percentage
    14.     End Sub
    15.  
    16.     Public Property Time() As Integer
    17.         Get
    18.             Return Me._time
    19.         End Get
    20.         Set(ByVal value As Integer)
    21.             Me._time = value
    22.         End Set
    23.     End Property
    24.     Public Overloads Property Value() As Integer
    25.         Get
    26.             Return newproc
    27.         End Get
    28.         Set(ByVal value As Integer)
    29.             Me.newproc = value
    30.             Me.oldproc = MyBase.Value
    31.             Me.starttime = Date.Now
    32.             If Not _trunning Then
    33.                 _t = New Threading.Thread(AddressOf UpdateProgress)
    34.                 _t.IsBackground = True
    35.                 _t.Start()
    36.             End If
    37.         End Set
    38.     End Property
    39.  
    40.     Private Delegate Sub myadapter(ByVal perc As Integer)
    41.     Private Sub adapter(ByVal perc As Integer)
    42.         If Me.InvokeRequired Then
    43.             Me.Invoke(New myadapter(AddressOf adapter), perc)
    44.         Else
    45.             MyBase.Value = perc
    46.         End If
    47.     End Sub
    48.  
    49.     Private Sub UpdateProgress()
    50.         _trunning = True
    51.         Do
    52.             Dim elapsed As TimeSpan = Date.Now.Subtract(starttime)
    53.             If elapsed.TotalMilliseconds >= Me.time Then Exit Do
    54.             '====================================================
    55.             Dim percofperc As Double = elapsed.TotalMilliseconds / Me.time
    56.             adapter(oldproc + (newproc - oldproc) * percofperc)
    57.             Threading.Thread.Sleep(50)
    58.         Loop
    59.         adapter(newproc)
    60.         _trunning = False
    61.     End Sub
    62. End Class

    It uses a thread in the background, which will run until it is no longer needed. Usage:
    Code:
    SmoothProgressBar1.Time = 1000
    SmoothProgressBar1.Value = 20
    Code:
    SmoothProgressBar1.SetProgress(20, 1000)
    This can be useful for operations that take long, but don't have intermediate progresses. Say, you are waiting for a connection to a server, you could use the timeout value as time scale for this control.

    If a next value change is sent before the previous one is updated, it will simply start from the current value.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width