Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello everyone,

 

I am working on a small project with font controls, and it has 3 checkbox controls Bold, Italic, and Underline. With a textbox at the bottom of the form, with a word.

 

When you check the Bold the text goes bold, etc

 

Question?

How do you make all three work at the same time?

 

Like this Sample text

 

Here is some of the code

 

If CheckBoxBold.Checked = True Then

txtSample.Font = New System.Drawing.Font(txtSample().Font, 1)

ElseIf CheckBoxItalic.Checked = True Then

txtSample.Font = New System.Drawing.Font(txtSample().Font, 3)

ElseIf CheckBoxUnderline.Checked = True Then

txtSample.Font = New System.Drawing.Font(txtSample().Font, 7)

Else

txtSample.Font = New System.Drawing.Font(txtSample().Font, 0)

End If

 

Is there something that goes into the formload event?

 

Thanks for the help,

J

  • *Gurus*
Posted

You have to combine values:

 

Dim myStyle As FontStyle

If CheckBoxBold.Checked Then myStyle = myStyle Or FontStyle.Bold
If CheckBoxItalic.Checked Then myStyle = myStyle Or FontStyle.Italic
If CheckBoxUnderline.Checked Then myStyle = myStyle Or FontStyle.Underline

txtSample.Font = New Font(txtSample.Font, myStyle)

 

Try something like that.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Thanks for the advice. However this is what I ended up with.

 

Dim FontBMask As Integer

 

 

Private Sub frmFontFun_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim ff As FontFamily

For Each ff In System.Drawing.FontFamily.Families

If Not ff.Name = "Monotype Corsiva" Then

ComboBox1.Items.Add(ff.Name)

End If

Next

ComboBox1.Text = ComboBox1.Font.Name

FontBMask = 0

End Sub

 

Private Sub CheckBoxBold_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBoxBold.CheckedChanged

If CheckBoxBold.Checked = True Then

FontBMask = FontBMask + 1

Else

FontBMask = FontBMask - 1

End If

txtSample.Font = New System.Drawing.Font(txtSample().Font, FontBMask)

End Sub

 

Private Sub CheckBoxUnderline_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBoxUnderline.CheckedChanged

If CheckBoxUnderline.Checked = True Then

FontBMask = FontBMask + 4

Else

FontBMask = FontBMask - 4

End If

txtSample.Font = New System.Drawing.Font(txtSample().Font, FontBMask)

End Sub

End Class

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...