• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

How do I write a file in RTF format using Visual Basic 2008?

I am currently developing a program using the Visual Basic component of Visual Studio 2008.

I have to produce a file in rich text format so as not to restrict it to a particular word processor such as MS Word. However, I have never done this before and have no idea how I write the file in RTF.

Can someone either describe the process or point me to some website where I can get something more descriptive than I have been able to find on the Microsoft website which, as usual, assumes a lot of knowledge?

(Normally I would have used C++ since I am much more experienced in that language but the task requires me to use VB where my experience is intermediate.)

0
jindalee
Asked:
jindalee
  • 2
  • 2
1 Solution
 
jpaulinoCommented:
Hi,
You just need to use a richtextbox control and then save as rtf like this:

Me.RichTextBox1.SaveFile("c:\myFile.rtf")

Open in new window

0
 
jindaleeAuthor Commented:
I guess then that if I want, for example, to have some text bolded, different font etc, I have to write the code to do the bolding etc and the SaveFile method does the rest?
0
 
jpaulinoCommented:
Yes, that's it! You just need to add the format you want to the text and save it as a rtf file.
Something like:
' bold the selection with size 12, font Arial
Me.RichTextBox1.SelectionFont = New Font("Arial", 12, FontStyle.Bold)  
and then save it
0
 
jindaleeAuthor Commented:
Thank you!

I thought that the solution would be pretty simple but couldn't see it for looking. I've already checked out your suggestion and it worked first time.
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now