Results 1 to 3 of 3

Thread: [RESOLVED] Changing Fonts at Runtime ?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    202

    Resolved [RESOLVED] Changing Fonts at Runtime ?

    Well i am making a Notepad Program with some useful Functions now im hanging here:

    I loaded all Fonts to a Combobox like this:

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim installed_fonts As New InstalledFontCollection
    
            For Each font_family As FontFamily In installed_fonts.Families
                tscb_font.Items.Add(font_family.Name)
            Next
    
    
        End Sub
    Now ok that works now i want to switch the Font i did this but it doesent work:

    Code:
    rtb_text.Select()
            rtb_text.SelectionFont = tscb_font.Font
    All Fonts are in the Combobox so i only need to know how to switch the Fonts...

    But it doesent work i hope you guys can help me =)

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: Changing Fonts at Runtime ?

    Code:
    'make sure selection is made in combo
    if tscb_font.selectedindex = -1 then return
    'set selectedtext to given font
    rtb_text.SelectionFont = new font(tscb_font.text, put size here)
    This will work, however it is unclear if you are looking to change the ENTIRE text of the RTB when you select a new font, or just the selected text. Just like Word, but unlike Notepad, the RTB can handle different fonts on text inside it. If you wanted to change the entire font of all the text when you change the selection, then just assign the font to the RTBs Font property instead of its SelectionFont property.

    You also need to specify a size you want the font to be. If you want to use the existing size of the existing font, you could do something like

    Code:
    rtb_text.SelectionFont = new font(tscb_font.text, SelectionFont.Size)

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2008
    Posts
    202

    Re: Changing Fonts at Runtime ?

    Quote Originally Posted by kleinma
    Code:
    'make sure selection is made in combo
    if tscb_font.selectedindex = -1 then return
    'set selectedtext to given font
    rtb_text.SelectionFont = new font(tscb_font.text, put size here)
    This will work, however it is unclear if you are looking to change the ENTIRE text of the RTB when you select a new font, or just the selected text. Just like Word, but unlike Notepad, the RTB can handle different fonts on text inside it. If you wanted to change the entire font of all the text when you change the selection, then just assign the font to the RTBs Font property instead of its SelectionFont property.

    You also need to specify a size you want the font to be. If you want to use the existing size of the existing font, you could do something like

    Code:
    rtb_text.SelectionFont = new font(tscb_font.text, SelectionFont.Size)
    Ok thx works perfect =)

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