C # comparison of transparent forms (1)

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.