happysam
asked on
Resetting RichTextBox after loading RTF
Dear Guys (and Gals),
I have one question which might sound simple to you but I still can't find the solution to it.
I have got a rich text box which will load a RTF file from local drive. After which the user can also choose to clear it and type in their own message. However, I realised that even if I do a
richtextbox1.text = ""
The previous settings for the fonts and the colors still stay in the box. This is really annoying as if the previous document contains underline and say green color for example, I won't be able to clear that for the user. Can I do a select everything in the richtextbox1 and then set the selcolor, selbold, selfontname etc to something I like?
I find that as richtextbix do not have a Forecolor property I cannot change its color unless I select all the text in the rich text box.
If it is not too much to ask, can you please kindly shed some light on this matter?
Thanks a million.
I have one question which might sound simple to you but I still can't find the solution to it.
I have got a rich text box which will load a RTF file from local drive. After which the user can also choose to clear it and type in their own message. However, I realised that even if I do a
richtextbox1.text = ""
The previous settings for the fonts and the colors still stay in the box. This is really annoying as if the previous document contains underline and say green color for example, I won't be able to clear that for the user. Can I do a select everything in the richtextbox1 and then set the selcolor, selbold, selfontname etc to something I like?
I find that as richtextbix do not have a Forecolor property I cannot change its color unless I select all the text in the rich text box.
If it is not too much to ask, can you please kindly shed some light on this matter?
Thanks a million.
happysam,
waty's answer will leave some of the fonts and fontstyles in place which is what you're trying to fix. Use the following code instead. It will change everything back to the default fonts.
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
RichTextBox1.SelBold = False
RichTextBox1.SelItalic = False
RichTextBox1.SelUnderline = False
RichTextBox1.SelColor = &H0&
RichTextBox1.SelFontName = "MS Sans Serif"
RichTextBox1.SelFontSize = 8
RichTextBox1.Text = ""
HATCHET
waty's answer will leave some of the fonts and fontstyles in place which is what you're trying to fix. Use the following code instead. It will change everything back to the default fonts.
RichTextBox1.SelStart = 0
RichTextBox1.SelLength = Len(RichTextBox1.Text)
RichTextBox1.SelBold = False
RichTextBox1.SelItalic = False
RichTextBox1.SelUnderline = False
RichTextBox1.SelColor = &H0&
RichTextBox1.SelFontName = "MS Sans Serif"
RichTextBox1.SelFontSize = 8
RichTextBox1.Text = ""
HATCHET
ASKER
Dear HATCHET,
It works! It really works! Such a simple solution yet I was trying it out for 2 days! Simple yet elegent!
Thanks a lot HATCHET! :)
Regards,
Happy
It works! It really works! Such a simple solution yet I was trying it out for 2 days! Simple yet elegent!
Thanks a lot HATCHET! :)
Regards,
Happy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
richtextbox1.TextRtf = ""