|
-
Oct 11th, 2006, 04:42 PM
#1
Thread Starter
Member
[RESOLVED] linklabel styling?
Hi,
How can I change the font, text size and change the text color of the link when the mouse is hovered over it?
I have played with:
Code:
Linklabel.font = Verdana;
Linklabel.forecolor = red;
Neither seem to work and the color part isn't what I am looking for.
Any help would be much appriciated.
Thanks,
Al
-
Oct 11th, 2006, 05:26 PM
#2
Re: linklabel styling?
If you notice there is a ForeColor property and a LinkColor Property, so if the entire text in linklabel is acting as a link then use LinkColor.
VB Code:
this.linkLabel1.LinkColor = Color.Red;
'Same for Forecolor
this.linkLabel1.ForeColor = Color.Red;
To change the font:
VB Code:
this.linkLabel1.Font = new System.Drawing.Font("Verdana",(float)(10.0),FontStyle.Regular);
EDIT: sorry, thought 'twas a VB question!!
Last edited by Harsh Gupta; Oct 11th, 2006 at 05:30 PM.
-
Oct 12th, 2006, 05:42 AM
#3
Thread Starter
Member
Re: linklabel styling?
great thanks harsh gupta!
That put me in the correct direction but now I have a further issue. My linklabels are created dynamically using this
Code:
public void AddNewLinkLabel()
{
LinkLabel aLabel = new LinkLabel();
this.List.Add(aLabel);
((Form1)Form1.ActiveForm).panel1.Controls.Add(aLabel);
//set linklabel properties
aLabel.AutoSize = true;
aLabel.LinkVisited = false;
aLabel.Visible = true;
aLabel.Top = 5;
aLabel.Height = 15;
aLabel.LinkColor = System.Drawing.Color.Blue;
aLabel.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
//aLabel.Font.FontFamily.Name.
aLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
// handler for clicked event of news title label
aLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(ClickHandler);
aLabel.MouseMove += new MouseEventHandler(aLabel_MouseMove);
aLabel.MouseLeave += new EventHandler(aLabel_MouseLeave);
aLabel.MouseHover += new EventHandler(aLabel_MouseHover);
}
and I have assigned Event Handlers dynamically which look like this
Code:
private void aLabel_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
aLabel.LinkColor = System.Drawing.Color.Red;
}
private void aLabel_MouseLeave(object sender, System.EventArgs e)
{
aLabel.LinkColor = System.Drawing.Color.Blue;
}
private void aLabel_MouseHover(object sender, System.EventArgs e)
{
aLabel.LinkColor = System.Drawing.Color.Red;
}
The issue is this won't compile as it can't find a linklabel called aLabel as they don't exist yet, until they are created dynamically.
Is there away to do this to enable it to compile and execute correctly?
Many thanks,
Al
-
Oct 12th, 2006, 06:58 AM
#4
Re: linklabel styling?
Whether or not you've created your LinkLabels at run time, the aLabel variable is declared within the AddNewLinkLabel method so it doesn't exist outside of that method. Within an event handler you reference the object that raised the event via the 'sender' argument:
Code:
private void aLabel_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
((LinkLabel)sender).LinkColor = System.Drawing.Color.Red;
}
Then you can use the same method to handle the event for as many different Linklabel's as you like.
-
Oct 12th, 2006, 07:05 AM
#5
Thread Starter
Member
Re: linklabel styling?
 Originally Posted by jmcilhinney
Whether or not you've created your LinkLabels at run time, the aLabel variable is declared within the AddNewLinkLabel method so it doesn't exist outside of that method. Within an event handler you reference the object that raised the event via the 'sender' argument:
Code:
private void aLabel_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
((LinkLabel)sender).LinkColor = System.Drawing.Color.Red;
}
Then you can use the same method to handle the event for as many different Linklabel's as you like.
Great thanks jmcilhinney.
Worked a treat.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|