Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fade in/out a panel with content within using c#

Tags:

c#

.net

winforms

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.

like image 823
Somebody Avatar asked Sep 16 '11 16:09

Somebody


1 Answers

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.

like image 152
Rob P. Avatar answered Sep 20 '22 20:09

Rob P.