fourinjuly4ij
New member
- Joined
- Mar 3, 2005
- Messages
- 3
- Programming Experience
- 3-5
Hi,
So I'm writting a small little word processor program just to get back into programming again. Right now, I have a toolbar with buttons, a RichTextBox for writing in, and two combobox's filled with the installed fonts and font sizes.
My actual question is, at this point when I change the font with the combobox it checks to see if any text in the RichTextBox is highlighted. If it is highlighted it changes the highlighted text, which is fine. My problem is when nothing is highlighted, it changes everything in the textbox to that font. I know why it does this, but I don't know how to just set the font past where the cursor is in the RichTextBox.
I know the problem lies after the Else statement. I set the entire Font property of the RichTextBox, but how do I set it for just after whee the cursor is located?
Thanks!
P.S.
txtContents = RichTextBox
cboFonts = Font combobox
cboFontSize = Font size combobox
So I'm writting a small little word processor program just to get back into programming again. Right now, I have a toolbar with buttons, a RichTextBox for writing in, and two combobox's filled with the installed fonts and font sizes.
My actual question is, at this point when I change the font with the combobox it checks to see if any text in the RichTextBox is highlighted. If it is highlighted it changes the highlighted text, which is fine. My problem is when nothing is highlighted, it changes everything in the textbox to that font. I know why it does this, but I don't know how to just set the font past where the cursor is in the RichTextBox.
VB.NET:
Private Sub cboFonts_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cboFonts.SelectedIndexChanged
Dim ComboFonts As Drawing.Text.InstalledFontCollection
ComboFonts = New Drawing.text.InstalledFontCollection
If txtContents.SelectionLength > 0 Then
txtContents.SelectionFont = New System.Drawing.Font(ComboFonts.Families(cboFonts.SelectedIndex), CInt(cboFontSize.Text), Font.Style)
txtContents.Focus()
Else
txtContents.Font = New System.Drawing.Font(ComboFonts.Families(cboFonts.SelectedIndex), CInt(cboFontSize.Text), Font.Style)
End If
End Sub
I know the problem lies after the Else statement. I set the entire Font property of the RichTextBox, but how do I set it for just after whee the cursor is located?
Thanks!
P.S.
txtContents = RichTextBox
cboFonts = Font combobox
cboFontSize = Font size combobox