Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Newbie with Progress Bar Question

0 views
Skip to first unread message

What To Do

unread,
Nov 20, 2009, 11:27:03 AM11/20/09
to
Hi All,

Sorry newbie here ...... I have a Splash Screen and am trying to get a
progress bar to work on the bottom. My splash screen stays on for 8000ms and
I would like the bar to go up in time with that.

I have the following code:

private void frmSplash_Load(object sender, EventArgs e)
{
prbSplash.Minimum = 0;
prbSplash.Maximum = 8000;
{
}
int value;
for (value = 0; value != 8000; value++)
{
prbSplash.Value = prbSplash.Value + 1;
}
}

This seems to just wizz up though. How can I slow it down a bit?

Cheers Everyone
Si

Jeff Johnson

unread,
Nov 20, 2009, 11:45:40 AM11/20/09
to
"What To Do" <nos...@nospam.com> wrote in message
news:eSZbN5fa...@TK2MSFTNGP02.phx.gbl...

If your splash screen is staying up for 8 seconds you must have some means
of determining when that 8 seconds is up. (I'll go out on a limb and say a
timer...?) Use that same method to update the progress bar.


What To Do

unread,
Nov 20, 2009, 11:52:09 AM11/20/09
to
Yep I have a timer in place:)

Sorry im a totally newbie to C# and Development in general. Could you
possible supply me with a link or example code to help me?

Im guessing i need to change my code below to use the timer?

Cheers
Si

"Jeff Johnson" <i....@enough.spam> wrote in message
news:%23A5JmDg...@TK2MSFTNGP04.phx.gbl...

Mr. Arnold

unread,
Nov 20, 2009, 12:24:04 PM11/20/09
to
What To Do wrote:
> Yep I have a timer in place:)
>
> Sorry im a totally newbie to C# and Development in general. Could you
> possible supply me with a link or example code to help me?
>
> Im guessing i need to change my code below to use the timer?
>

Your friend is Bing or Google.

http://www.codeproject.com/KB/cs/prettygoodsplashscreen.aspx

Jeff Johnson

unread,
Nov 20, 2009, 1:34:58 PM11/20/09
to
"What To Do" <nos...@nospam.com> wrote in message
news:OycZPHga...@TK2MSFTNGP05.phx.gbl...

> Yep I have a timer in place:)
>
> Sorry im a totally newbie to C# and Development in general. Could you
> possible supply me with a link or example code to help me?
>
> Im guessing i need to change my code below to use the timer?

No, you need to MOVE your code into the timer event. Hopefully you do NOT
simply have your timer interval set to 8000ms. If so, change it to something
smaller (let's say 80ms, 1% of the total time your splash screen displays)
and then have a private variable (a "field," i.e., a variable at the form
level, NOT a variable local to the timer event handler) and increment that
variable by 1 every time the event fires. Then you can set the value of your
progress bar to this amount (change the max of your progress bar to 100
instead of the 8000 it appears to be at). That way the event should be
called 100 times and you'll run your progress bar up to 100%. (Throw in some
error checking just to be sure your variable doesn't go above 100.)

I'm explaining this in words instead of giving you code because there's
nothing better to help a (self-proclaimed) newbie than actually writing
code.


Peter Duniho

unread,
Nov 20, 2009, 2:00:34 PM11/20/09
to
What To Do wrote:
> Yep I have a timer in place:)
>
> Sorry im a totally newbie to C# and Development in general. Could you
> possible supply me with a link or example code to help me?
>
> Im guessing i need to change my code below to use the timer?

My first advice is for you to not set a fixed time for your splash
screen to be displayed. Forcing a user to wait 8 seconds just because
you think he should is likely to annoy the user.

If you actually have some lengthy initialization that has to occur, then
that initialization should be able to report its progress, and that is
the progress that should be indicated in the ProgressBar as it changes.

If you are actually waiting 8 seconds arbitrarily, then the progress is
the passage of time. You can set a timer for some smaller interval
(e.g. 100ms), and then update the progress bar each time the timer
fires. For example:

private void frmSplash_Load(object sender, EventArgs e)
{
prbSplash.Minimum = 0;
prbSplash.Maximum = 8000;

DateTime dtStart = DateTime.Now;
System.Windows.Forms.Timer timer = new
System.Windows.Forms.Timer();

timer.Interval = 100;
timer.Tick += (sender, e) =>
{
int ms = (int)(DateTime.Now -
dtStart).TotalMilliseconds;
if (ms < prbSplash.Maximum)
{
prbSplash.Value = ms;
}
else
{
prbSplash.Value = prbSplash.Maximum;
timer.Stop();

// Do whatever here to clean up
// the splash screen. For example...
this.Close();
}
};

timer.Start();
}

Or something like that.

Pete

0 new messages