SIGN UP MEMBER LOGIN:    
ARTICLE

Drawing Transparent Controls in GDI+

Posted by Dinesh Beniwal Articles | GDI+ & Graphics August 04, 2010
In this article you will learn how you can draw transparent controls.
Reader Level:

This article has been excerpted from book "Graphics Programming with GDI+"

How can I draw transparent controls? This is one of the commonly asked questions on discussion forums.

Drawing transparent controls involves two steps. First we set a form's style to enable support for transparent controls. We do this by calling the SetStyle method of the form, passing ControlStyles.SupportTransparentBackColor as the first argument, and setting the second argument (which in turn sets the SupportTransparentBackColor bit) to true. Next we set the Control's BackColor property to a transparent color. Either we can use Color.Transparent, or we can create a Color object using an alpha component value less than 255 to provide custom semitransparent.

Listing 15.4 sets the background color of controls to transparent.

LISTING 15.4: Setting the background color of controls to transparent

            /* Code for transparent controls */
            this.SetStyle(
            ControlStyles.SupportTransparentBackColor, true);
            button1.BackColor = Color.Transparent;
            btnBrowse.BackColor = Color.Transparent;
            btnClose.BackColor = Color.Transparent;
            panel1.BackColor = Color.FromArgb(70, 0, 0, 255);


The output of Listing 15.4 looks like Figure 15.2

NOTE

Not all control support transparent color. For example, if you set the BackColor property of text box to Color.Transparent, you will get an exception.

Figure 15.2.jpg

FIGURE 15.2: Designing transparent controls

book.gif

 

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Nevron Gauge for SharePoint
Become a Sponsor