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?".
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
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.
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.