Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7805767
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:19:08+00:00 2026-06-02T02:19:08+00:00

I have a details panel which can be shown or hidden. How can I

  • 0

I have a details panel which can be shown or hidden.

How can I made a simple fade effect for showing/hiding that panel (and of course its contents) ?

I am using Windows forms, and controls don’t have opacity property in windows forms.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T02:19:09+00:00Added an answer on June 2, 2026 at 2:19 am

    This is quite do-able in Winforms, it only has to look like a fade. One technique is to use Control.DrawToBitmap() to create a bitmap of the control. And then blend from a background bitmap to the foreground bitmap with a timer.

    I’ll use a UserControl instead of a Panel so you can design the control with the Winforms designer. The code will however work in any kind of control. Add a new class to your project and paste the code shown below. Compile. Create your own UserControl from this one with Project + Add New Item, Windows Forms node, “Inherited User Control” template and pick FadeControl from the popup list. Design the user control as normal.

    As written, the control will automatically fade from the parent’s BackColor to the control content as soon as you add the control to the parent. Call FadeOut() to make it blend back to the background. Pass true if you want to automatically dispose the control when it is done fading. You can use FadeIn() and the Faded property for manual control of the fading. You can adjust the numbers in the lines commented with // tweakable to adjust the animation. Additional work is needed if the parent has a non-opaque background.

    using System;
    using System.Drawing;
    using System.Drawing.Imaging;
    using System.Windows.Forms;
    
    class FadeControl : UserControl {
    
        public FadeControl() {
            pbox = new PictureBox();
            pbox.BorderStyle = BorderStyle.None;
            pbox.Paint += new PaintEventHandler(pbox_Paint);
            fadeTimer = new Timer();
            fadeTimer.Interval = 15;   // tweakable
            fadeTimer.Tick += new EventHandler(fadeTimer_Tick);
        }
    
        public bool Faded {
            get { return blend < 0.5f; }
        }
        public void FadeIn() {
            stopFade(false);
            createBitmaps();
            startFade(1);
        }
        public void FadeOut(bool disposeWhenDone) {
            stopFade(false);
            createBitmaps();
            disposeOnComplete = disposeWhenDone;
            startFade(-1);
        }
    
        private void createBitmaps() {
            bmpBack = new Bitmap(this.ClientSize.Width, this.ClientSize.Height);
            using (var gr = Graphics.FromImage(bmpBack)) gr.Clear(this.Parent.BackColor);
            bmpFore = new Bitmap(bmpBack.Width, bmpBack.Height);
            this.DrawToBitmap(bmpFore, this.ClientRectangle);
        }
        void fadeTimer_Tick(object sender, EventArgs e) {
            blend += blendDir * 0.02F;   // tweakable
            bool done = false;
            if (blend < 0) { done = true; blend = 0; }
            if (blend > 1) { done = true; blend = 1; }
            if (done) stopFade(true); 
            else pbox.Invalidate();
        }
        void pbox_Paint(object sender, PaintEventArgs e) {
            Rectangle rc = new Rectangle(0, 0, pbox.Width, pbox.Height);
            ColorMatrix cm = new ColorMatrix();
            ImageAttributes ia = new ImageAttributes();
            cm.Matrix33 = blend;
            ia.SetColorMatrix(cm);
            e.Graphics.DrawImage(bmpFore, rc, 0, 0, bmpFore.Width, bmpFore.Height, GraphicsUnit.Pixel, ia);
            cm.Matrix33 = 1F - blend;
            ia.SetColorMatrix(cm);
            e.Graphics.DrawImage(bmpBack, rc, 0, 0, bmpBack.Width, bmpBack.Height, GraphicsUnit.Pixel, ia);
        }
    
        private void stopFade(bool complete) {
            fadeTimer.Enabled = false;
            if (complete) {
               if (!Faded) this.Controls.Remove(pbox);
               else if (disposeOnComplete) this.Dispose();
            }
            if (bmpBack != null) { bmpBack.Dispose(); bmpBack = null; }
            if (bmpFore != null) { bmpFore.Dispose(); bmpFore = null; }
        }
        private void startFade(int dir) {
            this.Controls.Add(pbox);
            this.Controls.SetChildIndex(pbox, 0);
            blendDir = dir;
            fadeTimer.Enabled = true;
            fadeTimer_Tick(this, EventArgs.Empty);
        }
    
        protected override void OnCreateControl() {
            base.OnCreateControl();
            if (!DesignMode) FadeIn();
        }
        protected override void OnResize(EventArgs eventargs) {
            pbox.Size = this.ClientSize;
            base.OnResize(eventargs);
        }
        protected override void Dispose(bool disposing) {
            if (disposing) {
                stopFade(false);
                pbox.Dispose();
                fadeTimer.Dispose();
            }
            base.Dispose(disposing);
        }
    
        private PictureBox pbox;
        private Timer fadeTimer;
        private Bitmap bmpBack, bmpFore;
        private float blend;
        private int blendDir = 1;
        private bool disposeOnComplete;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an mxml panel in which I'm using a repeater. The panel can
I have a simple ExtJs form panel which contains a fileuploadfield. When I submit
In a Ruby on Rails app, we have some details which are stored as
I have a personal details form that allows you to enter a certain number
I have a aspx page (details page) that needs to be loaded in a
i have view like 'home/details/5', it can be access by anonymous user. but there
I have a gridview that displays items details, I added two template fields one
I have a simple app I am messing around with its a basic Master/Details
How can one obtain the panel that is used within a TreeView ? I've
I have a program that creates UIViewControllers in a UISplitView depending upon which row

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.