There are several methods for creating transparent forms, each with its own advantages and disadvantages.
Let's take a look at the methods provided by C #.
1: Implemented by setting the TransparencyKey OF THE FORM
For example, the white in the form will become transparent.
this.BackColor =Color.White;
this.TransparencyKey = Color.White;
2: Implemented by setting the Opacity of the form
For example, the form transparency is 50%.
this.Opacity = 0.5;
To better illustrate the problem, let's first look at an instance.
(1) create a winform Application
(2) Add the following code to FormLoad:
This. BackColor = Color. White;
This. TransparencyKey = Color. White;
(3) Add a Label, Text = "TransparencyKey Demo", Backcolor = White (or transparent)
(4) run the command by pressing F5, as shown in
Careless friends have to watch it carefully. Have you found that the text "TransparencyKey Demo" is white-edged? If you drag the window to a video that is being played, you can see it more clearly.
Conclusion: TransparencyKey only supports transparency or opacity, and does not support excessive colors. For example, Transition Colors from transparency to transparency in PNG images will show annoying effects.
Let's take a look at Opacity. We found that it has a good display effect and there is no excessive color problem with TransparencyKey. However, Opacity sets the transparency of the form, which is different from that of a normal window, there is no difference between others. If you cover the transparent forms created through Opacity in the windows of other programs, you can see the following windows, but you cannot directly operate the following forms. In addition, all the controls in the window will have transparent effects and cannot be controlled independently.
Finally, whatever the implementation of TransparencyKey or Opacity is actually an encapsulation of the SetLayeredWindowAttributes () function, but the parameters are different.
In the next article, we will achieve more results, but we will not discuss setlayered;wattributes (), because its two functions have been encapsulated by Microsoft into TransparencyKey and Opacity, you only need to use it.
There are several methods for creating transparent forms, each with its own advantages and disadvantages.
Let's take a look at the methods provided by C #.
1: Implemented by setting the TransparencyKey OF THE FORM
For example, the white in the form will become transparent.
this.BackColor =Color.White;
this.TransparencyKey = Color.White;
2: Implemented by setting the Opacity of the form
For example, the form transparency is 50%.
this.Opacity = 0.5;
To better illustrate the problem, let's first look at an instance.
(1) create a winform Application
(2) Add the following code to FormLoad:
This. BackColor = Color. White;
This. TransparencyKey = Color. White;
(3) Add a Label, Text = "TransparencyKey Demo", Backcolor = White (or transparent)
(4) run the command by pressing F5, as shown in
Careless friends have to watch it carefully. Have you found that the text "TransparencyKey Demo" is white-edged? If you drag the window to a video that is being played, you can see it more clearly.
Conclusion: TransparencyKey only supports transparency or opacity, and does not support excessive colors. For example, Transition Colors from transparency to transparency in PNG images will show annoying effects.
Let's take a look at Opacity. We found that it has a good display effect and there is no excessive color problem with TransparencyKey. However, Opacity sets the transparency of the form, which is different from that of a normal window, there is no difference between others. If you cover the transparent forms created through Opacity in the windows of other programs, you can see the following windows, but you cannot directly operate the following forms. In addition, all the controls in the window will have transparent effects and cannot be controlled independently.
Finally, whatever the implementation of TransparencyKey or Opacity is actually an encapsulation of the SetLayeredWindowAttributes () function, but the parameters are different.
In the next article, we will achieve more results, but we will not discuss setlayered;wattributes (), because its two functions have been encapsulated by Microsoft into TransparencyKey and Opacity, you only need to use it.