我需要在WinForms上绘制透明PNG图像。我有一个基类:在WinForms上绘制透明图像
public abstract class BaseSkinable : Panel
{
protected BaseSkinable()
{
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
}
protected abstract void OnDraw(Graphics graphics);
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020;
return cp;
}
}
protected override void OnPaintBackground(PaintEventArgs e) { }
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.TextRenderingHint =
System.Drawing.Text.TextRenderingHint.AntiAlias;
e.Graphics.InterpolationMode =
System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
e.Graphics.PixelOffsetMode =
System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
e.Graphics.SmoothingMode =
System.Drawing.Drawing2D.SmoothingMode.HighQuality;
OnDraw(e.Graphics);
}
}
在继承的类:
protected override void OnDraw(Graphics graphics)
{
Image toDraw = SelectImageToDraw();
if (toDraw == null)
{
NoImageDraw(graphics);
return;
}
int width = toDraw.Size.Width;
int height = toDraw.Size.Height;
Rectangle rect = new Rectangle(0, 0, width, height);
graphics.DrawImage(toDraw, rect);
}
我需要重画的图像,如果用户移动鼠标移到控制。但问题是反对绘制覆盖旧图像。就像我们画图层一样。 Winforms可能不清晰图形和我的方法吸引了过去的图片。如何解决它,可能我做错了什么。
所以,你想绘制一个PNG图像到你的面板控制? – 2014-08-28 20:17:42
我有一个透明的PNG图像。我需要制作一个“ImageButton” - 控制鼠标进入,离开和点击时重绘图像的方式。所以问题是这个ImageButton需要透明且没有边框。 – user2598575 2014-08-30 05:54:06
你想在一个按钮上绘制一个透明的图像。按钮后面是“表格”? “形式”也是不透明的? – 2014-08-30 08:38:09