看错了. 重载控件. using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Linq; using System.Text; using System.Windows.Forms; using System.Drawing;namespace Linq { public partial class MyPanel : Panel { public MyPanel() { SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent; InitializeComponent(); } public MyPanel(IContainer container) { container.Add(this); InitializeComponent(); }
如何使Windows Form上的Panel或者Label控件半透明?(How to make a Panel or Label semi-transparent on a Windows Form? ) 通过设置控件背景色的alpha值 panel1.BackColor = Color.FromArgb(65, 204, 212, 230); 注意:在设计时手动输入这些值,不要用颜色选取
重载控件.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;namespace Linq
{
public partial class MyPanel : Panel
{
public MyPanel()
{
SetStyle(ControlStyles.UserPaint, true);
SetStyle(ControlStyles.SupportsTransparentBackColor, true); this.BackColor = Color.Transparent;
InitializeComponent();
} public MyPanel(IContainer container)
{
container.Add(this); InitializeComponent();
}
}
}
private void pnlNavigate_Paint(object sender, PaintEventArgs e)
{
base.OnPaint(e); // 背景设成透明还是必要的,控件上的图形在后面画
pnlNavigate.BackColor = Color.Transparent;
Rectangle rect = e.ClipRectangle;
e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; // 画控件上的图形,这里以一个线性渐变的图为例。
// 注意此处,128是透明度,范围是0-255。
// 如果控件上放一个不透明的图片,则须先将其处理为透明的。
LinearGradientBrush baseBackground = new LinearGradientBrush(rect,
Color.FromArgb(128, 191, 191, 191),
Color.FromArgb(128, 255, 255, 255),
270, false); e.Graphics.FillRectangle(baseBackground, rect);
e.Graphics.Flush();
}不过效果,我试了试,一般.
panel1.BackColor = Color.FromArgb(65, 204, 212, 230);
注意:在设计时手动输入这些值,不要用颜色选取
{
SetStyle(ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor, true); this.panel1.BackColor = Color .Transparent ;
}
1.用一个form来替代这个panel
2.把panel位置的webbrowser的图像传给panel去画相对来说用form来覆盖实现会比较简单,只需要在webbroser位置变动的时候把控件的坐标传给这个form就好了;
用panel画底图也需要把坐标传过来,但是不好实现半透明效果,全透明还好点。
Form _form = new Form();
_form.FormBorderStyle = FormBorderStyle.None;
_form.Size = this.Size;
_form.StartPosition = FormStartPosition.Manual;
_form.Location = this.Location;
_form.Opacity = 0.5;
_form.BackColor = Color.Black;
_form.ShowIcon = false;
_form.ShowInTaskbar = false;
_form.Show();
Form _FormDialog = new Form();
_FormDialog.ShowDialog();
_form.Close();可以COPY 这段代码试试看,看是不是你想要的