Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » C# » Windows Forms » Downloads
 
Add your own
alternative version

Non-transparent controls on a semi-transparent window

, 6 Jul 2006
The article describes the use and the principle of operation of semi-transparent controls with non-transparent child controls.
transparent_controls_demo.zip
TestSkinControl
App.ico
bin
Debug
KBSoft.Components.dll
TestSkinControl.exe
TestSkinControl.exe.manifest
TestSkinControl.csproj.user
transparent_controls_src.zip
Components
bin
components
common
components.csproj.user
skincomponents
///////////////////////////////////////////////////////////////////////////////
//
//  File:           labelitem.cs
//
//  Facility:       The unit contains the LabelItem class.
//
//  Abstract:       The class presenting the text field that is arranged 
//                  on the SkinTooltip control.
//
//  Environment:    VC 7.1
//
//  Author:         KB_Soft Group Ltd.
//
///////////////////////////////////////////////////////////////////////////////

using System;
using System.Drawing;
using System.ComponentModel;
using System.Drawing.Drawing2D;

namespace KBSoft.Components
{
    /// <summary>
    /// The class presenting the label that may be arranged only on     
    /// SkinTooltip with the help of the Add label command of the designer.
    /// </summary>
    [ ToolboxItem(false) ]
    public class LabelItem : System.ComponentModel.Component
    {
        #region Fields

        /// <summary>
        /// the label text
        /// </summary>
        string labelText = "";

        /// <summary>
        /// the label font.
        /// </summary>
        Font textFont = null; 

        /// <summary>
        /// the label position.
        /// </summary>
        Rectangle labelRect = Rectangle.Empty;

        /// <summary>
        /// the brush that draws the text.
        /// </summary>
        Brush textBrush = null;

        /// <summary>
        /// the parent control.
        /// </summary>
        SkinTooltip parent = null;
        /// <summary>
        /// Indicates whether a control is selected.
        /// </summary>
        private bool isSelected = false;

        /// <summary>
        /// The pen to draw the bound in the design-time.
        /// </summary>
        private Pen borderPen = null;

        /// <summary>
        /// Indicates whether we see the given label.
        /// </summary>
        private bool visible = true;


        #endregion

        #region Constructors

        /// <summary>
        /// The class constructor.
        /// </summary>
        public LabelItem()
        {
            textFont = new Font( "arial", 10 );
            textBrush = Brushes.Green;
            borderPen = new Pen( Color.FromArgb(255,0,0) );
            borderPen.DashStyle = DashStyle.Dash;
        }

        #endregion

        #region Properties

        /// <summary>
        /// The property sets the text that is displayed in the label.
        /// </summary>
        public string LabelText
        {
            get{ return this.labelText;  }
            set
            { 
                this.labelText = value;
 
                if( parent != null )
                {
                    //parent.Invalidate();
                    //parent.Update();
                }
            }
        }

        /// <summary>
        /// The property sets the font of the text that will be displayed.
        /// </summary>
        public Font TextFont
        {
            get{ return this.textFont;  }
            set
            { 
                this.textFont = value; 

                if(parent != null)
                {
                    parent.Invalidate();
                    parent.Update();
                }
            }
        }

        /// <summary>
        /// The property sets the label position.
        /// </summary>
        public Rectangle LabelRect
        {
            get{ return this.labelRect;  }
            set
            { 
                this.labelRect = value; 
                if(parent != null)
                {
                    parent.Invalidate();
                    parent.Update();
                }
            }
        }

        /// <summary>
        /// The property sets the text color.
        /// </summary>
        public Color TextColor
        {
            get{ return ( (SolidBrush)this.textBrush ).Color;  }
            set
            { 
                this.textBrush = new SolidBrush(value); 

                if( parent != null )
                {
                    parent.Invalidate();
                    parent.Update();
                }
            }
        }

        /// <summary>
        /// The property is needed to support the design-time. 
        /// Sets the parent control.
        /// </summary>
        [Browsable (false)]
        public SkinTooltip Parent
        {
            get{  return this.parent; }
            set{ this.parent = value; }
        }

        /// <summary>
        /// The property defines whether the label is selecetd in the design-time.
        /// </summary>
        [Browsable (false)]
        public bool Selected
        {
            get{ return this.isSelected;  }
            set
            { 
                this.isSelected = value; 
 
                if( parent != null )
                {
                parent.Invalidate(); 
                parent.Update();
                    }
                }
        }

        /// <summary>
        /// The property defines whether we see the given label.
        /// </summary>
        public bool Visible
        {
            get{ return this.visible;  }
            set{ this.visible = value; }
        }

        #endregion

        #region Methods

        /// <summary>
        /// The method draws the label.
        /// </summary>
        /// <param name="g">The context where the control will be drawn.</param>
        /// <param name="DesignMode">The parameter indicates whether the label is in the design-time.</param>
        public void DrawLabel( Graphics g, bool DesignMode )
        {
            StringFormat sf = new StringFormat();
            sf.LineAlignment = StringAlignment.Near;
            sf.Alignment = StringAlignment.Near;

            g.DrawString( labelText, textFont, textBrush, labelRect, sf );
            if( DesignMode )
            {
                if( this.isSelected )
                {
                    borderPen.DashStyle = DashStyle.Dot;
                    borderPen.Width = 2;
                    
                }
                else
                {
                    borderPen.Width = 2;
                    borderPen.DashStyle = DashStyle.Solid;

                }

                g.DrawRectangle( borderPen,this.LabelRect );
            }
            

        }
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Alexandr Golovanov
Web Developer
Russian Federation Russian Federation
Alexandr Golovanov is a .NET developer at KB_Soft Group, an offshore software development company located in Russia, Novosibirsk. Here he has worked
on various .NET projects.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150224.1 | Last Updated 6 Jul 2006
Article Copyright 2006 by Alexandr Golovanov
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid