日期:2014-05-17 浏览次数:20830 次
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Drawing;
namespace WindowsFormsApplication1
{
class SuperLinkLabel : LinkLabel
{
public bool IgnoreCase { get; set; }
private string keyWord = "";
public string Keyword
{
get { return keyWord; }
set { keyWord = value; this.Invalidate(); }
}
public Color KeywordColor { get; set; }
public SuperLinkLabel()
{
Keyword = "";
KeywordColor = Color.Red;
}
protected override void OnPaint(PaintEventArgs e)
{
e.Graphics.FillRectangle(new SolidBrush(SystemColors.Control), e.ClipRectangle);
StringFormat stringFormat = new StringFormat();
stringFormat.SetMeasurableCharacterRanges(GetRanges());
stringFormat.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
Region[] regions = e.Graphics.MeasureCharacterRanges(Text, Font, new RectangleF(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width + 200, e.ClipRectangle.Height), stringFormat);