Solving Transparency in Image Editing Tool
To create a transparent background for a rectangle in a Winforms application using .NET 3.5, the following steps can be taken:
SetStyle(ControlStyles.SupportsTransparentBackColor, true);
pnlSelectArea.BackColor = Color.Transparent;
public class TranspCtrl : Control { // Opacity property public int Opacity { get; set; } protected override CreateParams CreateParams { get { // Enable transparency CreateParams cp = base.CreateParams; cp.ExStyle = cp.ExStyle | 0x20; return cp; } } }
protected override void OnPaint(PaintEventArgs e) { // Custom painting logic with transparency }
TranspCtrl myRectangle = new TranspCtrl(); myRectangle.Opacity = 50; // Set the desired opacity level
The above is the detailed content of How Can I Achieve Transparency for a Rectangle in a WinForms Application Using .NET 3.5?. For more information, please follow other related articles on the PHP Chinese website!