且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建透明面板

更新时间:2023-11-17 16:08:46

嗨 - 发现以下代码不仅适用于面板而且适用于按钮,我猜其他控件 - 除了PictureBox





公共类TransparentPanel:Panel< ==更改为按钮,例如,工作
{
Timer Wriggler = new Timer() ;
public TransparentPanel()
{
Wriggler.Tick + = new EventHandler(TickHandler);
this.Wriggler.Interval = 500;
this.Wriggler.Enabled = true;
}
protected void TickHandler(对象发送者,EventArgs e)
{
this.InvalidateEx();
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle | = 0x00000020; // WS_EX_TRANSPARENT
返回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)
{
//不允许背景被绘制
}
}


hi how to create transparent panel for use png image?

and how to create animation for panel show???

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  
        }
    }