溫馨提示×

C# groupbox 如何實現透明背景

c#
小樊
319
2024-07-13 23:06:30
欄目: 編程語言

要實現C#中GroupBox的透明背景,可以通過以下步驟實現:

  1. 創建一個自定義的GroupBox控件,繼承自GroupBox控件:
public class TransparentGroupBox : GroupBox
{
    public TransparentGroupBox()
    {
        SetStyle(ControlStyles.SupportsTransparentBackColor, true);
        BackColor = Color.Transparent;
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        base.OnPaint(e);
        using (SolidBrush brush = new SolidBrush(this.ForeColor))
        {
            e.Graphics.DrawString(this.Text, this.Font, brush, new Point(10, 1));
        }
    }
}
  1. 在窗體中使用自定義的TransparentGroupBox控件,設置其背景顏色為透明:
TransparentGroupBox transparentGroupBox1 = new TransparentGroupBox();
transparentGroupBox1.Text = "Transparent GroupBox";
transparentGroupBox1.Location = new Point(50, 50);
transparentGroupBox1.Size = new Size(200, 100);
this.Controls.Add(transparentGroupBox1);

通過以上步驟,就可以實現C#中GroupBox控件的透明背景效果。

0
亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女