By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,089 Members | 2,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,089 IT Pros & Developers. It's quick & easy.

changing font type in RTB

P: n/a
Hi all,

I know now how to change the font name of a RTF file in a RTB control using,
for example:
RTextBox1.SelFontName = cmbFonts.Text

I have a RTF file -created with Word- displayed in a RTB control. Whenever I
change the font type during the runtime by selecting a font name from a
combobox -of all system fonts, the text changes its font correctly but I
loose some formatting such as a bold text and/or titles become normal text.
Is there any way of changing the font type/name without touching the
formatting of the text (e.g. a title of 15pts will still be the same but
only its fontname will change). So the users of the app, have only access to
change the font type not the font size..

Thanks,
--
Cengiz Ulku
ce*****@bluewin.ch
Jul 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> I know now how to change the font name of a RTF file in a RTB control
using,
for example:
RTextBox1.SelFontName = cmbFonts.Text

I have a RTF file -created with Word- displayed in a RTB control. Whenever I change the font type during the runtime by selecting a font name from a
combobox -of all system fonts, the text changes its font correctly but I
loose some formatting such as a bold text and/or titles become normal text. Is there any way of changing the font type/name without touching the
formatting of the text (e.g. a title of 15pts will still be the same but
only its fontname will change). So the users of the app, have only access to change the font type not the font size..


I just tried this (after changing the default control names to match yours)

Private Sub Command1_Click()
RTextBox1.SelFontName = cmbFonts.Text
End Sub

Private Sub Form_Load()
For X = 0 To 100
cmbFonts.AddItem Screen.Fonts(X)
Next
End Sub

on a RTF that I produced in Word a couple of years ago that has different
font sizes, italics and bolds in it. All of that formatting was preserved no
matter what I highlighted before clicking the button... even when the
highlight included only part of the bold title, all of the italic sub-title
and part of the normal body text. Do you have any other code being activated
besides the font change that might be getting in the way?

Rick - MVP
Jul 17 '05 #2

P: n/a
I think you can do that using SendMessage with
EM_SETCHARFORMAT.
There's a CHARFORMAT structure you send in with
your new format values, and a dwMask parameter that's
used to indicate which of your CHARFORMAT values are
relevant. If the mask includes only font name then the rest
should be left alone.

--
--
Cengiz Ulku <ce*****@bluewin.ch> wrote in message
news:3f**********@news.bluewin.ch...
Hi all,

I know now how to change the font name of a RTF file in a RTB control using, for example:
RTextBox1.SelFontName = cmbFonts.Text

I have a RTF file -created with Word- displayed in a RTB control. Whenever I change the font type during the runtime by selecting a font name from a
combobox -of all system fonts, the text changes its font correctly but I
loose some formatting such as a bold text and/or titles become normal text. Is there any way of changing the font type/name without touching the
formatting of the text (e.g. a title of 15pts will still be the same but
only its fontname will change). So the users of the app, have only access to change the font type not the font size..

Thanks,
--
Cengiz Ulku
ce*****@bluewin.ch

Jul 17 '05 #3

P: n/a
Ok I found what was wrong !!

What I used in my code was:

RTextBox1.Font.Name = cmbFonts.Text

So this causes a total formatting, with a default font size, I think... When
I try with SeLFontName it works!

Thanks for your help,

--
Cengiz Ulku
cengizu at bluewin.ch


"Cengiz Ulku" <ce*****@bluewin.ch> wrote in message
news:3f**********@news.bluewin.ch...
Hi all,

I know now how to change the font name of a RTF file in a RTB control using, for example:
RTextBox1.SelFontName = cmbFonts.Text

I have a RTF file -created with Word- displayed in a RTB control. Whenever I change the font type during the runtime by selecting a font name from a
combobox -of all system fonts, the text changes its font correctly but I
loose some formatting such as a bold text and/or titles become normal text. Is there any way of changing the font type/name without touching the
formatting of the text (e.g. a title of 15pts will still be the same but
only its fontname will change). So the users of the app, have only access to change the font type not the font size..

Thanks,
--
Cengiz Ulku
ce*****@bluewin.ch

Jul 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.