By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,624 Members | 1,747 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,624 IT Pros & Developers. It's quick & easy.

How make label bold at runtime?

P: n/a
How do I make a label bold at runtime (i.e. in code)?

Thanks,
Ron
Jul 5 '07 #1
Share this Question
Share on Google+
8 Replies


P: n/a
Label1.Font.Bold = True
"Ronald S. Cook" <rc***@westinis.comwrote in message
news:uJ*************@TK2MSFTNGP06.phx.gbl...
How do I make a label bold at runtime (i.e. in code)?

Thanks,
Ron


Jul 5 '07 #2

P: n/a
It says bold is a read-only property.

"Scott M." <s-***@nospam.nospamwrote in message
news:OT**************@TK2MSFTNGP02.phx.gbl...
Label1.Font.Bold = True
"Ronald S. Cook" <rc***@westinis.comwrote in message
news:uJ*************@TK2MSFTNGP06.phx.gbl...
>How do I make a label bold at runtime (i.e. in code)?

Thanks,
Ron



Jul 5 '07 #3

P: n/a
Ron,

Label1.Font = New Font(Label1.Font, FontStyle.Bold)

Kerry Moorman
"Ronald S. Cook" wrote:
It says bold is a read-only property.

"Scott M." <s-***@nospam.nospamwrote in message
news:OT**************@TK2MSFTNGP02.phx.gbl...
Label1.Font.Bold = True
"Ronald S. Cook" <rc***@westinis.comwrote in message
news:uJ*************@TK2MSFTNGP06.phx.gbl...
How do I make a label bold at runtime (i.e. in code)?

Thanks,
Ron



Jul 5 '07 #4

P: n/a

"Ronald S. Cook" <rc***@westinis.comwrote in message
news:um**************@TK2MSFTNGP03.phx.gbl...
It says bold is a read-only property.
This may be what you're looking for possibly. It seems kind of ridiculous
that you just can't set .Bold = true.

http://www.thescarms.com/dotnet/MouseOver.aspx

Google is your friend.

Jul 5 '07 #5

P: n/a
"Mr. Arnold" <MR. Ar****@Arnold.comschrieb:
>It says bold is a read-only property.

This may be what you're looking for possibly. It seems kind of ridiculous
that you just can't set .Bold = true.
'Font' is only a wrapper around a Win32 'HFONT'. In Win32, font objects
cannot be altered after they have been created.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jul 5 '07 #6

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.atha scritto nel
messaggio
>This may be what you're looking for possibly. It seems kind of ridiculous
that you just can't set .Bold = true.

'Font' is only a wrapper around a Win32 'HFONT'. In Win32, font objects
cannot be altered after they have been created.
You're right, but this is not a good way.
In VB6 the Font wrapper let you change the style, name, size, ecc... and in
..Net object of this type tell me "but I need to Dispose the old one or the
fw will do it for me?".

:)
Jul 5 '07 #7

P: n/a
Ron -

I woudl declare the two fonts (bold and not) as private variables (ie
as "fields" in OOP terminology), and set their values in the form's
onload event handler. That will allow you to reuse the same font
objects and swap them as needed, instead of constructing a new one
each time you desire thie effect. See how much cleaner this is?

Private myFont As Font
Private myFontBold As Font

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
myFont = New Font(Label1.Font, FontStyle.Regular)
myFontBold = New Font(Label1.Font, FontStyle.Bold)
End Sub

Private Sub BoldDemo(ByVal DoIt As Boolean)
If DoIt Then
Label1.Font = myFontBold
Else
Label1.Font = myFont
End If
End Sub
Good Luck,

-Mark

Jul 5 '07 #8

P: n/a
"Fabio" <zn*******@virgilio.itschrieb:
>>This may be what you're looking for possibly. It seems kind of
ridiculous that you just can't set .Bold = true.

'Font' is only a wrapper around a Win32 'HFONT'. In Win32, font objects
cannot be altered after they have been created.

You're right, but this is not a good way.
In VB6 the Font wrapper let you change the style, name, size, ecc... and
in .Net object of this type tell me "but I need to Dispose the old one or
the fw will do it for me?".

Do not dispose it if it is used for more than one control. If it isn't used
any more, you can (my recommendation) safely dispose it.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Jul 5 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.