BorderLabel.cs
上传用户:nnpulika
上传日期:2013-02-15
资源大小:597k
文件大小:2k
- using System;
- using System.Drawing;
- using System.Windows.Forms;
- using System.Drawing.Drawing2D;
- using System.ComponentModel;
- namespace UtilityLibrary.WinControls
- {
- /// <summary>
- /// Summary description for BorderLabel.
- /// </summary>
- [ToolboxItem(false)]
- public class BorderLabel : Label
- {
- #region Class Variables
- Pen pen = null;
- Pen hoverPen = null;
- bool highlight = false;
- int width = -1;
- int gap = 0;
- #endregion
-
- #region Constructors
- public BorderLabel(Color BorderColor, Color HoverColor): this(BorderColor, HoverColor, 1)
- {
- }
-
- public BorderLabel(Color BorderColor, Color HoverColor, int Width)
- {
- highlight = true;
- width = Width;
- pen = new Pen(BorderColor, Width);
- hoverPen = new Pen(HoverColor, Width);
- pen.Alignment = PenAlignment.Inset;
- hoverPen.Alignment = PenAlignment.Inset;
- if ( Width == 1 )
- gap = 1;
- }
- public BorderLabel(Color BorderColor): this(BorderColor, 1)
- {
- }
- public BorderLabel(Color BorderColor, int Width)
- {
- highlight = false;
- width = Width;
- pen = new Pen(BorderColor, Width);
- pen.Alignment = PenAlignment.Inset;
- if ( Width == 1 )
- gap = 1;
- }
- #endregion
- #region
- override protected void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- // Draw a border around the label
- Rectangle rc = Bounds;
- e.Graphics.DrawRectangle(pen, 0, 0, rc.Width-gap, rc.Height-gap);
- }
- override protected void OnMouseMove(MouseEventArgs e)
- {
- base.OnMouseMove(e);
- if ( highlight )
- {
- Graphics g = CreateGraphics();
- Rectangle rc = Bounds;
- g.DrawRectangle(hoverPen, 0, 0, rc.Width-gap, rc.Height-gap);
- g.Dispose();
- }
- }
- override protected void OnMouseLeave(EventArgs e)
- {
- base.OnMouseLeave(e);
- if ( highlight )
- {
- Graphics g = CreateGraphics();
- Rectangle rc = Bounds;
- g.DrawRectangle(pen, 0, 0, rc.Width-gap, rc.Height-gap);
- g.Dispose();
- }
- }
-
- #endregion
- }
-
- }