C # transparent background Panel, transparent image, and PitureBox transparent Effect

Source: Internet
Author: User
Tags transparent image

C # transparent background Panel, transparent image, and PitureBox transparent Effect

 

1. Custom transparent background Panel control: Add TransparentPanel. cs class to the Project

 

using System.Windows.Forms;using System.Drawing;
Public class TransparentPanel: Control {public TransparentPanel () {} protected override void OnPaintBackground (PaintEventArgs e) {// do not draw the background} protected override CreateParams {get {CreateParams cp = base. createParams; cp. exStyle | = 0x00000020; // WS_EX_TRANSPARENT return cp ;}} protected override void OnPaint (System. windows. forms. paintEventArgs e) {// draws the background image of the panel if (BackgroundImag E! = Null) e. graphics. drawImage (this. backgroundImage, new Point (0, 0);} // Add the custom property value num1 for the control // private int num1 = 1; // [Bindable (true ), category ("custom attribute bar"), DefaultValue (1), Description ("here is the Description of the custom attribute Attr1! ")] // Public int Attr1 // {// get {return num1 ;}// set {this. Invalidate ();}//}}

 

 


2. After F5 is compiled and run once, you can find the control TransparentPanel In the toolbar.

Then add the control to the Form and set its Image attribute to the *. png Image with transparency information to see the transparency effect.

 

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.