|
-
Oct 28th, 2007, 12:55 PM
#1
Thread Starter
Addicted Member
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:
With richtextbox1 ' contains a loaded file of settings
.SelStart = 0
nPos2 = InStr(1, .Text, "&") 'I use "&" as the end of a setting, it deletes it afterwards
.SelLength = nPos2 - 1
checked = .SelText
textbox1.SelStart = 0
textbox1.SelLength = Len(textbox1.Text)
textbox1.SelFontName = checked ' yet, for some reason, the richtextbox doesn't change its font...
textbox1.SelStart = 0
textbox1.SelLength = 0
.SelStart = 0
.SelLength = nPos2
.SelText = "" 'deletes the setting so it can move onto the next
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
-
Oct 28th, 2007, 12:59 PM
#2
Re: richtextbox refusing to change font name
In line #8, checked is a reserved word. Did you mean it to be the name of a font?
-
Oct 28th, 2007, 01:02 PM
#3
Thread Starter
Addicted Member
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.
-
Oct 29th, 2007, 09:36 AM
#4
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?
-
Oct 29th, 2007, 10:39 AM
#5
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 }
-
Oct 29th, 2007, 10:50 AM
#6
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.
-
Oct 29th, 2007, 10:56 AM
#7
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?
-
Oct 29th, 2007, 10:57 AM
#8
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.
-
Oct 29th, 2007, 11:02 AM
#9
Re: richtextbox refusing to change font name
 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.
-
Oct 29th, 2007, 11:44 AM
#10
Re: richtextbox refusing to change font name
 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
 Originally Posted by MartinLiss
The richtextbox control is an awkward beast.
becomes very evident.
-
Jul 7th, 2009, 10:57 AM
#11
New Member
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?
-
Jul 7th, 2009, 01:19 PM
#12
Re: don't understand this thread....
 Originally Posted by ycdbsoya
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|