Results 1 to 11 of 11

Thread: Font and Size

  1. #1
    Guest
    Hi!
    Still working on my NotePad thing. My problem is that I don't know hoe to change the font and/or size on the marked text. And another problem is that when i mark a text and then click my ComboBox, the text gets unmarked. Plz, help me!

    / Erik

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    I assume you're using a RichTextBox because you can't do this with the original textbox.
    Code:
    RichTextBox1.SelFontName = "Times New Roman"
    RichTextBox1.SelFontSize = 16
    The text isn't really deselected when the textbox loses focus but it's rather hidden.
    If you don't want this behaviour set the HideSelection property to False at design time.

    Good luck!

    PS. Hur är livet i Linköping DS.

  3. #3
    Guest
    Thanks for the help!

    PS. Bara bra =) DS.

  4. #4
    Guest

    Oops

    Hi again!
    The code you gave me didn't work! I don't know why. This is how it looks like:

    Private Sub chooseFont_Change()
    text.SelFontName = chooseFont.Value
    End Sub

    What do u think?

    / Erik

  5. #5
    Guest
    You need to use a RichTextBox to do this.

    [Edited by Megatron on 09-17-2000 at 11:54 AM]

  6. #6
    Guest
    I just finished writing an example of working with formatted text. Add the following code to a Form with a RichTextBox, CommonDialog and a CommandButton.

    Code:
    On Error Resume Next
    
    With CommonDialog1
        .Flags = cdlCFBoth Or cdlCFEffects
        .FontBold = RichTextBox1.SelBold
        .FontItalic = RichTextBox1.SelItalic
        .FontUnderline = RichTextBox1.SelUnderline
        .FontStrikethru = RichTextBox1.SelStrikeThru
        .FontName = RichTextBox1.SelFontName
        .FontSize = RichTextBox1.SelFontSize
        .Color = RichTextBox1.SelColor
    End With
    
    CommonDialog1.ShowFont
    
    If Err <> 32755 Then
        With RichTextBox1
            .SelBold = CommonDialog1.FontBold
            .SelItalic = CommonDialog1.FontItalic
            .SelUnderline = CommonDialog1.FontUnderline
            .SelStrikeThru = CommonDialog1.FontStrikethru
            .SelFontName = CommonDialog1.FontName
            .SelFontSize = CommonDialog1.FontSize
            .SelColor = CommonDialog1.Color
        End With
    End If
    When you select text in the RichTextBox then click the button, the FontDialog Box will appear and from there, you can format your text.

  7. #7
    Guest

    Won't work!

    Hi!
    It won't just work! An alert box pops up and say:
    Compile Error:
    Invalid Outside procedure


    / Erik

    PS. I have added RichTextBox, CommonDialog and CommandButton, and I haven't changed there names. DS.

  8. #8
    Guest
    What line are you getting it on?

  9. #9
    Guru Yonatan's Avatar
    Join Date
    Apr 1999
    Location
    Israel
    Posts
    892
    Put it in the CommandButton.
    Code:
    Private Sub Command1_Click()
        ' Megatron's code here
    End Sub

  10. #10
    Guest
    Now it worked. My bad =)
    But that wasn't really how I wanted it. I was thinking more like word, y'know, with these buttons. But thx anyway! I will proborbly use this in an other program.

    / Erik

  11. #11
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: Oops

    Originally posted by TimeHero
    Hi again!
    The code you gave me didn't work! I don't know why. This is how it looks like:

    Private Sub chooseFont_Change()
    text.SelFontName = chooseFont.Value
    End Sub
    I assume chooseFont is the ComboBox.
    The Change event of a ComboBox will only be fired when the user types in the textbox area. When you click to choose an item in the drop down list box the Click event is fired.
    So just move the code to the Click event.
    Code:
    Private Sub chooseFont_Click()
        text.SelFontName = chooseFont.List(chooseFont.ListIndex)
    End Sub
    Good luck!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width