dcsimg
Results 1 to 23 of 23

Thread: [Resolved] RTB paragraph indents

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    151

    Resolved [Resolved] RTB paragraph indents

    I posted this about an hour ago but it's not showing. Maybe my session timed out?
    So I apologize if this is a double-up.

    I have a questionnaire type program with multiple choice answers. Similar to a driver's test or quiz show.
    The questions are grouped into categories which are stored in an MS Access database along with four optional answers to each question.
    The app has a preview function similar to that of a print preview.
    The RTB preview is populated by the (R.S.Fields) question categories and answers that the user has chosen.

    I use the following to indent the answers.
    Code:
    RTB.SelIndent = (RTB.SelIndent + 400)
    My program loops through all answers and neatly places the question categories to the left of RTB and the selected answers are indented on a new line below each other.

    For the most part it looks great.
    However this only works correctly with the first line of each answer.
    Short answers work great but some answers are small paragraphs. They start off indented but then continue onto the next line from the left hand edge of the RTB, totally ignoring the Selindent.

    I have spent the whole day searching for the solution and I believe that "RTB.SelRightIndent" and "RTB.SelHangingIndent" may be what I need although I haven't found examples of how they are implemented at run time except maybe to load from an exiting RTF file.
    I need it to work with Access table fields, "on the fly".

    I am using "Microsoft Rich Textbox Control 6 (sp3)"

    Any help in this matter would be greatly appreciated. Cheers.

    Also if possible I'd like the listed categories to be bold and or underlined, but not the answers. Thanks.
    Last edited by AccadaccA; May 16th, 2019 at 08:15 PM. Reason: Resolved
    I rely heavily on trial and error, mostly only succeeding in the latter.

  2. #2
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,788

    Re: RTB paragraph indents

    You need to select the text that you want to indent. Use the properties SetStart and SelLenght for making the selection.

    All the properties that start with "Sel" are applied to the text that is currently selected.

  3. #3
    PowerPoster Elroy's Avatar
    Join Date
    Jun 2014
    Location
    Near Nashville TN
    Posts
    5,663

    Re: RTB paragraph indents

    Also, I sometimes do this stuff by massaging the actual RTF text. I believe pretty much anything from Write/Wordpad will paste into the RTB. That would allow you to study the RTF text for various features.

    That's sort of the hard way, but offers all the RTF options of the RTB.

    Good luck,
    Elroy
    Any software I post in these forums written by me is provided “AS IS” without warranty of any kind, expressed or implied, and permission is hereby granted, free of charge and without restriction, to any person obtaining a copy. Please understand that I’ve been programming since the mid-1970s and still have some of that code. My contemporary VB6 project is approaching 1,000 modules. In addition, I have a “VB6 random code folder” that is overflowing. I’ve been at this long enough to truly not know with absolute certainty from whence every single line of my code has come, with much of it coming from programmers under my employ who signed intellectual property transfers. I have not deliberately attempted to remove any licenses and/or attributions from any software. If someone finds that I have inadvertently done so, I sincerely apologize, and, upon notice and reasonable proof, will re-attach those licenses and/or attributions. To all, peace and happiness.

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    151

    Re: RTB paragraph indents

    Quote Originally Posted by Eduardo- View Post
    You need to select the text that you want to indent. Use the properties SetStart and SelLenght for making the selection.

    All the properties that start with "Sel" are applied to the text that is currently selected.
    Yeah that's the problem, mate. The RTB isn't shown until after it's populated and the user input is random.
    I need to be sitting on the user's lap to select the text options they've chosen. lol

    For the bold categories I have tried ...

    Code:
    RTB.Selstart = Len(RTB.text)
    RTB.text = RTB.Text & txtCategory.Text
    RTB.SelLength = Len(txtCategory)
    But it makes the entire preview bold. Even when I add "RTB.SelBold = False" or "RTB.SelBold = Not RTB.SelBold" after it.
    Thank you.


    Quote Originally Posted by Elroy View Post
    Also, I sometimes do this stuff by massaging the actual RTF text. I believe pretty much anything from Write/Wordpad will paste into the RTB. That would allow you to study the RTF text for various features.

    That's sort of the hard way, but offers all the RTF options of the RTB.

    Good luck,
    Elroy
    Cheers mate, I'm guessing "Write/Wordpad" is some sort of feature I haven't heard about yet. I saw it written like that "Write/Wordpad" in my searches yesterday and couldn't understand what the post meant. If I find out it's a built-in feature of vb6 I'll bloody scream my neighborhood down and kick myself so hard that you will feel the shock-wave from it. lol

    Ahhhh, a new day, a new 12 hour web search. Yippee!
    I rely heavily on trial and error, mostly only succeeding in the latter.

  5. #5
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    790

    Re: RTB paragraph indents

    Wordpad is a free, fairly basic word processing program that has been bundled with Windows since Windows 95.

    Write is the Wordpad predecessor that was bundled with Windows 3.x.

    I believe Write.exe was still bundled with all Windows versions after 3.x for a while (possibly still is in Windows 10), but it would simply launch Wordpad when executed.

  6. #6
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,788

    Re: RTB paragraph indents

    Quote Originally Posted by AccadaccA View Post
    Yeah that's the problem, mate. The RTB isn't shown until after it's populated and the user input is random.
    I need to be sitting on the user's lap to select the text options they've chosen. lol
    Who writes the text RTB, you (by code, even based on the user input) or the user (by typing)?

    If it is you, it is on your hands how to format it.

    Quote Originally Posted by AccadaccA View Post
    For the bold categories I have tried ...

    Code:
    RTB.Selstart = Len(RTB.text)
    RTB.text = RTB.Text & txtCategory.Text
    RTB.SelLength = Len(txtCategory)
    But it makes the entire preview bold.
    There are two parameters:

    SelStart: defines the start of the selection, if it is 10, it will select from the 10th character and ahead.

    SelLenght: defines the length of the selection, if it is 15, if will select only 15 characters from the start (from SelStart).

    After that, any formatting applied by the properties that start with Sel* (like SelBold, SelItalic, Etc.) will be applied to the selection only.

    Every time that you change the RTB.text, the start of the selection (SelStart) is reset to 0, and the length of the selection (SelLength) also to 0.

    Then, now knowing that, what's does your code do?:

    Quote Originally Posted by AccadaccA View Post
    Code:
    RTB.Selstart = Len(RTB.text) ' puts the start of the selection at the end of the text, nothing useful
    RTB.text = RTB.Text & txtCategory.Text ' changes the text and resets SelStart to 0 and SelLength to 0
    RTB.SelLength = Len(txtCategory) ' Sets SelLenght to the character count of the text, and since SelStart is in 0, it selects all the text of the control. Whatever Sel* property applied now, it will be applied to all the text
    Quote Originally Posted by AccadaccA View Post
    Even when I add "RTB.SelBold = False" or "RTB.SelBold = Not RTB.SelBold" after it.
    Thank you.
    If you didn't change the text or the selection, it should switch Bold on and off.
    But I would not rely on the return value of Sel* properties (like SelBold).
    Set it to True or False, not to "Not SelBold". Or use variables instead.

    Quote Originally Posted by AccadaccA View Post
    Ahhhh, a new day, a new 12 hour web search. Yippee!
    You just need you understand how the RichTextBox control works.

    Here there is a page that teaches about it.

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    151

    Re: RTB paragraph indents

    OptionBase1: Thank you for clarifying that.
    I do know what Wordpad is but seeing it written as "Write/Wordpad" made me think it could be something else.
    I was not aware of the "Write.exe".

    Cheers


    Quote Originally Posted by Eduardo- View Post
    Who writes the text RTB, you (by code, even based on the user input) or the user (by typing)?

    If it is you, it is on your hands how to format it.


    There are two parameters:

    SelStart: defines the start of the selection, if it is 10, it will select from the 10th character and ahead.

    SelLenght: defines the length of the selection, if it is 15, if will select only 15 characters from the start (from SelStart).

    After that, any formatting applied by the properties that start with Sel* (like SelBold, SelItalic, Etc.) will be applied to the selection only.

    Every time that you change the RTB.text, the start of the selection (SelStart) is reset to 0, and the length of the selection (SelLength) also to 0.
    Thank you but I do understand that and have made a couple of WordPad type text editors.
    This is different to just throwing a couple of toolbar buttons in and telling the user to go for it.

    I did ponder on your statement that "RTB.Selstart = Len(RTB.text) ' puts the start of the selection at the end of the text, nothing useful"

    So I inserted the txtCategory.Text first then wrote RTB.Selstart = Len(RTB.text) - Len(txtCategory) then I added RTB.SelLength = Len(txtCategory).
    I tried the "RTB.SelBold = True" after those lines then tried it again between them but neither position worked.


    Quote Originally Posted by Eduardo- View Post
    Then, now knowing that, what's does your code do?:
    If you didn't change the text or the selection, it should switch Bold on and off.
    Because it is part of a loop more text is inserted after the category, the indented answers, so it made no difference. I either get the entire preview RTB in bold or none of it is bold.

    Quote Originally Posted by Eduardo- View Post
    But I would not rely on the return value of Sel* properties (like SelBold).
    Set it to True or False, not to "Not SelBold". Or use variables instead.
    Thank you, I took your advice and will keep it either "True" or "False".

    My main focus is the indent. It would be nice to have the bold category titles but they're just icing on the cake.

    Quote Originally Posted by Eduardo- View Post
    You just need you understand how the RichTextBox control works.

    Here there is a page that teaches about it.
    Thanks for the link. I actually saved that page during my search yesterday before posting here and I downloaded the sample "RTF Pad" which fails to start if you haven't got a printer connected.
    Another thing is that it doesn't have the indent / outdent option and that is looks nothing like the screenshot. (Maybe the exe looks like that but the open source code version doesn't).

    Just for kicks I copied my preview text and pasted it into "RTF Pad". Although it was maximized to full screen the formatting looked worse than what I have.
    It has a feature to switch to plain text which resembled my preview. It still can't handle longer sentences or paragraphs without starting the new line from the left border.
    The Bullet function doesn't indent the text either, even when highlighted. It just adds the bullet image against the left border.
    I rely heavily on trial and error, mostly only succeeding in the latter.

  8. #8
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,788

    Re: RTB paragraph indents

    Ok, lets start with the Bold feature. The indent is similar.

    What you are trying to do, is this. Test in a new project, with a RichTextBox control named rtb1:

    Code:
        Dim t As String
        Dim iPos As Long
        
        rtb1.Text = "Some text: SelStart: defines the start of the selection, if it is 10, it will select from the 10th character and ahead." & vbCrLf & "SelLenght: defines the length of the selection, if it is 15, if will select only 15 characters from the start (from SelStart)." & vbCrLf
        
        t = "text to add at the end"
        
        iPos = Len(rtb1.Text)
        rtb1.SelStart = iPos
        rtb1.SelText = t
        rtb1.SelStart = iPos
        rtb1.SelLength = Len(t)
        rtb1.SelBold = True
        rtb1.SelStart = 0

    But a better option would be:

    Code:
        Dim t As String
        Dim iPos As Long
        
        rtb1.Text = "Some text: SelStart: defines the start of the selection, if it is 10, it will select from the 10th character and ahead." & vbCrLf & "SelLenght: defines the length of the selection, if it is 15, if will select only 15 characters from the start (from SelStart)." & vbCrLf
        
        t = "text to add at the end"
        
        rtb1.SelStart = Len(rtb1.Text) ' puts the insertion point at bthe end
        rtb1.SelBold = True ' new text added with SelText will be bold
        rtb1.SelText = t ' add new text
    PS: about the "nothing useful" sorry, perhaps I misunderstood what you were trying to do.

    Another thing to take into account is that when the SelLength is 0, the SelStart is the insertion point, and you can change the formatting with the properties named Sel* (for instance SelBold), and even when there is no text in the selection, the new text that can be added asigning something to SelText will have that formatting.
    If the SelStart (the insertion point) is at the end [= Len (RTB.text)], you can add text with .SelText = "text" and it will appear with the current formatting set by the Sel* properties.
    Last edited by Eduardo-; May 15th, 2019 at 11:12 PM.

  9. #9
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,788

    Re: RTB paragraph indents

    For the indentation:

    Code:
        rtb1.Text = "afeswdtgas dfsa dmsrgda fghet hdeashgrs " & vbCrLf & "vgsgef raestgfw reyhgeetg watyg esw" & vbCrLf
        rtb1.SelStart = Len(rtb1.Text)
        rtb1.SelIndent = 400
        rtb1.SelText = "New indented line (1)" & vbCrLf
        rtb1.SelText = "New indented line (2)" & vbCrLf
        rtb1.SelText = "New indented line (3)" & vbCrLf

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    151

    Re: RTB paragraph indents

    Quote Originally Posted by Eduardo- View Post
    PS: about the "nothing useful" sorry, perhaps I misunderstood what you were trying to do.
    No need to apologize mate, you made me sit back and give it a good look.

    Quote Originally Posted by Eduardo- View Post
    Another thing to take into account is that when the SelLength is 0, the SelStart is the insertion point, and you can change the formatting with the properties named Sel* (for instance SelBold), and even when there is no text in the selection, the new text that can be added asigning something to SelText will have that formatting.
    If the SelStart (the insertion point) is at the end [= Len (RTB.text)], you can add text with .SelText = "text" and it will appear with the current formatting set by the Sel* properties.
    Cheers mate, I'll keep that in mind.

    I came with some good news but I'll give your examples a try after this post. Thank you.

    I managed to get some positive results, even adding the event title to the center, making it bold, adding the date beside that (not bold) adding two lines then finally added a category in bold to the left.

    Code:
        RTB.Text = lblEventName.Caption & " - " & Format$(Date, "dd/mm/yy")
        RTB.Text = RTB.Text & vbCrLf & vbCrLf
        RTB.Text = RTB.Text & lblTempCategory.Caption
        RTB.SelStart = 0
        RTB.SelLength = Len(lblEventName.Caption)
        RTB.SelAlignment = rtfCenter
        RTB.SelStart = 0
        RTB.SelLength = Len(lblEventName.Caption)
        RTB.SelBold = True
        RTB.SelStart = Len(RTB.Text) - Len(lblTempCategory.Caption)
        RTB.SelLength = Len(lblTempCategory.Caption)
        RTB.SelBold = True
    The only downfall is that when adding another line "RTB.Text = RTB.Text & vbCrLf" after that it all goes to hell in a hand basket. lol
    So I was thinking to save that as an RTF file then close and reopening it to add the indent user-defined options/answers.
    But it's a lot of friggin' 'round to open and close the rtf file with each category.

    Like I said, I'll give your example a try.... after tea.

    Thank you.
    I rely heavily on trial and error, mostly only succeeding in the latter.

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    151

    Re: RTB paragraph indents

    Eduardo
    Okay I created a new project and added a RTB and three command buttons.

    Command1 click event is your first "bold" example.
    Command2 click event is your second "bold" example.
    Command3 click event is your "indent" example.

    All three work great "as is" but as soon as I add a new line..

    Code:
    rtb1.Text = rtb1.Text & vbCrLf & "Adding more to the rtb1.text just to test stuff."
    ... it all goes back to plain text and it's aligned on the left.

    Thank you for your time and efforts all the same. Much appreciated.
    I rely heavily on trial and error, mostly only succeeding in the latter.

  12. #12
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    3,556

    Re: RTB paragraph indents

    If you set the .Text property then everything is reset. Because it's the unformatted text.

    Try this:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
      RichTextBox1.Text = ""
    End Sub
    
    Private Sub Command1_Click()
      Dim lStartPos As Long
      lStartPos = Len(RichTextBox1.Text)
      RichTextBox1.SelStart = lStartPos
      If lStartPos = 0 Then
        RichTextBox1.SelText = "First line"
      Else
        RichTextBox1.SelText = vbLf & "Next line"
      End If
    End Sub
    
    Private Sub Command2_Click()
      RichTextBox1.SelIndent = RichTextBox1.SelIndent + 400
    End Sub
    
    Private Sub Command3_Click()
      RichTextBox1.SelIndent = RichTextBox1.SelIndent - 400
    End Sub

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    151

    Re: RTB paragraph indents

    Okay I've got even closer to the desired result.

    I just done away with all of the formatting except the new lines.
    Then after it looped through all of the categories and selected options (answers) I started the formatting.

    Code:
        RTB.SelStart = 0
        RTB.SelLength = Len(lblEventName.Caption)
        RTB.SelBold = True
        RTB.SelStart = 0
        RTB.SelLength = Len(lblEventName.Caption)
        RTB.SelAlignment = rtfCenter
        For i = 0 To lstCategories.ListCount - 1
        Compare = 0
        Pos = InStr(Pos + 1, RTB.Text, lstCategories.List(i), Compare)
        If Pos > 0 Then
        RTB.SelStart = Pos - 1
        RTB.SelLength = Len(lstCategories.List(i))
        RTB.SelBold = True
        End If
        Next i
        picPreview.Left = 0
        picPreview.Top = 0
        picPreview.Visible = True
    Now I have all but the event title and date aligned to the left.
    Only the event title and all of the categories in bold. Exactly what I wanted.
    This kind of eliminates the need to visually separate category from the user selected options.

    Of course having my cake and eating it too would be perfect but after slogging at this final hurdle for so long I'm relieved to at least have this result.

    Thanks for all of the replies. I can't exactly mark this as "Resolved" as it's not indented.... yet.


    Arnoutdv: What a brilliant idea, mate. Thanks I'll add that to what I have and we should be "home free".

    Much appreciated, one and all.
    I rely heavily on trial and error, mostly only succeeding in the latter.

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    151

    Re: RTB paragraph indents

    Ok, I've done it. Whoohoo!

    First write your desired text just like regular textbox text with new lines, disregarding any rtf formatting.
    In my case it had to loop through 19 categories, between 2 and 4 sub-categories each and up to 3 textboxes full of text per sub-category.

    Then I added as posted above but with a few extra bits.... to make it indented as well. Both when and where I want.

    Code:
    Dim Pos As Variant
    Dim Compare As Integer
    Dim X1 As Long
    
        RTB.SelStart = 0
        RTB.SelLength = Len(lblEventName.Caption)
        RTB.SelBold = True
        RTB.SelStart = 0
        RTB.SelLength = Len(lblEventName.Caption)
        RTB.SelAlignment = rtfCenter
        X1 = Pos ' Grab this position at the end of the center alignment to start the indent.
        RTB.SelStart = X1
        RTB.SelLength = Len(RTB.Text) - Val(X1) ' Set the selected length by subtracting the selStart from the entire text length.
        RTB.SelIndent = RTB.SelIndent + 400
        For i = 0 To lstCategories.ListCount - 1 ' start looping through the categories and the user's selected answers.
        Compare = 0
        Pos = InStr(Pos + 1, RTB.Text, lstCategories.List(i), Compare) ' use the "Find" routine to compare the RTB.text against the list of categories.
        If Pos > 0 Then
        X1 = Pos
        RTB.SelStart = Pos - 1
        RTB.SelLength = Len(lstCategories.List(i))
        RTB.SelBold = True
        RTB.SelStart = X1
        RTB.SelLength = Len(lstCategories.List(i))
        RTB.SelIndent = RTB.SelIndent - 400
        End If
        Next i
        picPreview.Left = 0
        picPreview.Top = 0
        picPreview.Visible = True
    Not bad for a self taught old fart. lol

    Thanks again for all the input.
    I rely heavily on trial and error, mostly only succeeding in the latter.

  15. #15
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,422

    Re: [Resolved] RTB paragraph indents

    RichEdit controls like those wrapped by the RichTextBox and InkEdit ActiveX controls also support the TOM interfaces. If you haven't met TOM yet, you can find the interfaces documented in your MSDN documentation CDs:

    Name:  MSDN sshot.png
