Background color looping

M

mortb

Hi
I want to loop the background color on my "about" form.
This is the code I've tried to use. It doesn't work.
The about form newer shows up. I thought Application.DoEvents(); would allow
the form to show

help appreciated!
/mortb

private void frmAbout_Load(object sender, System.EventArgs e)
{
do
{
int color = 0;
for(; color < 255; color ++)
{
this.BackColor = Color.FromArgb(color, color, color);
Application.DoEvents();
}
for(; color > 0; color --)
{
this.BackColor = Color.FromArgb(color, color, color);
Application.DoEvents();
}
}
while(true);
}
 
W

Wiktor Zychla

I want to loop the background color on my "about" form.
This is the code I've tried to use. It doesn't work.
The about form newer shows up. I thought Application.DoEvents(); would allow
the form to show

the problem with your code is that the Load event never ends.

put then a timer on your form and move the code from the Load event into the
timer's tick event handler. in the Load event just start the timer.

this should work.

regards,
Wiktor Zychla
 
H

Herfried K. Wagner [MVP]

* "Wiktor Zychla said:
the problem with your code is that the Load event never ends.

Another problem is that the form is not yet visible when the 'Load'
event handler is executed.
 
M

mortb

I solved it by putting a timer on the form -- the "infinte loop" approach
consumed to much CPU.

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top