public partial class TransparentPanel : Panel
{
#region Local Variables
private System.Drawing.Color _backColor = Color.Black;
private System.Drawing.Color _borderColor = Color.White;
private int _radius = 8;
private int _opacity = 125;
private System.Drawing.Color _dimmedColor = Color.LightGray;
Rectangle _IconRect = new Rectangle(0, 7, 24, 24);
protected Rectangle iRect = new Rectangle();
#endregion
#region Properties
[DefaultValue(typeof(Color), "Black")]
public new Color BackColor
// Gets or sets the background color of the control.
{
get { return _backColor; }
set { _backColor = value; Invalidate(); }
}
[DefaultValue(typeof(Color), "White"), Category("Appearance"), Description("The border color of the control.")]
/// Gets or sets the outer border color of the control.
public Color BorderColor
{
get { return _borderColor; }
set { _borderColor = value; Invalidate(); }
}
[
Bindable(true),
Category("Appearance"),
DefaultValue(125),
Description("The alpha value used to blend the control's background. Valid values are 0 through 255.")
]
public int Opacity
{
get { return _opacity; }
set { _opacity = value; this.Invalidate(); }
}
[
Bindable(true),
Category("Layout"),
DefaultValue(20),
Description("Radius of rounded borders")
]
public int Radius
{
get { return _radius; }
set { _radius = value; this.Invalidate(); }
}
public override Font Font
{
get { return base.Font; }
set { base.Font = value; this.Invalidate(); }
}
public override Color ForeColor
{
get { return base.ForeColor; }
set { base.ForeColor = value; this.Invalidate(); }
}
#endregion
public TransparentPanel()
{
InitializeComponent();
base.BackColor = Color.Transparent;
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint, true);
SetStyle(ControlStyles.Opaque, false);
Margin = new Padding(1, 1, 1, 1);
Font = new Font("宋体", 10F);
UpdateStyles();
}
protected void DrawBorder(Graphics g)
{
Rectangle rect = this.ClientRectangle;
rect.Width--;
rect.Height--;
using (GraphicsPath bp = GetPath(rect, _radius))
{
using (Pen p = new Pen(_borderColor))
{
g.DrawPath(p, bp);
}
}
}
protected void DrawBackground(Graphics g)
{
Rectangle rect = this.ClientRectangle;
iRect = rect;
rect.X++;
rect.Y++;
rect.Width -= 2;
rect.Height -= 2;
using (GraphicsPath bb = GetPath(rect, _radius))
{
using (Brush br = new SolidBrush(Color.FromArgb(_opacity, _backColor)))
{
g.FillPath(br, bb);
}
}
}
protected GraphicsPath GetPath(Rectangle rc, int r)
// Build the path with the round corners in the rectangle
// r is the radious of rounded corner.
{
int x = rc.X, y = rc.Y, w = rc.Width, h = rc.Height;
r = r << 1;
GraphicsPath path = new GraphicsPath();
if (r > 0)
// If the radious of rounded corner is greater than one side then
// do the side rounded
{
if (r > h) { r = h; }; //Rounded
if (r > w) { r = w; }; //Rounded
path.AddArc(x, y, r, r, 180, 90); //Upper left corner
path.AddArc(x + w - r, y, r, r, 270, 90); //Upper right corner
path.AddArc(x + w - r, y + h - r, r, r, 0, 90); //Lower right corner
path.AddArc(x, y + h - r, r, r, 90, 90); //Lower left corner
path.CloseFigure();
}
else
// If the radious of rounded corner is zero then the path is a rectangle
{
path.AddRectangle(rc);
}
return path;
}
/// <summary>
/// 创建Lable
/// </summary>
/// <param name="dt"></param>
/// <param name="panel1"></param>
/// <param name="eh"></param>
public void CreateLable(DataTable dt, Panel panel1, EventHandler eh,int n)
{
int w = Convert.ToInt32(width)-200*4;
int i = 1;
int x =(int)w/5;
int y = 10;
if (dt != null && dt.Rows.Count > 0)
{
foreach (DataRow row in dt.Rows)
{
string text = "",text1="";
string tag = "";
if (dt.Columns.Count > 2)
{
if (!(row["code"] is DBNull))
{
tag = row["code"].ToString();
}
}
if (!(row["brief"] is DBNull) && !(row["brief"].ToString().Equals("无")) && !(row["brief"].ToString().Equals("")))
{
text = row["brief"].ToString();
}
//else
//{
text1 = row["name"].ToString();
// }
Label b = new Label();