2

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).

Frederick
  • 213
  • 1
  • 5
  • 14
  • It sounds like there are one or more controls on the form that are slowing the painting down - what component(s) are shown on the troublesome panel? – Will A Jul 31 '10 at 19:18
  • @Will, one panel has a groupBox that contains three labels, one textbox, and one button. The other panel has a groupBox that contains a second panel that has six labels and a third panel, this third panel shows some data pulled from an SQL database (the data is just a few rows of user account names). – Frederick Jul 31 '10 at 19:32
  • How does the SQL data get displayed on the third panel - is this panel owner-drawn, or does it contain e.g. a DataGridView? – Will A Jul 31 '10 at 19:37
  • The SQL data is written into several tabs of a TableLayoutPanel control. – Frederick Jul 31 '10 at 19:41

1 Answers1

2

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.

Community
  • 1
  • 1
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • 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 Jul 31 '10 at 20:17