Solved

Resetting RichTextBox after loading RTF

Posted on 1998-09-28
4
160 Views
Last Modified: 2010-04-30
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.

0
Comment
Question by:happysam
  • 2
4 Comments
 
LVL 14

Expert Comment

by:waty
ID: 1437038
do :
richtextbox1.TextRtf = "" 
0
 
LVL 3

Expert Comment

by:HATCHET
ID: 1437039
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
0
 

Author Comment

by:happysam
ID: 1437040
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
0
 
LVL 3

Accepted Solution

by:
HATCHET earned 30 total points
ID: 1437041
happysam,

Thank You.    =)     <Takes a bow...>
How about a few points?   ; P
Take Care,


HATCHET
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 91
Copy a row 12 64
SQL VB connection works in one PC and doesn't in another 15 68
MS Access 03, TransferText, decimal places 8 78
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question