#region Using directives
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.ComponentModel;
#endregion
namespace SmartInstitute.Client.Controls
{
public class SectionHeader : Panel
{
// const values
private class Consts
{
public static Color ColorLow = Color.FromArgb(175, 200, 245);
public static Color ColorHigh = Color.FromArgb(205, 225, 250);
public static Pen PenTop = new Pen(Color.FromArgb(180, 210, 245));
public static Pen PenBottom = new Pen(SystemColors.InactiveCaption);
public const int PosOffset = 4;
}
// internal members
private LinearGradientBrush m_brush;
private string m_text = string.Empty;
[DefaultValueAttribute("")]
[CategoryAttribute("Appearance")]
[DescriptionAttribute("Header text.")]
public string HeaderText
{
get
{
return m_text;
}
set
{
m_text = value;
Invalidate();
}
}
public SectionHeader()
{
SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true);
}
// the caption needs to be drawn
protected override void OnPaint(PaintEventArgs e)
{
Draw(e.Graphics);
base.OnPaint(e);
}
// draw the caption
private void Draw(Graphics g)
{
if (Width != 0 && Height != 0)
{
if( null == m_brush )
this.CreateFillBrush();
// background
g.FillRectangle(m_brush, DisplayRectangle);
// header text
g.DrawString(m_text, Font, SystemBrushes.ControlText, Consts.PosOffset, ((Height - Font.Height) / 2));
// top and bottom lines
g.DrawLine(Consts.PenTop, 0, 0, Width - 1, 0);
g.DrawLine(Consts.PenBottom, 0, Height - 1, Width - 1, Height - 1);
}
}
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
this.CreateFillBrush();
}
private void CreateFillBrush()
{
if (Width > 0 && Height > 0)
{
// create the gradient brush when the control is resized
m_brush = new LinearGradientBrush(DisplayRectangle, Consts.ColorHigh, Consts.ColorLow, LinearGradientMode.Vertical);
}
}
}
}