如何创建透明面板 [英] How to create transparent panel
本文介绍了如何创建透明面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
如何创建透明面板以使用png图像?
以及如何为面板显示创建动画???
解决方案
嗨 - 发现以下代码不仅适用于面板而且适用于按钮,我猜其他控件 - 除了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 } }
这篇关于如何创建透明面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文