1

I'm trying to animate a user-control which has transparent backcolor. While animating (i.e. moving control up-down in vertical direction) user-control the backcolor does not refresh.

I have placed the control on the top of picturebox and then animating it. The picturebox has gradeitn color as backcolor with bottom starting as red to blue. Also user-control has traingle shape on it.

Code is in C# on windows OS.

I tried so many options but still facing same issue.Below is the code :

namespace AC
{
    public partial class MyTriangle: UserControl
    {
        public MyTriangle()
        {
            InitializeComponent();
            DefaultSettings();
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.BackColor = Color.Transparent;
        }


        /// <summary>
        /// Method for Transparent background
        /// </summary>
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x20;
                return cp;
            }
        }

        protected override void OnPaintBackground(PaintEventArgs e)
        {

        }

        protected void InvalidateEx()
        {
            this.Invalidate();
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            //base.OnPaint(e);
        }

    }
}

i believe whatever change we need to do is int user-control only. Please see attached traingle shape (tmp.png) and picturebox color (tmp1.png)![enter image description here][1] for reference.![enter image description here][2]

Thanks

3
  • I strongly suggest WPF if you need Rich UI features such as Animation and Transparency. winforms doesn't really support any of that.
    – Fede
    Feb 3, 2014 at 13:30
  • Please fix images in your question. Do you know about AnimateWindow? Otherwise, you may be stumbling at doing common mistake - drawing whole animation at once (this way nothing gets repainted properly, unless forced, with Refresh(), including that what is behind). Split it into frames, use timer, win.
    – Sinatr
    Feb 3, 2014 at 13:35
  • currently not able to attach image. I need to use Winforms only not wpf as of now.
    – user3265575
    Feb 4, 2014 at 3:01

0

Your Answer

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