473,320 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Setting LinkLabel cursor?

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
4 6519
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
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
Thanks! It works like a champ.
Feb 2 '07 #4
Thanks! It works like a champ.
Feb 2 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
Hi, I am loading some crystal reports in a method similar to this (see below). And set the cursor to waiting while the reoprt is loaded, run and shown. BUT while the report is running the cursor...
0
by: tota | last post by:
i'm using windowsApplication to connect to DB made by SQL i need to Display the Data of the first table in the DB as links when click it it openes a table and i navigte between them using buttons...
3
by: vince | last post by:
Hello, I have a ListBox filled with many lines of simply text I want to make few lines be a LinkLabel How can I do this Thanks
0
by: Suz | last post by:
I am stumped! I can't seem to figure out how to put a linklabel in a datagrid on a windows form. I have working code that displays a linklabel in edit mode but need the linklabel to display during...
1
by: Marcus Kwok | last post by:
I am having problems getting my LinkLabel hyperlink to work properly. Every time I click on it, I get the following exception: System.ComponentModel.Win32Exception: The requested lookup key was...
7
by: Academic | last post by:
What are the different effects of the following two statements: C1.Cursor = Cursors.WaitCursor C1.Cursor.Current = Cursors.WaitCursor I believe the first replaces the entire C1.Cursor...
12
by: info | last post by:
Hi All, I am trying to set the hourglass cursor inside a class that has nothing to do with MainForm class and I don't want to pass a reference to MainForm. How can I set the current cursor to...
3
by: bsturg21 | last post by:
Hello, I have a windows form that has a series of linklabels on it, and I need to have each linklabel, when clicked, open a separate windows form that has a single paramter passed into it. The...
2
by: prokopis | last post by:
am using c# for windows applications. am using dynamic linklayer array to print some labels in the form.i get some data from the database i add them in the linklabel array and i print it on the...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.