bright, fresh software
Downloads  |  Buy

Wyatt Says...

November 16th, 2008

If you’ve done any Windows Forms designing then you’ve undoubtedly used the LinkLabel control. You’ve also likely noticed its hideous look:

The ugliness of the LinkLabel that ships with Windows Forms is four fold.

  1. The repulsive navy blue color reminds me of Netscape Navigator (anyone else remember the graceful “Illegal Operation” crashes?).
  2. There’s no hover effect. OK, I lied. There’s a hover effect but you have to code it. And if you do code it, you better put on your epilepsy goggles – it’s gonna flicker.
  3. The non-standard hand cursor is missing the shadow and the gradient.
  4. The LinkLabel font is oddly rendered:

The Windows.Forms LinkLabel looks as though the text was drawn to the screen once, then drawn again without erasing the first copy. This gives the LinkLabel a jagged, “blocky” look.

LinkLabel2 – How I fixed it

It was a simple bit of code. I used ‘TextRenderer.DrawText(…)’ to do the actual drawing. The hand cursor was simply a matter of intercepting the WM_SETCURSOR message to my LinkLabel2 control:

[DllImport("user32.dll")]
public static extern int LoadCursor(int hInstance, int lpCursorName);

[DllImport("user32.dll")]
public static extern int SetCursor(int hCursor);

protected override void WndProc(ref Message m)
{
    //WM_SETCURSOR == 32
    if (m.Msg == 32)
    {
        //IDC_HAND == 32649
        SetCursor(LoadCursor(0, 32649));

        //the message has been handled
        m.Result = IntPtr.Zero;
        return;
    }

    base.WndProc(ref m);
}

But what about SysLink?

SysLink is a link control added to “ComCtl32.dll” in Windows XP. So, why not use SysLink? Because SysLink doesn’t exist in Windows 2000/98.

Maybe in 3 years, when Windows 2000 is dead, a simple SysLink wrapper for C# can be written.

Get it

It works with all the .NET 2.0 + languages (C#, VB.NET, etc.).

Also while you’re at it download wyUpdate, or any of my other open source projects.

Go to the LinkLabel2 site for further updates.

Subscribe to Wyatt Says...

Subscribe to the 'Wyatt Says...' RSS Feed and keep up to date on on my articles on updaters, usability, open source C# components, and software licensing.


Comments

Leave a Reply