设置lable在图片上透明显示
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace usercontrol_touming
{
public partial class UserControl1 : UserControl
{
public UserControl1()
{
InitializeComponent();
this.BackColor = Color.Transparent;
//panel1.Controls.Add(pictureBox1);
}
public class TransparentLabel : System.Windows.Forms.PictureBox
{
//Fields
private Point _Location = new Point(0, 0);
//Properties
public Point TextLocation
{
get
{
return this._Location;
}
set
{
this._Location = value;
}
}
[Browsable(true)]
new public string Text
{
get { return base.Text; }
set { base.Text = value; }
}
[Browsable(true)]
new public Font Font
{
get { return base.Font; }
set { base.Font = value; }
}
//
public TransparentLabel()
{
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
SizeF m_size = e.Graphics.MeasureString(this.Text, this.Font);
e.Graphics.DrawString(this.Text, this.Font, Brushes.Black, new RectangleF(this._Location, m_size));
}
}
private void UserControl1_Load(object sender, EventArgs e)
{
label1.Text = "2013-08-05"; }
}
}
浙公网安备 33010602011771号