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.Cursor 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_MouseEnter(object sender, EventArgs e)
{
linkLabel1.Cursor = Cursors.Arrow;
linkLabel1.Text = linkLabel1.Cursor.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.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication8
{
public class Class1 : LinkLabel
{
Cursor _newCursor = Cursors.Arrow;
public Class1()
{
}
public Cursor NewOverrideCursor
{
set
{
_newCursor = value;
this.OverrideCursor = value;
}
get
{
return this.OverrideCursor;
}
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove (e);
this.OverrideCursor = _newCursor;
}
}
}
This is what Reflector told me the linklabel does on a mouse move
event.
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(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.PointInLink(e.X, e.Y);
if (link3 != link1)
{
if (link1 != null)
{
link1.State &= ~LinkState.Hover;
}
if (link3 != null)
{
link3.State |= LinkState.Hover;
if (link3.Enabled)
{
this.OverrideCursor = Cursors.Hand;
}
}
else
{
this.OverrideCursor = null;
}
if (this.hoverLinkFont != this.linkFont)
{
if (link1 != null)
{
this.InvalidateLink(link1);
}
if (link3 != null)
{
this.InvalidateLink(link3);
}
}
}
}
}