Transparent control over PictureBox

后端 未结 7 1897
遥遥无期
遥遥无期 2020-11-22 14:21

In my C# Form I have a Label that displays a download percentage in the download event:

  this.lblprg.Text = overallpercent.ToString(\"#0\") + \"%\";
         


        
7条回答
  •  孤街浪徒
    2020-11-22 15:00

    You can draw text using TextRenderer which will draw it without background:

    private void pictureBox1_Paint(object sender, PaintEventArgs e)
    {
        TextRenderer.DrawText(e.Graphics, 
                              overallpercent.ToString("#0") + "%", 
                              this.Font, 
                              new Point(10, 10), 
                              Color.Red);
    }
    

    When overallpercent value changes, refresh pictureBox:

    pictureBox1.Refresh();
    

    You can also use Graphics.DrawString but TextRenderer.DrawText (using GDI) is faster than DrawString (GDI+)

    Also look at another answer here and DrawText reference here

提交回复
热议问题