views:

61

answers:

1

Various controls (mostly labels and panels) on my fairly simple c# WinForm form are not painted when the form is shown. They finish being painted about a half second after the form is shown.

Is there an easy fix to this?

More details:

The panel that paint the slowest displays some data read from an SQL database. The data is painted, by the text labels and background are not. The panel holds a very small amount of data pulled from the database.

Another panel that finishes painting after the form appears only contains a few labels, one text control and one button.

Also, this form lays on top of another form whose only purpose is to cover the computer screen with a semi-transparent background. When I delete this background form from the application the same controls still fail to finish painting before the form is shown (but now they finish being painted by only about a quarter second instead of by about a half second).

+1  A: 

This is standard Windows User32 rendering behavior. The form and most of the controls are individual windows. They each get a WM_PAINT message to tell them that they need to paint themselves, those messages are delivered one-by-one to each window, in Z-order. When a control is slow to paint itself, that gets to be noticeable. The unpainted rectangle of that control, and the ones after it, are visible for a brief moment.

Standard double-buffering techniques available in Windows Forms cannot solve this problem, you'd have to double-buffer the entire form. That's possible, my answer in this thread shows you how.

Hans Passant
@Hans: Yes, that seems to have done it (I need to test it a little more to be sure). Once again, thanks for your great help.
Frederick