|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Data;
using System.Text;
using System.Windows.Forms;
namespace ExControls
{
public partial class ExLabel : Label
{
private Color backColorStart = Color.Orange;
public Color BackColorStart
{
get { return backColorStart; }
set
{
if (!value.IsEmpty)
{
backColorStart = value;
}
else
{
backColorStart = Color.Orange;
}
}
}
private Color backColorEnd = Color.FromArgb(255, 206, 157);
public Color BackColorEnd
{
get { return backColorEnd; }
set
{
if (!value.IsEmpty)
{
backColorEnd = value;
}
else
{
backColorEnd = Color.FromArgb(255, 206, 157);
}
}
}
public ExLabel()
{
InitializeComponent();
SetStyle(ControlStyles.UserPaint, true);
}
private void ExLabel_Paint(object sender, PaintEventArgs e)
{
Rectangle rect = new Rectangle(0, 0, Width, Height);
LinearGradientBrush b = new LinearGradientBrush(rect, BackColorStart, BackColorEnd, 90);
GraphicsPath path = Helper.GetRoundRectPath(rect, 8);
e.Graphics.FillPath(b, path);
ContentAlignment align = this.TextAlign;
StringFormat format = new StringFormat();
switch (align)
{
case ContentAlignment.TopLeft:
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Near;
break;
case ContentAlignment.TopCenter:
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Near;
break;
case ContentAlignment.TopRight:
format.Alignment = StringAlignment.Far;
format.LineAlignment = StringAlignment.Near;
break;
case ContentAlignment.MiddleLeft:
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Center;
break;
case ContentAlignment.MiddleCenter:
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
break;
case ContentAlignment.MiddleRight:
format.Alignment = StringAlignment.Far;
format.LineAlignment = StringAlignment.Center;
break;
case ContentAlignment.BottomLeft:
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Far;
break;
case ContentAlignment.BottomCenter:
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Far;
break;
case ContentAlignment.BottomRight:
format.Alignment = StringAlignment.Far;
format.LineAlignment = StringAlignment.Far;
break;
}
rect.Inflate(-10, 0);
e.Graphics.DrawString(Text, Font, new SolidBrush(ForeColor), rect, format);
}
}
}
|
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.
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
With a heavy C++/MFC background started my way to the DotNet and C# world.
Going from device drivers to standard windows applications development using C++/MFC since 1998, I started the switch to .Net technology in 2004.
Currently I am the Technical Development Manager and Software Architect of Nebras Technology (Medical Software Vendor) and one of its executives owners.