ChangYou Wong
ChangYou Wong

Reputation: 93

Easiest way to show update on a form when stucked in a function (OnPaint) for a long time

I am loading something that takes a long time in OnPaint function the first time I run my program, and I need a way to show my progress. I already have the progress stuff up, but I just don't know the simplest way to show it.

Want either

  1. Something to keep the form responsive when stucked in OnPaint function for a prolonged period, I am changing the title name to show progression and I want the form to stay responsive!

  2. Pop up something else that is easily created to show progress

btw, I am loading it only OnPaint because I wanted the form to show up so that the user will know that the program opened correctly. Otherwise nothing will happen while the form loads, and the user might think that the program was not even opened.

Upvotes: 0

Views: 143

Answers (2)

ChangYou Wong
ChangYou Wong

Reputation: 93

DoEvent

As per mentioned by Jeremy Thompson, many thanks

Though I need to wait 2 days to be able to accept this answer.

Upvotes: 0

Chris Keller
Chris Keller

Reputation: 253

There is not a lot of context here, but if I understand correctly it appears that you have something that needs to happen when the form loads and it might take a long time. You are trying to do this in the paint event because you want to make sure that the user sees something while whatever is loading completes.

Is that assessment correct?

If so, I recommend that you consider the BackgroundWorker class as it will let you do the expensive 'loading' you discuss while keeping the UI responsive.

The example with the documentation does a great job so I'll not write another sample here...

BackgroundWorker Class

Chris

Upvotes: 2

Related Questions