Bit Mask

Xkape

Member
Joined
Apr 17, 2003
Messages
12
Location
Nashville, TN
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
 
You have to combine values:

Code:
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.
 
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
 

Similar threads

A
Replies
0
Views
148
Afshan Gul
A
V
Replies
0
Views
125
VB Novice Hendri
V
V
Replies
0
Views
109
VB Novice Hendri
V
V
Replies
0
Views
138
VB Novice Hendri
V
Back
Top