Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Formatting text in RichTextBox?

GWHicksGWHicks Member Posts: 26
I am working on a basic text editor program and have the code setup to allow the user to Bold, Italic, and Underline selected text, but I can't seem to allow it to combine any of those features.
Also my toolbar doesn't update appropriately when new text is selected. If the text is already Bold and is selected, the Bold toolbar button doesn't go to a pressed state. I know how to make the button change states, but I am unclear as to for what event I should do it, and how to verify which state it should be.
Hope someone can point me in a general direction.
Greg Hicks

Comments

  • paulmorrisonpaulmorrison Member Posts: 127
    : I am working on a basic text editor program and have the code setup to allow the user to Bold, Italic, and Underline selected text, but I can't seem to allow it to combine any of those features.
    : Also my toolbar doesn't update appropriately when new text is selected. If the text is already Bold and is selected, the Bold toolbar button doesn't go to a pressed state. I know how to make the button change states, but I am unclear as to for what event I should do it, and how to verify which state it should be.
    : Hope someone can point me in a general direction.
    : Greg Hicks
    :
    :
    Greg, I would be interested in seeing the code you have to this point.
    paulmorrison3@hotmail.com

  • GWHicksGWHicks Member Posts: 26
    Thanks for looking at this, here is my current code for Bold, the other styles are similar coding.

    rtbMaster = RichTextBox on form

    Dim CurrentFont As System.Drawing.Font
    Dim NewFont As System.Drawing.Font
    Dim FontSize As Integer

    Private Sub TextBold()
    CurrentFont = rtbMaster.SelectionFont
    If tbbBold.Pushed = True Then
    rtbMaster.SelectionFont = New Font(CurrentFont, FontStyle.Bold)
    Else
    rtbMaster.SelectionFont = New Font(CurrentFont, FontStyle.Regular)
    End If
    End Sub

    And here is my code to change the font size:

    Private Sub ChangeFontSize()
    CurrentFont = rtbMaster.SelectionFont
    FontSize = cboFontSize.SelectedValue
    rtbMaster.Font = New System.Drawing.Font(CurrentFont, FontSize)
    End Sub

    If I change the last line for changing font size and replace CurrentFont with an actual font name ("timesnewroman") it works for resizing, but I want it to change whatever the current font is.

    Let me know if you need more code than this.



  • GWHicksGWHicks Member Posts: 26
    Actually I have changed something in the ChangeFontSize Sub and it no longer works. I will post the code that does work once I figure out what I "fixed"! (-8



Sign In or Register to comment.