Reputation: 2779
I have a Panel as a container this panel has a picture on it as a background, within the container panel, I have another panel where I gonna put some information in labels, that information will change in time, what I want is a transition when a new info is about to show, fade out the information panel with the old info and then fade in the same panel with the new info. At the time of the fade out the information panel I will be able to see the backgroud image of the container panel. Both panels have BorderStyle=FixedSingle, also the info panel has a backcolor color.
Now my question is: is there any way to fade in/out the information panel and the whole content within too?
I was searching in the web, and I found an approach to this effect working with the panel's backcolor but it doesn't work at all, and besides, the content still there, since they just try to fade the backcolor property:
Timer tm = new Timer();
private void Form1_Shown(object sender, EventArgs e)
{
tm.Interval = 100;
tm.Tick += new EventHandler(timer1_Tick);
tm.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
int aa = 0;
panel2.BackColor = Color.FromArgb(aa, 255, 0, 0);
aa += 10;
if (aa > 255)
tm.Enabled = false;
}
Any help will be appreciated.
Upvotes: 9
Views: 10948
Reputation: 268
As suggested in other answers, you can not (easily without your own controls) fade in/out a panel.
You can fade the form in or out at start up OR have a modal dialog form that fades in or out.
Fade In
private void FadeIn_Tick(object sender, EventArgs e)
{
this.Opacity += .08;
if (this.Opacity >= 1)
{
FadeIn.Stop();
}
}
Fade Out
private void FadeOut_Tick(object sender, EventArgs e)
{
this.Opacity -= .08; //Decrease opacity
if (this.Opacity <= 0) //While it is not 0
{
FadeOut.Stop(); //Stop!
this.Close(); //Close the form
}
}
Upvotes: 2
Reputation: 15071
I don't believe you can set the opacity of individual controls. The form itself has an opacity, but I don't think you want to fade out the whole control.
You can create custom controls that support opacity...here's an example: http://www.slimee.com/2009/02/net-transparent-forms-and-controls-with.html
I believe this implementation would apply to child controls within the panel (because it is working on the rectangular area that the control takes up). If I'm wrong, you'd have to handle all of the child control's as part of your over-ridden behavior.
As others have said, getting this to look 'smooth' might be a lot of work. Hopefully someone will have a better answer.
Upvotes: 3