03-08-2005 09:19 AM
03-08-2005 01:19 PM
using NationalInstruments.UI;
using System.Drawing;
using System;
public class CustomCursor : XYCursor
{
private const string DefaultLabel = "blah, blah";
private string _label;
public CustomCursor()
{
_label = DefaultLabel;
}
public string Label
{
get
{
return _label;
}
set
{
if (value == null)
throw new ArgumentNullException("value");
if (_label != value)
{
_label = value;
//causes cursor to redraw.
Invalidate();
}
}
}
protected override void OnAfterDraw(AfterDrawXYCursorEventArgs e)
{
base.OnAfterDraw(e);
SizeF labelSize = e.Graphics.MeasureString(_label, LabelFont);
PointF referencePoint = new PointF(e.PointBounds.X + (e.PointBounds.Width / 2), e.PointBounds.Y + (e.PointBounds.Height / 2));
AlignmentArgs aligmentArgs = new AlignmentArgs(e.Bounds, referencePoint, labelSize, (float)PointSize.Width / 2, (float)PointSize.Height / 2);
PointF labelPoint = LabelAlignment.AdjustPosition(this, aligmentArgs);
using (Brush backgroundBrush = new SolidBrush(LabelBackColor))
using (Brush foregroundBrush = new SolidBrush(LabelForeColor))
{
e.Graphics.FillRectangle(backgroundBrush, new RectangleF(labelPoint, labelSize));
e.Graphics.DrawString(_label, LabelFont, foregroundBrush, labelPoint);
}
}
}
03-09-2005 05:44 AM
03-09-2005 09:51 AM