C # several solutions for transparent control background

Source: Internet
Author: User

Few winform programs have been developed. We have recently participated in a small project and met the functional requirements of the control background transparency. Here, we will summarize the requirements for reference by our peers.

0. concept and classification of background transparency

What does background transparency mean? Background transparency. Haha, nonsense. In fact, you have never thought about it. The requirements are different. Are the implementations different from the technical means.

The most basic thing is not to display the background of the control. So, who's the background?

After the background is transparent, the key to the problem is to show who is behind the transparent background. In other words, whether the transparent controls have one or more parents.

1. simple background transparency. parent is a situation.

A. Naturally transparent, label1

Implementation: Set the control background color to the window background color.

B. label2 transparent only when picture is set to parent

Implementation: this. label2.Parent = this. pictureBox1;

C. It is a label, but it only sets the Image attribute. It is equivalent to adding a background Image, and the background is naturally transparent.

This. label3.Image = Image. FromFile ("xfb.jpg ");
D. Common labels cannot be transparent across controls.

 

Summary: for a single background control, background transparency is easy to implement, but for a multi-object background, it is difficult to implement background transparency.

2. The background is transparent to the background of multiple controls.

To be honest, there are few such requirements. More is the third case below.

3. Transparent text, translucent background, and arbitrary background

 

This effect is similar to the lyrics of the desktop. The text background is completely transparent and you can set a background with color and transparency.

In fact, the implementation is very simple. The principle is to use two windows. The text is a transparent window, and the background with color and transparency is a background window, when the application is performed, remove the unnecessary properties of the two windows, such as the border and status bar icon. Finally, set the size and position of the two windows and the hierarchical relationship.

Text window background transparency this. TransparencyKey = this. BackColor; display text directly in the paint event drawstring

Background window with color and transparency: Use backcolor and Opacity directly

Author: binsweet

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.