Font dialog

alander

Well-known member
Joined
Jun 26, 2007
Messages
120
Location
Singapore
Programming Experience
5-10
I have 2 checkboxes to show if italics / bold was selected, however it doesnt show when i click ok on the dialog, but only show the 2nd time i open the dialog and click ok
Help anyone?
wrong code
VB.NET:
With fontDlgDefault.Font

     If fontDlgDefault.ShowDialog() = Windows.Forms.DialogResult.OK Then
                    txtDefFontFamily.Text = .Name
            txtDefFontSize.Text = .Size

            If .Italic Then : chkDefItalic.Checked = True
            Else : chkDefItalic.Checked = False
            End If

            If .Bold Then : chkDefBold.Checked = True
            Else : chkDefBold.Checked = False
            End If

        End With
    End If

It was the with, i cant bind it b4 user clicks ok

right code
VB.NET:
     If fontDlgDefault.ShowDialog() = Windows.Forms.DialogResult.OK Then
        With fontDlgDefault.Font
            txtDefFontFamily.Text = .Name
            txtDefFontSize.Text = .Size

            If .Italic Then : chkDefItalic.Checked = True
            Else : chkDefItalic.Checked = False
            End If

            If .Bold Then : chkDefBold.Checked = True
            Else : chkDefBold.Checked = False
            End If

        End With
    End If
 
Last edited:
Your code is more complex than necessary. This:
VB.NET:
            If .Italic Then : chkDefItalic.Checked = True
            Else : chkDefItalic.Checked = False
            End If

            If .Bold Then : chkDefBold.Checked = True
            Else : chkDefBold.Checked = False
            End If
should be replaced with this:
VB.NET:
            chkDefItalic.Checked = .Italic
            chkDefBold.Checked = .Bold
Isn't that nicer?
 
thanks for the tip
 
Back
Top