Transparent background color of TextBox and RichTextBox in. NET Environment

Source: Internet
Author: User

 

The text box control does not support transparent background colors.

   In. NET environment, TextBox and RichTextBox do not support transparent background colors. When we set their BackColor to Transparent in the property designer, a warning window is displayed, "invalid attribute values: the control does not support Transparent background colors ".

   There are many solutions for one search on the Internet:

   (1) Add the following code to the Code: textBox1.BackColor = System. Drawing. Color. Transparent;

   (2) inherit the TextBox to perform simple settings of the style ControlStyles. SupportsTransparentBackCOlor.

Public class MyTextBox: TextBox
{
   Public MyTextBox ()
   {
       This. setstyle (controlstyles. supportstransparentbackcOlor, true );
   }
}

   (3) If you do not want to make controls on your own, you can provide the following idea:

1. Create a form without borders. Set trancsparencykey to the same as textbox;
2. Put a textbox on the form, and set the dock attribute to fill;
3. Place a label on the main form and set it to transparent;
4. When you click label, show your own form and hide the label;
5. When the focus leaves Textbox, copy the content of the textbox to the label. Close the frameless window and display the label;
6. Think about other details, such as the appearance of the mouse and the shift of the focus with the tab key.

 

   Analysis:

   Method (1): not feasible. Although compilation is successful, it may encounter runtime errors. Winform does not support the transparent background color of the control.

   Method (2): not feasible. Although supportstransparentbackcAfter olor is true, the background color of the text box can be made

             If it is set to transparent but does not reach the transparent effect, the background color is still not transparent.

   Method (3): feasible but complex. This method is not the best solution. It can only be used if there are no other solutions.

 

Summary

   Because the. NET Framework does not support the background color of the text box control, some lower-level Win32 functions must be used. Below isThe Code projectSome of the best implementation methods found above are basically solved by using the underlying Win32 function. The specific code analysis is left for later time and can be used directly and conveniently now.

   This article specifically describes how to make the text box background transparent:How to make a textbox/RichTextBox transparent

 

Open-source controls

Alphablendtextbox-a transparent/translucent textbox for. net

 

Alpha blended (transparent capable) textbox and RichTextBox

 

 

In addition:

In C #, the button is transparent and borderless, but you can click the transparent part to implement its functions ~~~ · Thank you

Best Answer
A: Change the FlatStyle attribute of the button to Flat. Add a button1.BackColor = Color. Transparent; (or add this. button1.FlatStyle = FlatStyle. Flat; button1.BackColor = Color. Transparent;
Dedtfo
| Level 6
If it is Web, use ImageButton; if it is WinForm, use pictureBox and add the onclick event. I have tried it. If you use a button, you can see a little bit without borders. Of course, if you use images, you can use transparent images. You can use PS to export images. I have tried it. Hope to help you a little bit.

 

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.