Question LinkLabel Question...

aaronking

Member
Joined
Mar 21, 2009
Messages
6
Programming Experience
Beginner
Hello,

I have a linklabel on a form (called LinkLabel1) and I want to remove the underline of the control.

I know you can change the font ect and it has a tickbox for underline..

However, I want to remove the underline during runtime (using code).

Anyone know how to remove it using code during runtime?

I am using vb.net 2008 and I creating a 'Smart Device' application for 'windows CE'

anyone know how to do this?

Thanks.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,377
Location
Norway
Programming Experience
10+
aaronking said:
I know you can change the font ect and it has a tickbox for underline..
That is not how the underline for LinkLabel control works. You set the LinkLabel.LinkBehavior Property (System.Windows.Forms), one of the values is LinkBehavior.NeverUnderline. Leave the Fonts Underline unchecked in all cases. Note: documentation doesn't list any control specific members for LinkLabel in CE, is that right? If so, see the reply below.
Hack said:
The underline property is Read-Only so it would have to be moved in design.
In case you wondered, you can create a new Font object (also based on existing) and set new styles with constructor, this one for example: Font Constructor (Font, FontStyle) (System.Drawing)
Code:
Dim f As Font = Me.LinkLabel1.Font        
Me.LinkLabel1.Font = New Font(f, f.Style And Not FontStyle.Underline)
 

aaronking

Member
Joined
Mar 21, 2009
Messages
6
Programming Experience
Beginner
Dim f As Font = Me.LinkLabel1.Font
Me.LinkLabel1.Font = New Font(f, f.Style And Not FontStyle.Underline)
This does not work..

it has a blue underline under: New Font(f, f.Style And Not FontStyle.Underline)

and it says: Overload resolution failed becasue no accessible 'New' accepts this number of arguments.

I am creating this with vb.net 2008 and its for a smart device application for Windows CE.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,377
Location
Norway
Programming Experience
10+
Oh, I forgot to check that also, CE really puts the restraints on ya, huh? :) For CE these constructors are listed:
help said:
Font(FontFamily, Single, FontStyle)
Font(String, Single, FontStyle)
Font Constructor (System.Drawing) (in the Frameworks dropdown select only CE)

Code:
New Font(f.FontFamily, f.Size, f.Style And Not FontStyle.Underline)
 

aaronking

Member
Joined
Mar 21, 2009
Messages
6
Programming Experience
Beginner
I have added the following code on the Form_Load:

Code:
Dim f As Font = Me.LinkLabel1.Font
        Me.LinkLabel1.Font = New Font("arial", f.Size, f.Style And Not FontStyle.Underline)
but when I run the application on windows XP the underline is still there.

But if I run the application on CE its gone.

Is there a way of making the underline hidden on XP as well as CE?
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,377
Location
Norway
Programming Experience
10+
In full framework the LinkBehavior property takes effect, which is why I adviced to not underline the Font property with this.
 

aaronking

Member
Joined
Mar 21, 2009
Messages
6
Programming Experience
Beginner
In full framework the LinkBehavior property takes effect, which is why I adviced to not underline the Font property with this.
I have added a linklabel to the form without changing any settings to the font. (still didn't work) so I changed the underline in the font and it still didn't work.

the underline is not there when running it on the Windows CE device, but as soon as i run the same application on XP the line is there.
 

send2te

Well-known member
Joined
Dec 13, 2009
Messages
46
Programming Experience
10+
{Be hAppy}

Dim MyLabel As New LinkLabel
MyLabel.Text = "I am not under lined"
MyLabel.LinkBehavior = LinkBehavior.NeverUnderline
Me.Controls.Add(MyLabel)
 

aaronking

Member
Joined
Mar 21, 2009
Messages
6
Programming Experience
Beginner
{Be hAppy}

Dim MyLabel As New LinkLabel
MyLabel.Text = "I am not under lined"
MyLabel.LinkBehavior = LinkBehavior.NeverUnderline
Me.Controls.Add(MyLabel)
It don't work.. I am trying to write this for windows CE (smart device application for winCE)
 
Top Bottom