By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 711 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

form becoming black while increasing opacity from 0 to 1

100+
P: 153
I am ShowDialoging one form in which the activate event increases the opacity from 0 to 1. I set the opacity to 0 in it's constructor.The problem is that during the showing of the form it becomes black.
And after it's opacity becomes one it becoems the normal color (Control).
The code is as follows

Expand|Select|Wrap|Line Numbers
  1.          public Form1()
  2.         {
  3.             InitializeComponent();
  4.             this.Opacity = 0;
  5.         }
  6.  
  7.         private void Form1_Activated(object sender, EventArgs e)
  8.         {
  9.             while (this.Opacity < 1)
  10.             {
  11.                 this.Opacity += .01;
  12.                 Thread.Sleep(100);
  13.             }
  14.         }

I wanted to show the screenshot but when i print-screen while it is black and paste it in MS Paint it shows the normal way !
Tha's weird.How to get around this ?

EDIT:I found the solution.The thread is Sleeping so how would it display the opacity changed form !
I used this.Refresh(); before the sleep and it worked.
Jan 6 '09 #1
Share this Question
Share on Google+
1 Reply


Plater
Expert 5K+
P: 7,872
Yup you are correct. That loop is also known as a "busy loop" as it keeps the thread busy and does not allow it to process the windows messages (which by calling Refresh() you are forcing it to do.) Application.DoEvents() should also work.
Jan 6 '09 #2

Post your reply

Sign in to post your reply or Sign up for a free account.