Library tutorials & articles

Rich Text Box Controls

Colors, bullets & superscript

First there's coloring.  You set this by changing the SelColor to the color of your choice.  You can use any color (vbcolor, RGB, QBColors).

Object.SelColor = color

RichTextBox1.SelColor = vbGreen
'Now anything typed will be green

Now protecting.  Protecting disabled editing from the selected text

Object.SelProtected

RichTextBox1.SelProtected = True

Any text that was selected during this method is now protected.

Bullets are creating by setting the SelBullet property to true.  This creates bullets where new lines are put, and the line the cursor was just at.

Object.SelBullets = True

'RichTextBox displays:
'We are know for:
'Creating programs
RichTextBox.SelBullets = True
'RichTexBox now displays
'We are know for:
'·Creating programs

With the bullets you can indent them using BulletIndent

Object.BulletIndent = Integer

'Using the one before
'RichTextBox1 displays:
'We are know for:
'·Creating programs
RichTextBox1.BulletIndent = 200
'RichTextBox1 no displays:
'We are know for:
'·       Creating programs

Next is how to superscript or subscript. To make superscript or subscript you have to use the SelCharOffSet and SelFontSize at the same time.  The SelCharOffSet just changes the position of the text.  

Using the SelCharOffSet property:

Object.SelCharOffSet property

   To subscript, you just need to change the SelFontSize.  If you want to superscript, you must change the font size and the SelCharOffSet.
Hello
SubScript:

Dim VariableName As Integer
Integer = Object.SelFontSize
Object.SelFontSize = Integer / 3 * 2
'This makes the size 2/3 of the original

SuperScript:

Dim VariableName As Integer
Object.SelFontSize = Integer / 3 * 2
Object.SelCharOffSet = Temp * 5

That is how you can make a subscript or superscript font.  They covers most of the control on the rich textbox.

