vs2005 c# 如何设置picturebox绝对透明 请问,如何设置picturebox绝对不明, ((Bitmap)pictureBox2.Image).MakeTransparent();这个方法好像只是这只背景与底图相通,如果上面再有两个PICTUREBOx叠加的话,就不透明了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 picturebox2.hidepicturebox2.drawtobitmap(me.backgroundimage,picturebox2.bounds) PictureBox支持PNG格式的透明通道,把图像设置成PNG格式,然后自己编辑PNG图像的透明区域。 picturebox的透明是相对与他的父控件,而不是所看到的直接透明过去 可以考虑,动态的获取picturebox所对应的区域的图片作为它的背景图片。 你说的这个方法,我试过,这杨picturebox的背景是父窗体的,但是如果我在该picturebox和其父窗体之间再加上一个picturebox2的话,最上层的picturebox对中间层的picturebox2是不透明的,还是显示的是父窗体的背景,因此picturebox怎么实现绝对透明,无论它的底层有什么样的图片都可以透明的看过去 多个PictureBox并不是一个很好的设计,你为什么不自己贴图绘制呢。即便你这么拼凑实现了,也是很慢的。 自己写控件吧public class TransparentControl : Control{ private readonly Timer refresher; private Image _image; public TransparentControl() { SetStyle(ControlStyles.SupportsTransparentBackColor, true); BackColor = Color.Transparent; refresher = new Timer(); refresher.Tick += TimerOnTick; refresher.Interval = 50; refresher.Enabled = true; refresher.Start(); } protected override CreateParams CreateParams { get { CreateParams cp = base.CreateParams; cp.ExStyle |= 0x20; return cp; } } protected override void OnMove(EventArgs e) { RecreateHandle(); } protected override void OnPaint(PaintEventArgs e) { if (_image != null) { e.Graphics.DrawImage(_image, (Width / 2) - (_image.Width / 2), (Height / 2) - (_image.Height / 2)); } } protected override void OnPaintBackground(PaintEventArgs e) { //Do not paint background } //Hack public void Redraw() { RecreateHandle(); } private void TimerOnTick(object source, EventArgs e) { RecreateHandle(); refresher.Stop(); } public Image Image { get { return _image; } set { _image = value; RecreateHandle(); } }} 我写过一个帖子,你可以参考里面的的 OpacityImage 控件,可能还有些问题,自己修改下。项目是VS2010的,不过是用.net2.0的FrameWorkhttp://topic.csdn.net/u/20120919/23/6628ebac-31fb-453c-99d9-a3936817e667.html 窗体的一部分是图片,如何使其全屏化,并隐藏菜单工具栏等。 C#如何判断一个时间比另一个时间小,或大 C# 将按钮控件封装为用户控件 winfrom中checkedlistbox的绑定问题 新手问题 怎样声明动态数组对象 哪位高人有GridControl 控件,我家底都亮出来了 新手探路,望高手指点迷津!!!! 如何用C#自制MP3解码器+播放器? 报表by c# word文档的比较功能,比较的结果为整段显示,为什么啊? winform 修改配置文件后重新读取。
picturebox2.drawtobitmap(me.backgroundimage,picturebox2.bounds)
可以考虑,动态的获取picturebox所对应的区域的图片作为它的背景图片。
你说的这个方法,我试过,这杨picturebox的背景是父窗体的,但是如果我在该picturebox和其父窗体之间再加上一个picturebox2的话,最上层的picturebox对中间层的picturebox2是不透明的,还是显示的是父窗体的背景,因此picturebox怎么实现绝对透明,无论它的底层有什么样的图片都可以透明的看过去
{
private readonly Timer refresher;
private Image _image; public TransparentControl()
{
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
BackColor = Color.Transparent;
refresher = new Timer();
refresher.Tick += TimerOnTick;
refresher.Interval = 50;
refresher.Enabled = true;
refresher.Start();
} protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x20;
return cp;
}
} protected override void OnMove(EventArgs e)
{
RecreateHandle();
}
protected override void OnPaint(PaintEventArgs e)
{
if (_image != null)
{
e.Graphics.DrawImage(_image, (Width / 2) - (_image.Width / 2), (Height / 2) - (_image.Height / 2));
}
} protected override void OnPaintBackground(PaintEventArgs e)
{
//Do not paint background
} //Hack
public void Redraw()
{
RecreateHandle();
} private void TimerOnTick(object source, EventArgs e)
{
RecreateHandle();
refresher.Stop();
} public Image Image
{
get
{
return _image;
}
set
{
_image = value;
RecreateHandle();
}
}
}