绝对背景透明的Label

来源:互联网 发布:jsp页面js格式化日期 编辑:程序博客网 时间:2024/04/28 19:36

看了不少所谓的透明标签,都是假的。相对父控件透明 并不是真正的透明。这个才是真的,如假包换。   

 class SuLabel : Label

    {

        public SuLabel()

        {

 

        }

 

        protected override void OnPaint(PaintEventArgs e)

        {

            int fontstyleIndex = 0;

            fontstyleIndex = (int)Font.Style;

            BackColor = ForeColor;

            GraphicsPath gp = new GraphicsPath();

            gp.AddString(Text, Font.FontFamily, fontstyleIndex, Font.Size, ClientRectangle, StringFormat.GenericDefault);

            this.Region = new Region(gp);

            gp.Dispose();

        }

    }

 

绝对原创,转载注明出处。。。。。。。

原创粉丝点击