Comments

  1. 22 Jul 2009 at 02:01

    hmm...anyone know how to code the button "aligement left" , so that when the button is clicked , the text in the richtextbox is align to the left...anyone can help? ~.^

  2. 17 Oct 2005 at 08:16

    hi redstar...


    m also facing same problem.. do u got any solution?


    with regards,


    kailas

  3. 21 Apr 2005 at 09:05

    how to get arrow intendation

  4. 21 Apr 2005 at 09:04

    how to chane the bullet intend as arrow

  5. 03 Feb 2005 at 00:34

    I am wondering if thier is a way to save and load text formatting using VB6, for example fonts, text colors etc. Does anybody know any easy ways round it???

  6. 26 Aug 2003 at 19:59

    Try the following code as work around:


    ' flag the section with bullet mark
    rtfSectionText.SelBullet = True


    ' replace bullet with numbers
    rtfSectionText.SelRTF = Replace(rtfSectionText.SelRTF, "\pnlvlblt", "\pndec", 1, -1, vbTextCompare)


    I found som rtf documentation on the Microsoft site:
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnrtfspec/html/rtfspec_16.asp


    Hope it helps

  7. 26 Jul 2003 at 06:00

    Bulleted indenting is fine.
    But how to get number indentation?
    Is there any way?
    thank you

  8. 09 Dec 2002 at 03:07

    How to make subscripts and superscripts in DHTML editor using c#?

  9. 29 Sep 2002 at 15:05

    Hi,


    I am having problems in sending selected text to a rich text box control without selecting the text at runtime e.g. at runtime the rich text box contains the text "Selection" and when a command button is pressed the following text in BOLD is appended to the current text "IS EASY"


    Selection IS EASY

  10. 21 Sep 2002 at 13:49
    There are in the world some control that let me justify the text like word?

    (I know that this cannot).
  11. 21 Sep 2002 at 13:45
    How can a Rich Text control justify completely a paragraph?
  12. 15 Sep 2002 at 15:32

    I use the rich text box and insert in it the mschart object, but i can not refer to mschart property and metods with OLEOBJECTS.
    help me pleas, help.

  13. 10 Sep 2002 at 11:57

    0 = rtf
    1 = text

  14. 26 Aug 2002 at 13:56
    Actually in the subscribe fo not use * because * 0 is 0 and will not have any effect. It is better to use +200 (approximetly) to have the result you want...
  15. 19 Aug 2002 at 11:19
    how ca i possiblly pasted any copied cell from .xls
  16. 08 Aug 2002 at 05:41

    Hi,


    i am working with richtextbox quite a lot of time, but i am still wondering how can i input a picture in it. Also i have the point that i ignore  some of his opportunities. So i would be glad if you could write something about them. Thank you on advance

  17. 09 Jul 2002 at 01:47
    Have you tried the Multiline property?
  18. 03 Jul 2002 at 21:40
    K, first off. Right away you mension:

    Object.Save (FilePath, FileType)

    WHAT FILETYPES? Can it save in RTF, Text, and what are the corresponding numbers?????????????

    Secondly, I am sure that in EVERY rich text editor I have ever used, you can set different indents for different paragraphs. Yet you do not mension how to align a paragraph... "is just like setting the alignment for a whole textbox."

    Aside from that it was pretty good, but can't you also do Horizontal Rules in Rich Text? I know no-one normally does, but if ya can . . .

    Thanks for the info though, I was always confused about the select stuff.
  19. 26 May 2002 at 13:22

    Hello KillerSheep,


    Is this what you're looking for:


    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    Option Explicit


    Public Const WMUSER = &H400
    Private Const EM
    SETTARGETDEVICE = (WM_USER + 72)


    Public Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal LParam As Long) As Long


    Public Enum ViewModes
       Default = 0
       WordWrap = 1
       WYSIWYG = 2
    End Enum


    Const EMFORMATRANGE As Long = WMUSER + 57


    '** Set View Mode
    Public Sub SetViewMode(ByVal ViewMode As ViewModes)
       Select Case ViewMode 'Set View Mode
           Case 0 'No Wrap
               SendMessageLong rtfText.hWnd, EMSETTARGETDEVICE, 0, 1
           Case 1 'Word Wrap
               SendMessageLong rtfText.hWnd, EM
    SETTARGETDEVICE, 0, 0
           Case 2 'WYSIWYG
               On Error Resume Next
               SendMessageLong rtfText.hWnd, EM_SETTARGETDEVICE, Printer.hdc, Printer.Width
      End Select
    End Sub


    '@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@


    By

  20. 20 May 2002 at 07:39
    Thanks for taking the trouble to reply, man.
    Thanks a lot!
    Now, where can I find the soln for this?
    Quote:
    [1]Posted by phracker76 on 18 May 2002 07:38 PM[/1]
    VB has no bulit in functions or constants for what you want, im not gonna be much help here sorry!




  21. 18 May 2002 at 19:38
    VB has no bulit in functions or constants for what you want, im not gonna be much help here sorry!

  22. 18 May 2002 at 19:20
    What I want is to present the text in a justified manner.
    Not left, right or center.

    Justified as in MS Word. ie, both left and right ends are aligned.
  23. 18 May 2002 at 17:41
    By justify im assuming you meen Right, Left and Center. You need to use the

    Code:
    object.SelAlignment


    and one of the following;


    1. vbLeftJustify
    2. vbRightJustify
    3. vbCenter


    for example;

    RichTextBox1.SelAlignment = vbCenter

    or

    RichTextBox1.SelAlignment = vbLeftJustify

    Hope thats some help;

    Luke

  24. 05 May 2002 at 13:40

    When printing Rich Textbox text it seems to disregard the Current X/Y command.  What gives>

  25. 25 Apr 2002 at 00:36
    Hi!,
    Could you tell me how to display the text in Justified manner in a RT Box?
    I've tried just about everything (other than writing a new control )
    Tx and Regards
  26. 24 Apr 2002 at 06:04

    one thing you forgot - How do you toggle line wrapping on and off?!


    hee hee thanks

  27. 25 Feb 2002 at 23:43
    Let me try the option u have mentioned , but will it work with vb.net need to be checked.

    There is no option of
    Richtextbox1.selprint(Printer.hdc) in vb.net that is only in VB6.

    Thanks
  28. 25 Feb 2002 at 16:37
    Private Sub mnuPrintItem_Click()
       'Prints the current document using the device
       'handle of the current printer
       RichTextBox1.SelPrint (Printer.hDC)
    End Sub
  29. 25 Feb 2002 at 00:40
    Can you help me out in printing the formated text in richtextbox.
  30. 01 Jan 1999 at 00:00

    This thread is for discussions of Rich Text Box Controls.

Leave a comment

Sign in or Join us (it's free).

 ZERO-COOL I'm a 12 year old child who is interested in learning programming languages. My current two are Visual Basic and C++.

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback