|
-
Mar 3rd, 2005, 05:42 AM
#1
Thread Starter
Fanatic Member
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
-
Mar 3rd, 2005, 06:01 AM
#2
Hyperactive Member
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:
#Region "Imports"
Imports System.ComponentModel
#End Region
<ToolboxBitmap(GetType(ProgressStatusBar))> Public Class ProgressStatusBar : Inherits StatusBar
Private _progressBar As System.Windows.Forms.ProgressBar
Private _progressPosition As Integer = -1
#Region "Instantiation"
Public Sub New()
'instantiate the progress bar
_progressBar = New ProgressBar
'don't allow it to display yet
_progressBar.Hide()
'add to the controls collection of the status bar
Controls.Add(ProgressBar)
End Sub
#End Region
#Region "Property Procedures"
<Description("Gets or sets the position of the progress bar."), Category("Appearence")> _
Public Property ProgressPosition() As Integer
Get
Return _progressPosition
End Get
Set(ByVal Value As Integer)
'check to see if a valid value has been passed
If Value > PanelCount - 1 Then
Throw New ArgumentOutOfRangeException(ProgressPosition, Value, "Enter a value that is within the bounds of the panel count.")
Exit Property
End If
Dim panel As StatusBarPanel
_progressPosition = Value
'reset all the panels to text
Try
For Each panel In Panels
panel.Style = StatusBarPanelStyle.Text
Next
Finally
panel = Nothing
End Try
'set the property of the selected panel to owner drawn
Panels(_progressPosition).Style = StatusBarPanelStyle.OwnerDraw
End Set
End Property
<Description("Gets the progress bar object."), Browsable(False)> _
Public ReadOnly Property ProgressBar() As System.windows.forms.ProgressBar
Get
'returns the progress bar as an object allowing its properties to be set as normal
Return _progressBar
End Get
End Property
<Browsable(False), Description("Gets the number of panels in the status bar.")> _
Public ReadOnly Property PanelCount() As Integer
Get
Dim panel As StatusBarPanel
Dim count As Integer = 0
Try
For Each panel In Panels
count += 1
Next
Finally
panel = Nothing
End Try
Return count
End Get
End Property
#End Region
#Region "Private Procedures"
Private Sub Reposition(ByVal sender As Object, ByVal e As StatusBarDrawItemEventArgs) Handles MyBase.DrawItem
'set the location of the status bar to the x and y of the eventargs
_progressBar.Location = New Point(e.Bounds.X, e.Bounds.Y)
'set the size to fill the panel
_progressBar.Size = New Size(e.Bounds.Width, e.Bounds.Height)
'display the progress bar
_progressBar.Show()
End Sub
#End Region
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 
-
Mar 3rd, 2005, 06:18 AM
#3
Thread Starter
Fanatic Member
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
-
Mar 3rd, 2005, 06:29 AM
#4
Hyperactive Member
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"
-
Mar 3rd, 2005, 06:34 AM
#5
Hyperactive Member
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:
'work out how much to progress each time
mdiForm.sbrMain.ProgressBar.Step = CType(100 / doc.Bookmarks.Count, Integer)
For Each bookmark In doc.Bookmarks
'do your processing here
'then increment the progress bar
mdiForm.sbrMain.ProgressBar.PerformStep()
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 
-
Mar 3rd, 2005, 06:35 AM
#6
-
Mar 3rd, 2005, 06:41 AM
#7
Hyperactive Member
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 
-
Mar 3rd, 2005, 06:53 AM
#8
Hyperactive Member
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 
-
Mar 3rd, 2005, 07:25 AM
#9
Hyperactive Member
Re: Progress Indicator
Wow! I'm gonna try that next week.
Thanks.
"I'm Brian and so is my Wife"
-
Mar 24th, 2005, 06:05 PM
#10
Frenzied Member
-
Mar 25th, 2005, 02:39 PM
#11
Frenzied Member
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..
-
Mar 25th, 2005, 02:44 PM
#12
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|