天天看点

winform去掉laber背景色

public Basic_FM()

        {

            InitializeComponent();

            label1.Parent = pictureBox1;//窗体加载时,需加

        }

 private void pictureBox1_Paint(object sender, PaintEventArgs e)

        {

            ClearBackColor(sender,e);

        }

        public void ClearBackColor(object sender,object e1)

        {

            PictureBox pb = sender as PictureBox;

            PaintEventArgs e = e1 as PaintEventArgs;

            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));

                }

            }

        }

继续阅读