9

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.

5
  • I don't know much about WPF, but if that is an option for you, it might be a better choice to achieve the effect you're looking for. en.wikipedia.org/wiki/Windows_Presentation_Foundation
    – Kiley Naro
    Sep 16, 2011 at 17:58
  • Yes, in WPF you just create an animation that changes the opacity of the panel over time. Sep 16, 2011 at 18:34
  • 1
    The problem you are going to face is that Opacity is only available at the form level, not the control level. Maybe a clever hack where you create an identical image on a form overlaying your panel and once the opactiy is at 100%, you hide the form. Winforms isn't good at this.
    – LarsTech
    Sep 16, 2011 at 18:39
  • Indeed. Trying to do this in WinForms will cause you nothing but pain. It'd be like ramming a square peg in a round hole. Even if you can't change your whole app to WPF, there are ways to make WPF controls, and then host them in WinForms—that might be something to look at. Sep 16, 2011 at 19:07
  • Thank you all for your comments, Kiley Naro, Robert Rossney, I am in the same page, I know nothing about WPF :( LarsTech you right the opacity is just for the forms, maybe I have to try something different. I agree Adam Rackis
    – Somebody
    Sep 17, 2011 at 3:51

2 Answers 2

3

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.

1
  • I appreciate your answer, I agree with you, the intention of this app is to have a dashboard in a big TV where some info will be showing in time, that's why I need to use some visual effects to give the viewers a nice experience. Perhaps I need to find another tool to do this.
    – Somebody
    Sep 19, 2011 at 12:26
2

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
        }
    }
2
  • thanks for respond MisdartedPenguin but your solution applies just to forms (like you said).
    – Somebody
    Sep 23, 2011 at 19:08
  • This is not a solution for this question. Not even close
    – Ghasem
    Dec 28, 2015 at 4:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.