J Bradley
J Bradley

Reputation: 109

Windows form not repainting

I am new to C# but I have been programming with VB6 for a long time. I have a very simple project that runs without any errors. There is one problem however and it has to do with the Windows itself. If I open up any Window (from any other program) and that window overlaps my application...the moment I close that "other window", my application's Window does not repaint the portion that was overlapped by the "other window".

The same thing happens whenever the Bubbles screensaver comes on for Windows Vista. When I jiggle the mouse to cancel the screen saver, guess what??? I have bubbles scattered all over my Window. In VB, we had a simple "Window.Refresh" and voila! In C# however, this does not work. I have scoured the forum(s) and there seems to be a mention of "refreshing a thread". I'm kind of confused at this point. Why can't things be simple??

Upvotes: 2

Views: 5262

Answers (2)

James Love
James Love

Reputation: 1020

There is nothing special you should need to do to redraw the Form in C# (Form should redraw fine when you bring the window back to the top).

Do you have any third party controls in play? Control.Refresh() does exist in C#, should you should be able to call it from the Form itself (usually this.Refresh() in your Form's codebehind), or any Control which has children (like Panel).

Upvotes: 0

Reed Copsey
Reed Copsey

Reputation: 564333

You can call Form.Invalidate to invalidate the client area of the form. That will cause it to receive a paint message, and redraw itself.

This is similar to the VB6 Refresh method.

However, this should happen automatically. If your application is doing some processing in the UI thread, however, it will prevent it from processing its messages until the work is completed. If this is the case, you should consider using BackgroundWorker (or some other method) to push the work onto a background thread.

Upvotes: 2

Related Questions