On 2 Feb, 14:26, "David Veeneman" <dav...@nospam. comwrote:
I'm creating a UserControl that uses a LinkLabel. For reasons that I won't
bore everyone with, I don't want the LinkLable to show the default hand
cursor when the mouse enters the control. Should be a simple setting on the
LinkLabel.Curso r property, right? Not so simple.
I set the property, but still got the default 'hand' cursor. To debug, I
added the following event handler to my LinkLabel control:
private void linkLabel1_Mous eEnter(object sender, EventArgs e)
{
linkLabel1.Curs or = Cursors.Arrow;
linkLabel1.Text = linkLabel1.Curs or.ToString();
}
When I run the app and enter the LinkLabel, it shows that its Cursor is
still set to Cursors.Default (the hand)! The Cursor property is not getting
set.
Any thoughts as to what's going on here? Thanks in advance
David Veeneman
Foresight Systems
Yep, if you disassemble the Linklabel, you get the code at the end of
this reply, but there's hope :)
This works:
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;
namespace WindowsApplicat ion8
{
public class Class1 : LinkLabel
{
Cursor _newCursor = Cursors.Arrow;
public Class1()
{
}
public Cursor NewOverrideCurs or
{
set
{
_newCursor = value;
this.OverrideCu rsor = value;
}
get
{
return this.OverrideCu rsor;
}
}
protected override void OnMouseMove(Mou seEventArgs e)
{
base.OnMouseMov e (e);
this.OverrideCu rsor = _newCursor;
}
}
}
This is what Reflector told me the linklabel does on a mouse move
event.
protected override void OnMouseMove(Mou seEventArgs e)
{
base.OnMouseMov e(e);
if (base.Enabled)
{
LinkLabel.Link link1 = null;
foreach (LinkLabel.Link link2 in this.links)
{
if ((link2.State & LinkState.Hover ) ==
LinkState.Hover )
{
link1 = link2;
break;
}
}
LinkLabel.Link link3 = this.PointInLin k(e.X, e.Y);
if (link3 != link1)
{
if (link1 != null)
{
link1.State &= ~LinkState.Hove r;
}
if (link3 != null)
{
link3.State |= LinkState.Hover ;
if (link3.Enabled)
{
this.OverrideCu rsor = Cursors.Hand;
}
}
else
{
this.OverrideCu rsor = null;
}
if (this.hoverLink Font != this.linkFont)
{
if (link1 != null)
{
this.Invalidate Link(link1);
}
if (link3 != null)
{
this.Invalidate Link(link3);
}
}
}
}
}