关于在picturebox上重绘Label后的Label的mouseclick事件不起作用
为了使Label在Picturebox控件上透明,我重绘了Label达到了透明目的,可是Label的MouseClick事件不知道怎么写了?写了之后点击没反应,而且Label那个小手的形状也没了
请教高手
我在load事件里写了
public Form_BLJ()
{
InitializeComponent();
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.OptimizedDoubleBuffer,true);
label1.Parent = pictureBox1;
label2.Parent = pictureBox1;
label3.Parent = pictureBox1;
label4.Parent = pictureBox1;
label5.Parent = pictureBox1;
label6.Parent = pictureBox1;
label7.Parent = pictureBox1;
label8.Parent = pictureBox1;
label9.Parent = pictureBox1;
label10.Parent = pictureBox1;
label11.Parent = pictureBox1;
label12.Parent = pictureBox1;
label13.Parent = pictureBox1;
label14.Parent = pictureBox1;
label15.Parent = pictureBox1;
label16.Parent = pictureBox1;
label17.Parent = pictureBox1;
label18.Parent = pictureBox1;
label19.Parent = pictureBox1;
label20.Parent = pictureBox1;
label21.Parent = pictureBox1;
label22.Parent = pictureBox1;
label23.Parent = pictureBox1;
}
重写了picturebox的Paint事件
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
PictureBox pb = sender as PictureBox;
foreach (Control C in pb.Controls)
{
if (C is Label)
{
Label L = (Label)C;
L.Visible = false;
e.Graphics.DrawString(L.Text, L.Font, new SolidBrush(L.ForeColor),
new RectangleF(L.Left - pb.Left, L.Top - pb.Top, L.Width, L.Height));
}
}
}
private void label1_MouseClick_1(object sender, MouseEventArgs e)
{
BLJ_YF blj_yf = new BLJ_YF();
blj_yf.Show();
}
也写了label1_MouseClick事件,可是没用
高手帮忙下!!急
------解决方案--------------------
设置透明,只需要这样既可,窗体初始化时,代码写上
C# code
label5.Parent = pictureBox1;
label5.BackColor = Color.Transparent;
------解决方案--------------------
对,1楼说的对,根本没必要重绘,这样click事件就可以直接用了,也不用在重写click事件了