C#winForm中设置在PictureBox上的Label控件透明

设置PictureBox控件上的Label控件透明的步骤:

1) 新建一个PictureBox控件,名称是pbxImage
2) 新建一些Label控件,放在PictureBox上
3) 添加PictureBox的Paint事件
4) 添加如下代码:

//pbxImage is PictureBox control
    private void pbxImage_Paint(object sender, PaintEventArgs e)
    {
      foreach (Control C in this.Controls)
      {
        if (C is Label)
        {
          Label L = (Label)C;
          L.Visible = false;
          e.Graphics.DrawString(L.Text, L.Font, new
SolidBrush(L.ForeColor), L.Left - picBack.Left, L.Top - picBack.Top);
        }
      }
    }
 

你可能感兴趣的:(Windows/.NET)