473,772 Members | 3,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Curso r 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_Mous eEnter(object sender, EventArgs e)
{
linkLabel1.Curs or = Cursors.Arrow;
linkLabel1.Text = linkLabel1.Curs or.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 6582
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.Curso r 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_Mous eEnter(object sender, EventArgs e)
{
linkLabel1.Curs or = Cursors.Arrow;
linkLabel1.Text = linkLabel1.Curs or.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.Collecti ons;
using System.Componen tModel;
using System.Windows. Forms;
using System.Data;

namespace WindowsApplicat ion8
{
public class Class1 : LinkLabel
{
Cursor _newCursor = Cursors.Arrow;
public Class1()
{

}
public Cursor NewOverrideCurs or
{
set
{
_newCursor = value;
this.OverrideCu rsor = value;
}
get
{
return this.OverrideCu rsor;
}
}
protected override void OnMouseMove(Mou seEventArgs e)
{

base.OnMouseMov e (e);
this.OverrideCu rsor = _newCursor;
}
}
}



This is what Reflector told me the linklabel does on a mouse move
event.
protected override void OnMouseMove(Mou seEventArgs e)
{
base.OnMouseMov e(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.PointInLin k(e.X, e.Y);
if (link3 != link1)
{
if (link1 != null)
{
link1.State &= ~LinkState.Hove r;
}
if (link3 != null)
{
link3.State |= LinkState.Hover ;
if (link3.Enabled)
{
this.OverrideCu rsor = Cursors.Hand;
}
}
else
{
this.OverrideCu rsor = null;
}
if (this.hoverLink Font != this.linkFont)
{
if (link1 != null)
{
this.Invalidate Link(link1);
}
if (link3 != null)
{
this.Invalidate Link(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.Collecti ons.Generic;
using System.Componen tModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows. Forms;

namespace littleApp
{
public partial class customLink : LinkLabel
{
public customLink()
{
InitializeCompo nent();
this.OverrideCu rsor = Cursors.Arrow;
}

protected override void OnMouseMove(Mou seEventArgs e)
{
base.OnMouseMov e(e);
this.OverrideCu rsor = Cursors.Arrow;
}

}
}
"David Veeneman" <da****@nospam. comwrote in message
news:OK******** ******@TK2MSFTN GP04.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.Curso r 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_Mous eEnter(object sender, EventArgs e)
{
linkLabel1.Curs or = Cursors.Arrow;
linkLabel1.Text = linkLabel1.Curs or.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
3380
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 changes back to default. I have tested setting it back to waiting after the call to run the report, - and it does get set. Has anyone else seen this wierd crystal bug I am also putting a message in the status bar - and this hold true the
0
1894
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 my problem is that i need to make the retrieved data as links (similar to objectList in Mobile application) i used LinkLabel to make an array of LinkLabels for (int n=0 ; i<j ; i++) {
3
12030
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
1268
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 the initial datagrid load. I am working with datagridcolumnstyles. I have looked at combobox examples, etc but can't seem to extrapolate. Any help appreciated! Thanks!
1
1745
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 not found in any active activation context at System.Diagnostics.Process.StartWithShellExecuteEx(ProcessStartInfo startInfo) at System.Diagnostics.Process.Start() at System.Diagnostics.Process.Start(ProcessStartInfo startInfo) at...
7
6186
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 object with a new one while the second only replaces the Current object of C1.Cursor, but I can't
12
5014
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 Hourglass and then back to arrow? Thanks a lot,
3
4694
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 form that has the System.Windows.Forms.LinkLabel controls on it is in a different project and under a different namespace from the file where the LinkLabel_LinkClicked events are, so I can't just do frm.ShowDialog under the LinkClicked method. ...
2
2139
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 screen. my problem is how to make that linklabel to work when i select the label.am using the code below but is not working:) public class Form1 : Form { System.Windows.Forms.LinkLabel linklabel;
0
10104
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6715
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.