Reasons for why a WinForms label does not want to be transparent?

后端 未结 11 1830
抹茶落季
抹茶落季 2020-11-28 10:42

Why can\'t I set the BackColor of a Label to Transparent? I have done it before, but now it just don\'t want to...

I created a new UserControl, added a progressbar a

11条回答
  •  盖世英雄少女心
    2020-11-28 11:02

    Most simple solution is following:

    1. Set background color to transparency either in visual editor or in constructor of your form:

      this.label1.BackColor = System.Drawing.Color.Transparent;

    2. Set Parent property of your label to control that you want to be visible behind the text. This can be done in form constructor or in Load method:

      this.label1.Parent = progressBar1;

    Its true that this is not true transparency as in DirectX. The result you see on display is composed only from two layers. You cant sum up more than two layers with this approach (each layer having its own transparency defined by alpha parameter). But its suitable for many practical situations you can encounter in Winforms programming.

提交回复
热议问题