By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,117 Members | 2,178 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,117 IT Pros & Developers. It's quick & easy.

Setting LinkLabel cursor?

P: n/a
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
Feb 2 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
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);
}
}
}
}
}

Feb 2 '07 #2

P: n/a
argh DevX beat me too it ;) but you could simplify it one step less. This
is essentially what dev did except i have assumed you will always want your
link to have an arrow so no need for the property to override the cursor.
Then you can just drop this one all over your forms and never need to touch
its properties for the cursor.

Great spot tho, i never realised that the cursor property of linklabel seems
to do f**k all.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace littleApp
{
public partial class customLink : LinkLabel
{
public customLink()
{
InitializeComponent();
this.OverrideCursor = Cursors.Arrow;
}

protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
this.OverrideCursor = Cursors.Arrow;
}

}
}
"David Veeneman" <da****@nospam.comwrote in message
news:OK**************@TK2MSFTNGP04.phx.gbl...
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

Feb 2 '07 #3

P: n/a
Thanks! It works like a champ.
Feb 2 '07 #4

P: n/a
Thanks! It works like a champ.
Feb 2 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.