Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
97 views

A Simple Implementation of Outlook Style Groupbox Control With Transparency Support

This document describes an implementation of an Outlook-style group box control for .NET with transparency support. The control allows customizing the group box border color, background image or icon, and enables a transparent background. The source code provided implements the control using GDI+ and doubles buffering to draw the text, line, and image or icon on the transparent background.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
97 views

A Simple Implementation of Outlook Style Groupbox Control With Transparency Support

This document describes an implementation of an Outlook-style group box control for .NET with transparency support. The control allows customizing the group box border color, background image or icon, and enables a transparent background. The source code provided implements the control using GDI+ and doubles buffering to draw the text, line, and image or icon on the transparent background.

Uploaded by

BaneeIshaqueK
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

{} DailyCoding.com Tips and tricks C#, ASP.

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();
}
}

Source Code (Download here)


usingSystem;
usingSystem.Collections;
usingSystem.ComponentModel;
usingSystem.Drawing;
usingSystem.Data;
usingSystem.Windows.Forms;
namespaceOwf.Controls
{
publicpartialclassOutlookGroupBox:Panel
{
[Browsable(true)]
publicnewstringText
{
get{returnbase.Text;}
set
{
base.Text=value;
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?

Tags: .NET, Outlook, Groupbox, GDI+, Office contols, GDI+ controls


Facing issue while using? contact sa@openwinforms.com

Share this page


Contact Site Admin: sa@openwinforms.com

You might also like