Results 1 to 12 of 12

Thread: richtextbox refusing to change font name

  1. #1

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    richtextbox refusing to change font name

    Well, I have this code (contrary to what it looks like, "textbox1" is definately, certainly, 100% sure that it's referring to a richtextbox, as some other code already works). For some reason, the font isn't changing:

    vb Code:
    1. With richtextbox1 ' contains a loaded file of settings
    2. .SelStart = 0
    3. nPos2 = InStr(1, .Text, "&") 'I use "&" as the end of a setting, it deletes it afterwards
    4. .SelLength = nPos2 - 1
    5. checked = .SelText
    6. textbox1.SelStart = 0
    7. textbox1.SelLength = Len(textbox1.Text)
    8. textbox1.SelFontName = checked ' yet, for some reason, the richtextbox doesn't change its font...
    9. textbox1.SelStart = 0
    10. textbox1.SelLength = 0
    11. .SelStart = 0
    12. .SelLength = nPos2
    13. .SelText = "" 'deletes the setting so it can move onto the next
    14. End With

    Now, I've already managed to apply this to text colour and a caption, so why shouldn't this be working here? If I check the contents of "checked", it returns the name of the font that I wanted, yet there is no font change

  2. #2

  3. #3

    Thread Starter
    Addicted Member ajames's Avatar
    Join Date
    Mar 2005
    Location
    Wales, UK
    Posts
    178

    Re: richtextbox refusing to change font name

    I changed that to "checkdr" with no avail. It's a variable that stores the name of a font temporarily.

    EDIT: In more detail, it stores the font name temporarily whilst the text in textbox1 is being selected so that .selFontName can be used
    Last edited by ajames; Oct 28th, 2007 at 01:51 PM.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: richtextbox refusing to change font name

    As a test, hard code the name to see if it works
    Code:
    textbox1.SelFontName = "Arial"
    Also, is checkdr as string variable?

  5. #5
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: richtextbox refusing to change font name

    The richtextbox control is an awkward beast. In order for you to change the font or to include more than one font in the same rtb, you need to alter the textRFT of the rtb. For example the textRTF of the rtb may originally look like this

    {\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 MS Sans Serif;}}
    \viewkind4\uc1\pard\lang1033\f0\fs17 RichTextBox2
    \par }


    and to add Arial font text to that rtb you'd first have to edit the textRTF to look like

    {\rtf1\ansi\ansicpg1252\deff0{\fonttbl{\f0\fnil\fcharset0 Arial;}{\f1\fnil\fcharset0 MS Sans Serif;}}
    \viewkind4\uc1\pard\lang1033\b\fs17 RichTextBox1
    \par \b0 RichTextBox2\f1
    \par }

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: richtextbox refusing to change font name

    I use an RTB in my Code Library and I've never had a problem with changing the font or the font size.

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: richtextbox refusing to change font name

    Okay I may have misspoke when I said "In order for you to change the font or to include more than one font in the same rtb...". Does your code library entry allow more than one font in the same rtb?

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: richtextbox refusing to change font name

    The way I have it set up, it affects the entire control, not selective text. That would be more difficult, but doable.

    For one thing, the selected text font change wouldn't be there the next time the program ran because there wouldn't be anything selected.

  9. #9
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Re: richtextbox refusing to change font name

    Quote Originally Posted by Hack
    The way I have it set up, it affects the entire control, not selective text. That would be more difficult, but doable.

    For one thing, the selected text font change wouldn't be there the next time the program ran because there wouldn't be anything selected.
    The "more difficult" part would be that anytime you need to have more than one font or font size or font color etc in the same rtb you first need to add the appropriate "code" to the textRTF.

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: richtextbox refusing to change font name

    Quote Originally Posted by MartinLiss
    The "more difficult" part would be that anytime you need to have more than one font or font size or font color etc in the same rtb you first need to add the appropriate "code" to the textRTF.
    Yep, you are right, and it is in cases like this that
    Quote Originally Posted by MartinLiss
    The richtextbox control is an awkward beast.
    becomes very evident.

  11. #11
    New Member
    Join Date
    Jun 2009
    Posts
    2

    Question Re: don't understand this thread....

    I realise this is an old thread, but I'm ploughing through old threads to try & solve some of my RTB problems.
    This thread has thrown me a bit, because I have coding in my app which allows for multiple fonts in a single RTB, which seems to work fine.
    If the user selects some text in the RTB and clicks on the Font button on my text toolbar, I use the commondialog so they can change the font attributes for the selected text.

    Code:
    Select Case Button.Key
    
        Case Is = "Font"                                                  'MLHIDE
           ' Set Cancel to True.
           cdlFont.CancelError = True
           On Error GoTo ErrHandler
           ' Set the Flags property.
           cdlFont.FLAGS = cdlCFBoth Or cdlCFEffects
           ' Display the Font dialog box.
           cdlFont.ShowFont
           ' Set text properties according to user's
           ' selections.
           On Error GoTo 0
           rtbText(intRTBIndex).SelFontName = cdlFont.FontName
           rtbText(intRTBIndex).SelFontSize = cdlFont.FontSize
           rtbText(intRTBIndex).SelBold = cdlFont.FontBold
           rtbText(intRTBIndex).SelItalic = cdlFont.FontItalic
           rtbText(intRTBIndex).SelUnderline = cdlFont.FontUnderline
           rtbText(intRTBIndex).SelStrikeThru = cdlFont.FontStrikethru
           rtbText(intRTBIndex).SelColor = cdlFont.Color
           Call rtbText_SelChange(intRTBIndex)
    It all seems to work OK, and the RTB itself does the job of adding the new font into the header info in the TextRTF.

    Am I missing something here?

  12. #12
    PowerPoster isnoend07's Avatar
    Join Date
    Feb 2007
    Posts
    3,237

    Re: don't understand this thread....

    Quote Originally Posted by ycdbsoya View Post
    I realise this is an old thread, but I'm ploughing through old threads to try & solve some of my RTB problems.
    This thread has thrown me a bit, because I have coding in my app which allows for multiple fonts in a single RTB, which seems to work fine.
    If the user selects some text in the RTB and clicks on the Font button on my text toolbar, I use the commondialog so they can change the font attributes for the selected text.

    Code:
    Select Case Button.Key
    
        Case Is = "Font"                                                  'MLHIDE
           ' Set Cancel to True.
           cdlFont.CancelError = True
           On Error GoTo ErrHandler
           ' Set the Flags property.
           cdlFont.FLAGS = cdlCFBoth Or cdlCFEffects
           ' Display the Font dialog box.
           cdlFont.ShowFont
           ' Set text properties according to user's
           ' selections.
           On Error GoTo 0
           rtbText(intRTBIndex).SelFontName = cdlFont.FontName
           rtbText(intRTBIndex).SelFontSize = cdlFont.FontSize
           rtbText(intRTBIndex).SelBold = cdlFont.FontBold
           rtbText(intRTBIndex).SelItalic = cdlFont.FontItalic
           rtbText(intRTBIndex).SelUnderline = cdlFont.FontUnderline
           rtbText(intRTBIndex).SelStrikeThru = cdlFont.FontStrikethru
           rtbText(intRTBIndex).SelColor = cdlFont.Color
           Call rtbText_SelChange(intRTBIndex)
    It all seems to work OK, and the RTB itself does the job of adding the new font into the header info in the TextRTF.

    Am I missing something here?
    I agree i use i have a lot of rtb's and never had this problem they are speaking of. I can change the font, color and size of each individual letter in a word add superscript, subscript, word color shading save the rtb. Open the rtb and everything is still as i changed it. I do not understand this thread
    Waiting for a full featured smart phone with out marrying a provider
    Go Android
    Go raiders

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