Post by bobowk on May 25, 2016 17:03:50 GMT 10
I have three checkboxes, one called Bold, Underline and Italic. The names of these are CheckBox1, CheckBox2 and Checkbox3. I want to be able to... Let's say, selected checkbox1 and checkbox 2 so my text will be bold and italic. Although, when I do this, only one of them gets selected. Ive tried this. But to repeat checkbox2.checked=true and all of that it becomes a mess.
If CheckBox1.Checked = True And CheckBox2.Checked = False And CheckBox3.Checked = False Then
If RichTextBox1.SelectionFont IsNot Nothing Then
RichTextBox1.SelectionFont = New Font(ComboBox1.Text, CInt(ComboBox2.SelectedItem), FontStyle.Bold)
Else
RichTextBox1.SelectionFont = New Font(ComboBox1.Text, CInt(ComboBox2.SelectedItem), FontStyle.Bold) End If Any easier way? I want it like microsoft word.
|
|
Post by ArchApps on May 27, 2016 13:25:41 GMT 10
RichTextBox.Font = New Font(FontName.Text, 10, FontStyle.Regular)
|
|
Post by Nathan Lecompte on May 27, 2016 16:06:14 GMT 10
It's in the source code of the "How to make an advanced text editor in VB.NET" video, you can view the video here: Source code link: techview.link/1Y7BIAo
|
|
Post by bobowk on May 27, 2016 17:33:14 GMT 10
Nathan Lecompte, the Underline, Bold and italic cant do all at the same time. Please help!
|
|
Post by Nathan Lecompte on May 28, 2016 14:19:51 GMT 10
Ah, yeah it seems that back then I hadn't made it to allow selections to have multiple font-styles. This should work: Private Sub ButtonBold_Click(sender As System.Object, e As System.EventArgs) Handles ButtonBold.Click 'Sets the selected text to bold 'If RichTextBoxPrintCtrl1.SelectionFont.Style = FontStyle.Bold Then ' RichTextBoxPrintCtrl1.SelectionFont = New Font(CurrentFont, CurrentSize, FontStyle.Regular) 'Else ' RichTextBoxPrintCtrl1.SelectionFont = New Font(CurrentFont, CurrentSize, FontStyle.Bold) 'End If Dim font_style_set As New Font(RichTextBoxPrintCtrl1.SelectionFont, RichTextBoxPrintCtrl1.SelectionFont.Style Xor FontStyle.Bold) RichTextBoxPrintCtrl1.SelectionFont = font_style_set If ButtonBold.BackColor = Color.WhiteSmoke Then ButtonBold.BackColor = Color.Gainsboro Else ButtonBold.BackColor = Color.WhiteSmoke End If End Sub
Private Sub ButtonItalic_Click(sender As System.Object, e As System.EventArgs) Handles ButtonItalic.Click 'Sets the selected text to italic 'If RichTextBoxPrintCtrl1.SelectionFont.Style = FontStyle.Italic Then ' RichTextBoxPrintCtrl1.SelectionFont = New Font(CurrentFont, CurrentSize, FontStyle.Regular) 'Else ' RichTextBoxPrintCtrl1.SelectionFont = New Font(CurrentFont, CurrentSize, FontStyle.Italic) 'End If Dim font_style_set As New Font(RichTextBoxPrintCtrl1.SelectionFont, RichTextBoxPrintCtrl1.SelectionFont.Style Xor FontStyle.Italic) RichTextBoxPrintCtrl1.SelectionFont = font_style_set If ButtonItalic.BackColor = Color.WhiteSmoke Then ButtonItalic.BackColor = Color.Gainsboro Else ButtonItalic.BackColor = Color.WhiteSmoke End If End Sub
Private Sub ButtonUnderlined_Click(sender As System.Object, e As System.EventArgs) Handles ButtonUnderlined.Click 'Sets the selected text to underline 'If RichTextBoxPrintCtrl1.SelectionFont.Style = FontStyle.Underline Then ' RichTextBoxPrintCtrl1.SelectionFont = New Font(CurrentFont, CurrentSize, FontStyle.Regular) 'Else ' RichTextBoxPrintCtrl1.SelectionFont = New Font(CurrentFont, CurrentSize, FontStyle.Underline) 'End If Dim font_style_set As New Font(RichTextBoxPrintCtrl1.SelectionFont, RichTextBoxPrintCtrl1.SelectionFont.Style Xor FontStyle.Underline) RichTextBoxPrintCtrl1.SelectionFont = font_style_set If ButtonUnderlined.BackColor = Color.WhiteSmoke Then ButtonUnderlined.BackColor = Color.Gainsboro Else ButtonUnderlined.BackColor = Color.WhiteSmoke End If End Sub
Private Sub ButtonStrikeout_Click(sender As System.Object, e As System.EventArgs) Handles ButtonStrikeout.Click 'Sets the selected text to strikeout 'If RichTextBoxPrintCtrl1.SelectionFont.Style = FontStyle.Strikeout Then ' RichTextBoxPrintCtrl1.SelectionFont = New Font(CurrentFont, CurrentSize, FontStyle.Regular) 'Else ' RichTextBoxPrintCtrl1.SelectionFont = New Font(CurrentFont, CurrentSize, FontStyle.Strikeout) 'End If Dim font_style_set As New Font(RichTextBoxPrintCtrl1.SelectionFont, RichTextBoxPrintCtrl1.SelectionFont.Style Xor FontStyle.Strikeout) RichTextBoxPrintCtrl1.SelectionFont = font_style_set If ButtonStrikeout.BackColor = Color.WhiteSmoke Then ButtonStrikeout.BackColor = Color.Gainsboro Else ButtonStrikeout.BackColor = Color.WhiteSmoke End If End Sub
This is done using the code from the tutorial, so it uses buttons instead of checkboxes; therefore you wont need to change the backcolor in order to give it a checked look (you also need to change RichTextBoxPrintCtrl1 to the name of your RichTextBox) Hope this helps!
|
|
Post by bobowk on Jun 1, 2016 11:38:29 GMT 10
Nathan Lecompte When I change the size, the bold, Italic and underline resets... It doesn't stay.
|
|
Post by Nathan Lecompte on Jun 1, 2016 17:10:56 GMT 10
What code are you using to change the size?
|
|
Post by bobowk on Jun 2, 2016 11:06:34 GMT 10
Nathan Lecompte Dim exf As Font = RichTextBox1.SelectionFont If RichTextBox1.SelectionFont IsNot Nothing Then RichTextBox1.SelectionFont = New Font(ComboBox1.Text, CInt(ComboBox2.Text), FontStyle.Regular)
Else RichTextBox1.SelectionFont = New Font(ComboBox1.Text, CInt(ComboBox2.Text), FontStyle.Regular)
End If
|
|
Post by Nathan Lecompte on Jun 2, 2016 17:17:01 GMT 10
Not sure why you have "Dim exf As Font = RichTextBox1.SelectionFont" there since it isn't exactly being used. There also isn't a need to check for a SelectionFont, the reason why your FontStyle keeps changing is because you're setting it to Regular; just remove the FontStyle section:
RichTextBox1.SelectionFont = New Font(ComboBox1.Text, ComboBox2.Text)
|
|