0

I have a standard desktop form with a picture as background and various labels on it. When i run the project I have the following output result: The form appear drawing the background nicely but for about 1/3 second my labels are white, as the color of label background is white, but it's set to transparent.

I tried to set the visibility of the form to false or the opacity to 0% and only after few seconds to make it visible, same result, nothing changed.

I tried also to use the double buffered graphic but my problem is not the flickering then nothing changed too.

Any idea on how to bypass this?

dbarnes
  • 1,803
  • 3
  • 17
  • 31
  • 1
    winforms? share some code. – Daniel A. White Apr 14 '15 at 19:37
  • Anything else going on when the form is loading (data access, etc)? – Rufus L Apr 14 '15 at 19:38
  • This sounds like WinForms but a little more detail, and possibly a screenshot of the issue would help. Also, if it is WinForms, one thing to know is that "transparent" is not truly transparent. It just takes on the background color of the container. Check out this article about that: http://weblog.west-wind.com/posts/2008/Feb/07/Transparent-Labels-in-WinForms – Daved Apr 14 '15 at 19:39
  • Try moving any heavy logic from the form load event handler to the form shown event handler. you might want to have the labels visible property set to false in designer and to true only on the form shown event – Zohar Peled Apr 14 '15 at 19:40
  • Yes i have some process at startup... but i have the same result also if i make the form visible after a lot of seconds. i tried also to disable them but with no results. – Guybrush Threepwood Apr 14 '15 at 19:44
  • Post your code if you want us to help. – maccettura Apr 14 '15 at 19:45
  • @Daved you are right! the problem is on the labels.... if i make it visible afterfew milliseconds the drawing it's so good...Now i need to find the best place (event) where to make it visibles! Thanks a lot – Guybrush Threepwood Apr 14 '15 at 19:49
  • @maccettura + Daniel A. White no code needed, the problem was caused because (as Daved say) the transparent color of controls is not real transparent and it take some time to snap the image behind and draw it as background – Guybrush Threepwood Apr 14 '15 at 19:51
  • @GuybrushThreepwood Default the labels, or container they are in depending on your setup, to hidden. Then show them only after you load what you need in the form. Typically, you have a form load event that you could add the visibility toggle to the end of. Alternatively, you can try the solution I linked to. – Daved Apr 14 '15 at 19:53
  • Your solution is to Thread.Sleep a few milliseconds to let the logic process before rendering? – maccettura Apr 14 '15 at 19:53
  • The solution of @Zohar Peled is perfectly working! Thanks a lot to all :-) – Guybrush Threepwood Apr 14 '15 at 19:54
  • @maccettura i don't know at this time the best place to make labels visible... i'm trying it... anyway if i make they visible with a simple button (then after the form loads) they display perfectly.. – Guybrush Threepwood Apr 14 '15 at 19:57

1 Answers1

1

Move any heavy logic from the form load event handler to the form shown event handler. You might also want to have the labels visible property set to false in designer and to set them back to true only on the form shown event.

Zohar Peled
  • 79,642
  • 10
  • 69
  • 121
  • your is the solution but as i tried no form events should correct the drawing.. making labels visible there does not work as expected.. i maked all the labels visible with a simple timer (activated by the form load event) with a delay of about 100 milliseconds.. – Guybrush Threepwood Apr 14 '15 at 20:12
  • Edit Again: To have the best result also set the form opacity to 0% and use the timer to bring it again to 100 after making controls visible and after an application.doevents() call. – Guybrush Threepwood Apr 14 '15 at 20:25