RichTextBox with Text Alignment in VB6

In this article, we will create a program that can open a RichTextBox and manipulate its alignment such as Left, Center, and Right. RichTextBox allows the user to enter and edit text while providing more advanced formatting features than the standard TextBox control. Text can be assigned directly to the control, or can be loaded from a rich text format (RTF) or plain text file. Now, let's start this tutorial! 1.Let's start this tutorial by following the following steps in Microsoft Visual Basic 6.0: Open Microsoft Visual Basic 6.0, click Choose Standard EXE, and click Open. 2.Go to Project Tab, and Click Components or Press Ctrl+T. components 3. In the Controls Tab, find and check Microsoft Rich TextBox Control 6.0. Click apply and then click OK. control 4. Next, insert two Buttons named cmdSearch labeled it as "Left",Command2 labeled it as "Center", and Command3 labeled it as "Right". Add also RichTextBox namedRich TextBox1 from the component. You must design your interface like this: design 5.Now put this code for your code module.
  1. Private Sub Command1_Click()
  2. RichTextBox1.SelAlignment = rtfLeft
  3. End Sub
  4. Private Sub Command2_Click()
  5. RichTextBox1.SelAlignment = rtfCenter
  6. End Sub
  7. Private Sub Command3_Click()
  8. RichTextBox1.SelAlignment = rtfRight
  9. End Sub

Explanation:

Button1 is used for the Left alignment, Button2 for Center Alignment, and Button3 for Right Alignment. The SelAlignment property of a RichTextBox returns a selected alignment of either left, center or right. rtfLeft will go to the text’s left alignment, rtfCenter will go to the text’s center alignment, rtfRight will go to the text’s right alignment, respectively.

Output:

outputoutput Download the source code below and try it! :) For more inquiries just contact my number or e-mail below. Best Regards, Engr. Lyndon R. Bermoy IT Instructor/System Developer/Android Developer Mobile: 09488225971 Telephone: 826-9296 E-mail:[email protected] Follow and add me in my Facebook Account: https://www.facebook.com/donzzsky

Add new comment