- 1). Create a new project by selecting "Create New Project" from the "File" menu. Name it whatever you like and use the default options for any dialog boxes that Visual Basic presents to you. When you have finished, you should be staring at a blank window in the Visual Basic GUI design interface.
- 2). Find the RichTextBox component in the control list on the left-hand side of the screen, and drag it into your application window.
- 3). Find the Button component from the control list and drag it into your application window as well. Go to the properties list on the bottom right of the screen, and change the text property of this button to "Strip RTF."
- 4). Double-click the button. This will move you out of the GUI design interface and to the source code editor. It will also declare a function automatically for you that will be called whenever the button is pressed by a user.
- 5). Insert the following code into the button click function:
Private Sub Button1_Click(ByVal sender As System.Object, ByValue As System.EventArgs) Handles Button1.Click
RichTextBox1.Rtf = {\rtf1\ansi\deff0{\colortbl;red0\green0\blue0;\red255\green0\blue0;}This line is the default color\line\cf2This line is red\line\cf1This line is the default color}
String plaintext = RichTextBox1.Text
End Sub
Going line by line, this will place some RTF formatted text into the RichTextBox. It will then place the text, with its formatting stripped, into a string named plaintext. From there, you can do with it what you like.
SHARE