A Simple Implementation of Outlook Style Groupbox Control With Transparency Support
A Simple Implementation of Outlook Style Groupbox Control With Transparency Support
NET
Subscribe in a reader
Home
Controls
Articles
Asimpleimplementationofoutlookstylegroupboxcontrolwith
transparencysupport
Download Source Code outlook_style_group_box.zip
Post comments
Need help?
Introduction
This article explains very simple implementation of a outlook style groupbox. This control also
supports transparent background.
Features
Following are the customizable things in this control
Groupbox border color
Back image or icon
Transparent background
This is achieved by using follwing code.
bool_isTransparent=false;
[Browsable(true),Category("Appearance")]
publicboolIsTransparent
{
get{return_isTransparent;}
set
{
_isTransparent=value;
if(_isTransparent==true)
{
this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);
this.BackColor=Color.Transparent;
}
Invalidate();
}
}
Sponsors
Contact
privateColor_lineColor=SystemColors.Highlight;
[Browsable(true),Category("Appearance")]
publicColorLineColor
{
get{return_lineColor;}
set
{
_lineColor=value;
Invalidate();
}
}
privateImage_image;
[Browsable(true),Category("Appearance")]
publicImageImage
{
get{return_image;}
set
{
if(value!=null)
{
_image=value;
_icon=null;
Invalidate();
}
}
}
privateIcon_icon;
[Browsable(true),Category("Appearance")]
publicIconIcon
{
get{return_icon;}
set
{
if(value!=null)
{
_icon=value;
_image=null;
Invalidate();
}
}
}
bool_isTransparent=false;
[Browsable(true),Category("Appearance")]
publicboolIsTransparent
{
get{return_isTransparent;}
set
{
_isTransparent=value;
if(_isTransparent==true)
{
this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);
this.BackColor=Color.Transparent;
}
Invalidate();
}
}
publicOutlookGroupBox()
{
InitializeComponent();
SetStyles();
}
publicOutlookGroupBox(IContainercontainer)
{
container.Add(this);
InitializeComponent();
SetStyles();
}
voidSetStyles()
{
this.SetStyle(ControlStyles.DoubleBuffer,true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint,true);
this.SetStyle(ControlStyles.ResizeRedraw,true);
this.SetStyle(ControlStyles.UserPaint,true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor,true);
}
privatevoidOutlookGroupBox_Paint(objectsender,PaintEventArgse)
{
Fontfont=this.Font;
SizeFsize=e.Graphics.MeasureString(this.Text,font);
e.Graphics.DrawString(this.Text,font,newSolidBrush(this.ForeColor),1,1);
e.Graphics.DrawLine(newPen(_lineColor),size.Width+3,(size.Height+3)/2,
this.Width5,(size.Height+3)/2);
if(_image!=null)
{
e.Graphics.DrawImageUnscaled(_image,this.Padding.Left,this.Padding.Top);
}
elseif(_icon!=null)
{
e.Graphics.DrawIconUnstretched(_icon,newRectangle(this.Padding.Left,
this.Padding.Top,_icon.Width,_icon.Height));
}
}
}
}
Post comments
Need help?