Results 1 to 12 of 12

Thread: Progress Indicator

  1. #1

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Progress Indicator

    Guys,

    Whats the best way of informing users of task progress. I want this to be really visual, something in the middle of the screen rather than hour glass on cursor or something in the status bar.

    In Excel, I would show a small user form with the text "Task in Progress, please wait", and then I would put all the working code on the activate event of that form.

    Is there an easy way to do this in .NET ?

    Thanks
    Bob

  2. #2
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: Progress Indicator

    How about a small form with a progress bar on it?

    Or use this custom status bar which hosts a progress bar in it:

    VB Code:
    1. #Region "Imports"
    2. Imports System.ComponentModel
    3. #End Region
    4. <ToolboxBitmap(GetType(ProgressStatusBar))> Public Class ProgressStatusBar : Inherits StatusBar
    5.     Private _progressBar As System.Windows.Forms.ProgressBar
    6.     Private _progressPosition As Integer = -1
    7. #Region "Instantiation"
    8.     Public Sub New()
    9.         'instantiate the progress bar
    10.         _progressBar = New ProgressBar
    11.         'don't allow it to display yet
    12.         _progressBar.Hide()
    13.         'add to the controls collection of the status bar
    14.         Controls.Add(ProgressBar)
    15.     End Sub
    16. #End Region
    17. #Region "Property Procedures"
    18.     <Description("Gets or sets the position of the progress bar."), Category("Appearence")> _
    19.     Public Property ProgressPosition() As Integer
    20.         Get
    21.             Return _progressPosition
    22.         End Get
    23.         Set(ByVal Value As Integer)
    24.             'check to see if a valid value has been passed
    25.             If Value > PanelCount - 1 Then
    26.                 Throw New ArgumentOutOfRangeException(ProgressPosition, Value, "Enter a value that is within the bounds of the panel count.")
    27.                 Exit Property
    28.             End If
    29.             Dim panel As StatusBarPanel
    30.             _progressPosition = Value
    31.             'reset all the panels to text
    32.             Try
    33.                 For Each panel In Panels
    34.                     panel.Style = StatusBarPanelStyle.Text
    35.                 Next
    36.             Finally
    37.                 panel = Nothing
    38.             End Try
    39.             'set the property of the selected panel to owner drawn
    40.             Panels(_progressPosition).Style = StatusBarPanelStyle.OwnerDraw
    41.         End Set
    42.     End Property
    43.  
    44.     <Description("Gets the progress bar object."), Browsable(False)> _
    45.     Public ReadOnly Property ProgressBar() As System.windows.forms.ProgressBar
    46.         Get
    47.             'returns the progress bar as an object allowing its properties to be set as normal
    48.             Return _progressBar
    49.         End Get
    50.     End Property
    51.  
    52.     <Browsable(False), Description("Gets the number of panels in the status bar.")> _
    53.     Public ReadOnly Property PanelCount() As Integer
    54.         Get
    55.             Dim panel As StatusBarPanel
    56.             Dim count As Integer = 0
    57.             Try
    58.                 For Each panel In Panels
    59.                     count += 1
    60.                 Next
    61.             Finally
    62.                 panel = Nothing
    63.             End Try
    64.             Return count
    65.         End Get
    66.     End Property
    67. #End Region
    68. #Region "Private Procedures"
    69.     Private Sub Reposition(ByVal sender As Object, ByVal e As StatusBarDrawItemEventArgs) Handles MyBase.DrawItem
    70.         'set the location of the status bar to the x and y of the eventargs
    71.         _progressBar.Location = New Point(e.Bounds.X, e.Bounds.Y)
    72.         'set the size to fill the panel
    73.         _progressBar.Size = New Size(e.Bounds.Width, e.Bounds.Height)
    74.         'display the progress bar
    75.         _progressBar.Show()
    76.     End Sub
    77. #End Region
    78. End Class
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  3. #3

    Thread Starter
    Fanatic Member staticbob's Avatar
    Join Date
    Jan 2005
    Location
    Manchestershire, UK Cabbage: I do
    Posts
    619

    Re: Progress Indicator

    Thanks Squizz, your the greatest. . . or was that dangermouse ?

    Anyway, how do I implement this ? Does it go into its own module, if so how do I then call and show it from my current code . .

    Ta
    Bob

  4. #4
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307

    Re: Progress Indicator

    Hi Squirrel,

    Can I use this same technique for embedding a combo into a toolbar??

    Sorry for hijaking your thread Staticbob!
    "I'm Brian and so is my Wife"

  5. #5
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: Progress Indicator

    Create a new windows controls project.

    Delete any default controls .NET adds then add a new component control.

    Delete everything in the code window and paste in the stuff from above.

    Build the project.

    In your actual project, right click the toolbox, choose add/remove (or whatever it says) then navigate to the bin folder for your controls project. Select the .dll file and it should add itself to your toolbox.

    To use it, do something like this: (this is an example where I was iterating through bookmarks in a word document)

    VB Code:
    1. 'work out how much to progress each time
    2.             mdiForm.sbrMain.ProgressBar.Step = CType(100 / doc.Bookmarks.Count, Integer)
    3. For Each bookmark In doc.Bookmarks
    4.    'do your processing here
    5.     'then increment the progress bar
    6.     mdiForm.sbrMain.ProgressBar.PerformStep()
    7. Next
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  6. #6
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: Progress Indicator

    Lee,

    I've never tried it but probably....

    <...sound of squirrel paws scampering off to try it out>

    Will report back later
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  7. #7
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: Progress Indicator

    One more thing....lose the bit at the top about the toolbox bitmap unless you add a bitmap to your project called ProgressStatusBar.bmp
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  8. #8
    Hyperactive Member Lil Ms Squirrel's Avatar
    Join Date
    Nov 2004
    Location
    planet squirrel
    Posts
    494

    Re: Progress Indicator

    Lee,

    Yes you can.

    It should work for hosting any control...
    Be who you are and say what you feel, because those who mind don't matter and those who matter don't mind.
    Dr. Seuss

  9. #9
    Hyperactive Member LeeSalter's Avatar
    Join Date
    Oct 2002
    Location
    Notts, England
    Posts
    307

    Re: Progress Indicator

    Wow! I'm gonna try that next week.
    Thanks.

    "I'm Brian and so is my Wife"

  10. #10
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Progress Indicator

    Thanks A Million!

  11. #11
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Progress Indicator

    I cant seem to get it to work..

    i have created the DLL but i cant seem to use the
    progressbar.step = (whatever)

    Help..

  12. #12
    Frenzied Member dinosaur_uk's Avatar
    Join Date
    Sep 2004
    Location
    Jurassic Park
    Posts
    1,098

    Re: Progress Indicator

    OK got it to work now..

    how do i set the max and the min bound for the progress bar?

Posting Permissions

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



Click Here to Expand Forum to Full Width