Views: 57
Size:  11.5 KB


    These can be more powerful than the exposed properties and methods in the ActiveX controls interfaces for performing some actions. Text Object Model is a lot like the Word Object Model and this isn't an accident.

    Code:
    Option Explicit
    
    Private Const WM_USER As Long = &H400&
    Private Const EM_GETOLEINTERFACE As Long = WM_USER + 60
    
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageW" ( _
        ByVal hWnd As Long, _
        ByVal wMsg As Long, _
        ByVal wParam As Long, _
        ByVal lParam As Long) As Long
    
    Private tdRTB As tom.ITextDocument
    Private SpaceAfter As Single
    Private Lorems() As String
    Private PastFirstPara As Boolean
    Private ParaStyle As Long
    
    Private Sub cmdNextCase_Click()
        Const PARASTYLE_COUNT As Long = 7
        Dim Lorem As String
        Dim LastLineBreak As Long
        Dim IndentWidth As Single
    
        RTB.Locked = False
        Lorem = Lorems(Int(Rnd() * (UBound(Lorems) + 1)))
        LastLineBreak = InStrRev(Lorem, vbNewLine)
        With tdRTB.Selection
            .Move tomStory, 1 'Move to end of story (document text).
            If PastFirstPara Then
                .Text = vbNewLine
                .Move tomStory, 1
            Else
                PastFirstPara = True
            End If
            'Clear settings of this new paragraph:
            With .Para
                .SetIndents 0, 0, 0
                .NoLineNumber = tomTrue
                .ListType = tomListNone
                .SpaceAfter = 0
            End With
            .Font.Bold = tomTrue
            Select Case ParaStyle
                Case 0
                    .Text = "Case 0: Plain paragraph" & vbNewLine
                    .Move tomStory, 1
                    .Font.Bold = tomFalse
                    .Para.SpaceAfter = SpaceAfter
                    .Text = Replace$(Lorem, vbNewLine, " ")
                Case 1
                    .Text = "Case 1: Plain paragraph with indents" & vbNewLine
                    .Move tomStory, 1
                    .Font.Bold = tomFalse
                    With .Para
                        .SpaceAfter = SpaceAfter
                        IndentWidth = ScaleX(0.375, vbInches, vbPoints)
                        .SetIndents 0, IndentWidth, IndentWidth
                    End With
                    .Text = Replace$(Lorem, vbNewLine, "  ")
                Case 2
                    .Text = "Case 2: Plain paragraph with indents including 1st line indent" & vbNewLine
                    .Move tomStory, 1
                    .Font.Bold = tomFalse
                    With .Para
                        .SpaceAfter = SpaceAfter
                        IndentWidth = ScaleX(0.375, vbInches, vbPoints)
                        .SetIndents IndentWidth, IndentWidth, IndentWidth
                    End With
                    .Text = Replace$(Lorem, vbNewLine, "  ")
                Case 3
                    .Text = "Case 3: Plain paragraph with left indent only" & vbNewLine
                    .Move tomStory, 1
                    .Font.Bold = tomFalse
                    With .Para
                        .SpaceAfter = SpaceAfter
                        IndentWidth = ScaleX(0.375, vbInches, vbPoints)
                        .SetIndents 0, IndentWidth, 0
                    End With
                    .Text = Replace$(Lorem, vbNewLine, "  ")
                Case 4
                    .Text = "Case 4: Numbered list" & vbNewLine
                    .Move tomStory, 1
                    .Font.Bold = tomFalse
                    With .Para
                        IndentWidth = ScaleX(0.25, vbInches, vbPoints)
                        .SetIndents -IndentWidth, IndentWidth, 0
                        .NoLineNumber = tomFalse
                        .ListStart = 1
                        .ListType = tomListNumberAsArabic Or tomListPeriod
                    End With
                    If LastLineBreak > 0 Then
                        .Text = Left$(Lorem, LastLineBreak + 1)
                        .Move tomStory, 1
                        .Para.SpaceAfter = SpaceAfter
                        .Text = Mid$(Lorem, LastLineBreak + 2)
                    Else
                        .Para.SpaceAfter = SpaceAfter
                        .Text = Lorem
                    End If
                Case 5
                    .Text = "Case 5: Bulletted list" & vbNewLine
                    .Move tomStory, 1
                    .Font.Bold = tomFalse
                    With .Para
                        IndentWidth = ScaleX(0.25, vbInches, vbPoints)
                        .SetIndents -IndentWidth, IndentWidth, 0
                        .ListType = tomListBullet
                    End With
                    If LastLineBreak > 0 Then
                        .Text = Left$(Lorem, LastLineBreak + 1)
                        .Move tomStory, 1
                        .Para.SpaceAfter = SpaceAfter
                        .Text = Mid$(Lorem, LastLineBreak + 2)
                    Else
                        .Para.SpaceAfter = SpaceAfter
                        .Text = Lorem
                    End If
                Case 6
                    .Text = "Case 6: Paragraph as lines" & vbNewLine
                    .Move tomStory, 1
                    .Font.Bold = tomFalse
                    .Para.SpaceAfter = SpaceAfter
                    .Text = Replace$(Lorem, vbNewLine, vbVerticalTab)
            End Select
            .ScrollIntoView tomEnd
        End With
        RTB.Locked = True
        ParaStyle = (ParaStyle + 1) Mod PARASTYLE_COUNT
    End Sub
    
    Private Sub Form_Load()
        Dim IUnknown As stdole.IUnknown
    
        SendMessage RTB.hWnd, EM_GETOLEINTERFACE, 0, VarPtr(IUnknown)
        Set tdRTB = IUnknown
        SpaceAfter = ScaleY(TextHeight("Wj"), ScaleMode, vbPoints)
        Lorems = Split(StrConv(LoadResData("LOREM", "ANSI"), vbUnicode), vbNewLine & vbNewLine)
    End Sub
    
    Private Sub Form_Resize()
        If WindowState <> vbMinimized Then
            With RTB
                .Move 0, .Top, ScaleWidth, ScaleHeight - .Top
            End With
        End If
    End Sub
    Name:  sshot.png
