473,378 Members | 1,607 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,378 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 6528
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.