ProgressBar does not appear

  • Thread starter Thread starter George
  • Start date Start date
G

George

Windows XP, VB.net 2003

Cannot get the progress bar to appear.

I've followed the basic logic shown at:
http://msdn.microsoft.com/library/d.../frlrfsystemwindowsformsprogressbarclasstopic


frmMain.ProgressBar1.Show()
frmMain.ProgressBar1.Maximum = FilesArray.GetUpperBound(0) + 1
frmMain.ProgressBar1.Minimum = 1
frmMain.ProgressBar1.Step = 1

For Fi = 0 To FilesArray.GetUpperBound(0)
File.Copy(FilesArray(Fi), NewFile)
frmMain.ProgressBar1.PerformStep()
Next Fi

The code takes about 30 seconds, but the progressbar does not appear.
Any problem with Windows XP?

Thanks,
George
 
George,

try to Refresh the progress bar after modifying its value property, and see,
if that works.

Klaus
 
does this make any difference?

with frmMain.ProgressBar1

..Maximum = FilesArray.GetUpperBound(0) + 1
..Minimum = 1
..Step = 1
..visible = true

end with

hth

Richard
 
Klaus,
Thanks for the suggestion.

The ProgressBar control was in frmMain.vb.
The ProgressBar code was in another module (Files.vb),
code was: frmMain.ProgressBar1.Visible = True.

I moved the ProgressBar code to be in frmMain.vb,
code is now: Me.ProgressBar1.Visible = True.

This enabled the ProgressBar to appear.

But its operation improved much after adding your suggestion:
Me.ProgressBar1.Refresh()

So my question is: Must the ProgressBar code reside in the same
class/module as the control? Is this "written" somewhere?

Thanks again,
George
 
George,

Actually, it doesn't really matter where the code resides. But I strongly
recommend to encapsulate logical program units in self contained classes.
But this is not a "must" for having things really working.

If you'd asked me for my 2 cents: I'd create a class displaying the progress
bar in a seperate modeless form which contains the progress bar and nothing
else. I'd have a public value and a max property for this dialog, which
delegates those values to the progress bar and takes care of refreshing the
progress bar when the value changes.

Klaus
 
Klaus,
I have it working with your suggestion:
A separate form (frmProgress) that has only the ProgressBar1 control.
This seems to be better than taking space on the main form.

The Module has this code:Module ModuleFiles
Dim frmProgress As New frmProgress

Sub ConvertFiles()
frmProgress.ProgressBar1.Maximum = FilesArray.GetUpperBound(0) + 1
frmProgress.ProgressBar1.Minimum = 1
frmProgress.Show()

For Fi = 0 To FilesArray.GetUpperBound(0)
File.Copy(FilesArray(Fi), NewFile)
CountTotal = CountTotal + 1
frmProgress.ProgressBar1.Value = CountTotal
frmProgress.Refresh()
Next Fi
MsgBox(CountTotal & " files were converted.")
frmProgress.Hide()
End Sub

End Module
Another question:
Altho frmProgress.Hide() works, is it the right thing to do?
Close? Dispose?

Thanks,
George
 
George,

You use hide just to set a form's visible property to false. It simply
disapears from the screen, but it's still there (however, setting a form's
visible property to false disables its own message pump, if it has been
shown modally, previously).

If you close the form, you "emulate" that it has been closed by the user. In
this case you'll get the forms Closing event, where a procedure binding that
event can it prevent form closing with setting the right parameter in the
eventargs.

Disposing a form is definite. Once you disposed a form, it's gone, and you
can't do anything against it.

Hope that helps,

Klaus
 
What I forgot:

If you close a form, and nothing is be done to prevent it from closing, it's
disposed, too.
 
Back
Top