读书人

[C#关于绘制透明控件的]

发布时间: 2013-08-04 18:26:16 作者: rapoo

[C#关于绘制透明控件的求助]

设计视图

代码:

public MyTransparentControl()
{
InitializeComponent();

SetStyle(ControlStyles.SupportsTransparentBackColor

| ControlStyles.UserPaint

| ControlStyles.AllPaintingInWmPaint

| ControlStyles.Opaque, true);


base.CreateControl();

this.BringToFront();
}

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

for (int i = 0; i < this.Width; i += 100)//画线
{
e.Graphics.DrawLine(new Pen(Color.Gray), new Point(i + 50, 0), new Point(i, this.Height - 1));
}
}

protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;

cp.Style |= 0x00000020;
//WS_EX_TRANSPARENT



return cp;
}
}



运行时:
[C#关于绘制透明控件的]
后面就是桌面……

为啥我不能实现这个效果:
[C#关于绘制透明控件的]
虚心求大神解答。 没人知道?
同3楼 看法
[解决办法]
class TransparentControl:Control
{
protected override CreateParams CreateParams
{
get
{
CreateParams para = base.CreateParams;
para.ExStyle
[解决办法]
= 0x00000020; //WS_EX_TRANSPARENT 透明支持
return para;
}
}
protected override void OnPaintBackground(PaintEventArgs e) //不画背景
{
//base.OnPaintBackground(e);
}
protected override OnPaint(PaintEventArgs e)


{
//绘制图形
}
}

读书人网 >C#

热点推荐