skip to Main Content

Every Form Designer I ever worked with always set the default color of Label to "transparent".
For some reason, Visual Studio set the default color of winform widgets to be predefined "Control" color.
This is NOT good because some container are not of "Control" color (eg Tab Container) so the backround of label doesn’t blend in container’s color.
Is there some way to override default settings and use transparent for label (checkbox…)?

I don’t want to do it at runtime (scanning the tree and settings the color for each matching widget)
I know how to do it for one control in the designer but I want to change the default settings so I don’t have to alter the color for every widget.

RE:
I think I got my explanation.
The designer code was full of

Label.BackColor = System.Drawing.SystemColors.Control;

This is legacy code (> 15 years) so I don’t know why it happens to be like this but you probably don’t want this to happen.
I tried with new label on a new winform, there are no Label.BackColor assignment at all.

This is what confused me, if the property inspector shows that the BackColor is "Control" this can mean two things :

  1. BackColor is not set
    = Background is transparent ; if you move your label to a red panel, it will have a red background (and the BackColor property will now displays as "red" instead of "Control")

  2. BackColor is set to System.Drawing.SystemColors.Control
    = Background is grey ; if you move your label to a red panel, it will have a grey background.

2

Answers


  1. Chosen as BEST ANSWER

    By default the VS2022 has a "standard" behaviour (you see the color of container through the label).
    But, as soon as you choose a color, you're doomed : you cannot easily go from a color assignment to a no color (initial state). Revert back to "Control" color will result in a grey background instead of a transparent.

    To undo this, you could :

    • Change BackColor to transparent (in the web colors), or
    • Go into the designer code and remove all unwanted BackColor = System.Drawing.SystemColors.Control;

  2. In Visual Studio 2022 Winform, the label control’s back color by default is consistent with the background control.

    To set transparent by default, you can create a custom control (not user control) and drag the label -> click properties to set.

    Check the doc: Extend an existing control

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search