LinkLabel
control has some annoying problems:
- By default, it doesn't use any system colors (namely
Color.Blue
instead ofSystemColors.HotTrack
for theLinkColor
property) - It uses the old, ugly, aliased version of the hand cursor
I have found the following answer here which claims to fix the cursor issue:
using System.Runtime.InteropServices;
namespace System.Windows.Forms {
public class LinkLabelEx : LinkLabel {
private const int IDC_HAND = 32649;
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
private static extern IntPtr LoadCursor(IntPtr hInstance, int lpCursorName);
private static readonly Cursor SystemHandCursor = new Cursor(LoadCursor(IntPtr.Zero, IDC_HAND));
protected override void OnMouseMove(MouseEventArgs e) {
base.OnMouseMove(e);
// If the base class decided to show the ugly hand cursor
if(OverrideCursor == Cursors.Hand) {
// Show the system hand cursor instead
OverrideCursor = SystemHandCursor;
}
}
}
}
However, this solution is not perfect. For example, the old, ugly cursor flashes for one frame before the correct cursor is displayed when hovered over it.
I have also read about the native SysLink
control in ComCtl32.dll which doesn't have there problems, but I can't find a good solution to use it in C#/WinForms. However I would prefer a pure .NET solution anyway.
How can I make the LinkLabel
control better by solving above mentioned problems?