Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi how to create transparent panel for use png image?

and how to create animation for panel show???
Posted
Comments
Sergey Alexandrovich Kryukov 13-Aug-13 11:40am    
What do you mean by "Panel"? Exact and full type name, please.
How the transparency should be manifested? The purpose?
You should always tag the UI library or application type you want to use (WPF, Forms...?)...
—SA

1 solution

Hi - Found the following code whith works not only for panels but also for buttons and I guess other controls --except PictureBox


public class TransparentPanel : Panel <==change to Button for instance, and works
    {
        Timer Wriggler = new Timer();
        public TransparentPanel()
        {
            Wriggler.Tick += new EventHandler(TickHandler);
            this.Wriggler.Interval = 500;
            this.Wriggler.Enabled = true;
        }
        protected void TickHandler(object sender, EventArgs e)
        {
            this.InvalidateEx();
        }
        protected override CreateParams CreateParams
        {
            get
            {
                CreateParams cp = base.CreateParams;
                cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT 
                return cp;
            }
        }
        protected void InvalidateEx()
        {
            if (Parent == null)
            {
                return;
            }
            Rectangle rc = new Rectangle(this.Location, this.Size);
            Parent.Invalidate(rc, true);
        }
        protected override void OnPaintBackground(PaintEventArgs pevent)
        {
            // Do not allow the background to be painted  
        }
    }
 
Share this answer
 
Comments
hadi-z 14-Aug-13 2:02am    
thanks
but, i want a png image as my menu with some animation show on my form.

this control not work very good

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900