Dealing with the FontDialog

A

active

A few questions about the FontDialog and dealing with Fonts

Is it necessary to pass the parameters ByRef so that updated values can be
returned.?

I wouldn't think it is necessary for the font but is required for the color.
Is that correct??

Private Sub DialogSetFontVariable(ByRef acolor As Drawing.Color, ByRef
audtFontVariable As Font)

Dim FontDialog1 As New FontDialog

FontDialog1.Font = audtFontVariable ????Does this mean changes made by the
dialog are made to audtFontVariable????

FontDialog1.ShowColor = True

FontDialog1.Color = acolor

If FontDialog1.ShowDialog() <> DialogResult.Cancel Then

audtFontVariable = FontDialog1.Font.Clone ????Is this needed to update
audtFontVariable????Is clone necessary??

acolor = FontDialog1.Color ????Is this needed to update aColor????

End If





Thanks in advance for any answers,

Cal
 
H

Herfried K. Wagner [MVP]

* " active said:
A few questions about the FontDialog and dealing with Fonts

Is it necessary to pass the parameters ByRef so that updated values can be
returned.?

I wouldn't think it is necessary for the font but is required for the color.
Is that correct??

Private Sub DialogSetFontVariable(ByRef acolor As Drawing.Color, ByRef
audtFontVariable As Font)

'Color' is a value type, so you will have to pass it 'ByRef', 'Font' is
a reference type, you want to allow the procedure to change this
reference, so pass it 'ByRef' too.
Dim FontDialog1 As New FontDialog

FontDialog1.Font = audtFontVariable ????Does this mean changes made by the
dialog are made to audtFontVariable????

Why not test it on your own?
FontDialog1.ShowColor = True

FontDialog1.Color = acolor

If FontDialog1.ShowDialog() <> DialogResult.Cancel Then

audtFontVariable = FontDialog1.Font.Clone ????Is this needed to update
audtFontVariable????Is clone necessary??

Yes. Doesn't it work if you skip the 'Clone'?
acolor = FontDialog1.Color ????Is this needed to update aColor????

Yes.
 
A

active

Before I sent this I found a little bug that I don't even what to mention.
So thanks for the answers
Cal

Why not test it on your own?

I'd would really appreciate an answer to this.
The more I'm sure of the better debugging I can do.

I've been testing all day and for some reason after I leave this routine the
font is Nothing.

I've tried everything I can think of.
I'd guess that assigning audtFontVariable to FontDialog1.Font would cause
the dialog box to change the values stored in it.
If that were the case I could pass it byVal and skip the assignment below.

Except if I understand the Help the font properties are read only so that is
why I did it the way I did it.
 
H

Herfried K. Wagner [MVP]

* " active said:
I'd would really appreciate an answer to this.
The more I'm sure of the better debugging I can do.

I've been testing all day and for some reason after I leave this routine the
font is Nothing.

I've tried everything I can think of.
I'd guess that assigning audtFontVariable to FontDialog1.Font would cause
the dialog box to change the values stored in it.
If that were the case I could pass it byVal and skip the assignment below.

Except if I understand the Help the font properties are read only so that is
why I did it the way I did it.

I would use something like this:

\\\
Public Function GetIt(ByRef DestColor As Color, ByRef DestFont As Font)
Dim f As New FontDialog()
f.Font = DestFont
f.Color = DestColor
f.ShowColor = True
f.ShowDialog()
DestFont = f.Font
DestColor = f.Color
End Function

Private Sub Test()
GetIt(Me.Label1.ForeColor, Me.Label1.Font)
End Sub
///
 

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.

Ask a Question

Top