Views: 59
Size:  8.0 KB


    Even after two decades this still doesn't appear to be very well known to VB6 programmers. This seems odd since so many got their start writing VBA macros for MS Office applications.

    In any case TOM is one more tool in our toolbox.
    Attached Files Attached Files

  16. #16
    Frenzied Member wqweto's Avatar
    Join Date
    May 2011
    Posts
    1,491

    Re: [Resolved] RTB paragraph indents

    Quote Originally Posted by dilettante View Post
    Even after two decades this still doesn't appear to be very well known to VB6 programmers.
    How hard was for RTB (MS) developers to wrap SendMessage RTB.hWnd, EM_GETOLEINTERFACE, 0, VarPtr(IUnknown) into a Property Get? There must be a reason for TOM to remain a mystery that I cannot understand yet.

    cheers,
    </wqw>

  17. #17
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,788

    Re: [Resolved] RTB paragraph indents

    AccadaccA:

    As Arnoutdv already pointed out, every time that you assign text from the .Text property, all formatting is lost (as you already experienced).
    When you do that, it replaces all the text of the control with new text, and this property .Text only can receive plain text since it is String type, so you are in fact assigning new text without any formatting every time that you set text from the .Text property.

    It can be used for the starting text if you want, as long as that starting text has no fomatting. Then to place the SelStart at the end and begin using SelText for the new text, or you can completely avoid using .Text and assing all the text with SelText from the start.

    It is better to only use SelText. You don't even need to change the SelStart and SelLenght, since the insertion point is automatically set at the end after any text addition:

    Code:
        RichTextBox1.Text = "" ' resets the text
        RichTextBox1.SelText = "First line" & vbCrLf
        RichTextBox1.SelBold = True
        RichTextBox1.SelText = "Second line Bold" & vbCrLf
        RichTextBox1.SelBold = False
        RichTextBox1.SelItalic = True
        RichTextBox1.SelText = "Third line Italic" & vbCrLf
        RichTextBox1.SelItalic = False
        RichTextBox1.SelIndent = 400
        RichTextBox1.SelText = "Fourth line indented" & vbCrLf
        RichTextBox1.SelText = "Fifth line still indented" & vbCrLf
        RichTextBox1.SelIndent = 0
        RichTextBox1.SelText = "Sixth line normal" & vbCrLf
    If you need to insert formatred text (for example that cames from another Rich textBox control) into this control, you need to do something else, but it seems to me that it is not what your need.
    Last edited by Eduardo-; May 16th, 2019 at 11:12 AM.

  18. #18
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,422

    Re: [Resolved] RTB paragraph indents

    Quote Originally Posted by wqweto View Post
    There must be a reason for TOM to remain a mystery that I cannot understand yet.
    I'm more frustrated that they never updated the typelib with the newer TOM2 interfaces we got in RichEdit 6.0 a while back: Text Object Model Interfaces. But we know we're less than 2nd class citizens on Windows these days. Since RichTextBox wraps an older RichEdit only InkEdit would have the new features for us anyway I suppose.

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    151

    Re: [Resolved] RTB paragraph indents

    Quote Originally Posted by Eduardo- View Post
    AccadaccA:
    As Arnoutdv already pointed out, every time that you assign text from the .Text property, all formatting is lost (as you already experienced)..
    Yes, all input obviously helped get me over the line and I appreciate all who contributed, but this program is for setting competition rules on various topics so the user's input would vary as to which rules they wanted to implement, the number of rules they require and in whatever order they thought best for any given event. Event rules change from state to state.
    It also has an editor for creating, editing and deleting categories, sub-categories and the rules, so there is never a set length of anything to preview or print.

    Therefore I couldn't use any predefined lines as your last post suggests.
    Although it's appreciated all the same. Thank you.

    dilettante Thanks for your post. It would have been easier to have just given me TOM's number and I could have rang him. lol
    All jokes aside, that looks pretty cool, especially having it numbered.
    I wouldn't want each indented sentence numbered as the rules can be many sentences long or as short as a few words.
    But I'll definitely take a look into sharing some time with TOM for future applications. Thank you, much appreciated.
    I rely heavily on trial and error, mostly only succeeding in the latter.

  20. #20
    Frenzied Member
    Join Date
    Feb 2017
    Posts
    1,788

    Re: [Resolved] RTB paragraph indents

    Quote Originally Posted by AccadaccA View Post
    Therefore I couldn't use any predefined lines as your last post suggests.
    That was an example, of course you will have the text coming from variables and probably database records in the real program and not text literals as my example.

    If you want to work without much problems with the Rich TextBox, that's the way to do it.
    I feel that you didn't learn/understand how to do it (otherwise you wouldn't be saying this).
    But I already explained and I don't think it is too hard to understand. Good luck.

  21. #21
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,422

    Re: [Resolved] RTB paragraph indents

    Quote Originally Posted by AccadaccA View Post
    I wouldn't want each indented sentence numbered as the rules can be many sentences long or as short as a few words.
    That was just he way I did the demo, leaving in CRLFs to break things up into "lines."

    RichEdit numbers paragraphs. Paragraphs are typically separated by CRLF, CR, or LF. As long as your sentences aren't broken up by those the entire paragraph gets 1 number.

  22. #22

    Thread Starter
    Addicted Member
    Join Date
    Feb 2008
    Posts
    151

    Re: [Resolved] RTB paragraph indents

    Quote Originally Posted by Eduardo- View Post
    That was an example, of course you will have the text coming from variables and probably database records in the real program and not text literals as my example.

    If you want to work without much problems with the Rich TextBox, that's the way to do it.
    I feel that you didn't learn/understand how to do it (otherwise you wouldn't be saying this).
    But I already explained and I don't think it is too hard to understand. Good luck.
    Thanks mate, I do understand. I may not have portrayed that at the time as after dealing with a pounding head ache all day I finally got the desired results and the cogs inside my head were over-heated worn and warped. lol
    I have copied all examples of this thread to a new text file in a folder with all of my other vb6 notes.
    So nobody's efforts were in vain. They're all appreciated.

    Quote Originally Posted by dilettante View Post
    That was just he way I did the demo, leaving in CRLFs to break things up into "lines."

    RichEdit numbers paragraphs. Paragraphs are typically separated by CRLF, CR, or LF. As long as your sentences aren't broken up by those the entire paragraph gets 1 number.
    I see, thanks. That'll work perfectly.
    I haven't got hold of TOM just yet but I promise I will very soon.
    Thank you.
    I rely heavily on trial and error, mostly only succeeding in the latter.

  23. #23
    PowerPoster
    Join Date
    Feb 2006
    Posts
    20,422

    Re: [Resolved] RTB paragraph indents

    If you can accomplish what you need without it do so. TOM is just another alternative.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width