Windows Develop Bookmark and Share   
 index > Windows Forms General > Force a form to redraw
 

Force a form to redraw

Hi all,

When opening my application it needs to load quite a lot of images. I would like to show a progress form so I made a second form containing a progressbar and a label. When an image is loaded I update the label and the progressbar and then call Refresh() of the progress form, otherwise the label does not update correctly. This works fine, but when the progressform is moved, or another application is shown over the progressform (because it is maximized) and then minimized, the progressform does not update anymore.

How can I solve this?

kind regards,

Jef

Jef Patat  Wednesday, January 17, 2007 9:31 AM

HI

first off, are you doing this in an asynchroneous way? (you probably should be)

otherwise the gui will block will it's loading a file, which is probably not what you want

however, related to your problem:

try, instead of calling Refresh(), to call:
this.Invalidate()
http://msdn2.microsoft.com/en-us/library/598t492a.aspx

Hope this helps, please close the thread if it does

frederikm  Wednesday, January 17, 2007 12:02 PM

I'm not doing it async. It is for personal use and I can do nothing with the app as long as images are not loaded.

I did try Invalidate() before, but that just makes it worse, the text doesn't refresh anymore. So I thought that was the wrong way.

Other ideas?

Jef Patat  Wednesday, January 17, 2007 1:50 PM

You could use a Backgroundworker control to do it async.

Your form won't do anything as long as it's loading the images. A possibility to refresh the form and receive user input at least from time to time would be to call Application.DoEvents() after having loaded an image.

Greets

rlnd  Wednesday, January 17, 2007 1:57 PM

Hi

can you post the code?

frederikm  Wednesday, January 17, 2007 10:07 PM

Application.DoEvents()

{load image 1}
Application.DoEvents();
{load image 2}
Application.DoEvents();
...

BackgroundWorker

  • Add a BackgroundWorker to your form
  • Handle the BackgroundWorker's DoWork event - here goes your code to load those images
  • In Form_Load, start the BackgroundWorker - backgroundWorker.RunWorkerAsync()
rlnd  Thursday, January 18, 2007 7:14 AM

You can use google to search for other answers

Custom Search

More Threads

• Appending RichTextBox Data
• Application.AddMessageFilter Question
• WebBrowser Control Waiting..
• Get text in combo box
• How to port C to VB.NET
• Panel ClientSize
• Ending A Process
• Problem in using Journal Hooks
• Form Instance
• Common Language Runtime Debugging Services