Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does RichTextBox support LineSpacing? 1

Status
Not open for further replies.

ZmrAbdulla

Technical User
Joined
Apr 22, 2003
Messages
4,364
Location
AE
Does RTB support LineSpacing?
I couldn't find a solution
Is that possible to set LineSpacing =1 ?
If possible then which event I should use?
Thanks

Zameer Abdulla
Visit Me
 
I am still searching for a solution...Thanks

Zameer Abdulla
Visit Me
 
LineSpacing=1? Erm...isn't that the default?

I'm guessing what you really want is double line spacing. Does VB's RTB support that? yes, it does - but not directly through any of it's exposed Properties or Methods. You need to use the API (and you can do a lot more to the paragraph formatting than simply play with linespacing).

Here's an example routine (with necessary declarations) thaty should allow you to set any linespacing you like on the paragraph(s) that currently selected in an RTB:
Code:
[blue]Option Explicit

Private Const MAX_TAB_STOPS = 32&
Private Const EM_SETPARAFORMAT = &H447
Private Const PFM_LINESPACING = &H100&

Private Type PARAFORMAT2
    cbSize As Integer
    wPad1 As Integer
    dwMask As Long
    wNumbering As Integer
    wReserved As Integer
    dxStartIndent As Long
    dxRightIndent As Long
    dxOffset As Long
    wAlignment As Integer
    cTabCount As Integer
    lTabStops(0 To MAX_TAB_STOPS - 1) As Long
    dySpaceBefore As Long          ' Vertical spacing before para
    dySpaceAfter As Long           ' Vertical spacing after para
    dyLineSpacing As Long          ' Line spacing depending on Rule
    sStyle As Integer              ' Style handle
    bLineSpacingRule As Byte       ' Rule for line spacing
    bCRC As Byte                   ' Reserved for CRC for rapid searching
    wShadingWeight As Integer      ' Shading in hundredths of a per cent
    wShadingStyle As Integer       ' Nibble 0: style, 1: cfpat, 2: cbpat
    wNumberingStart As Integer     ' Starting value for numbering
    wNumberingStyle As Integer     ' Alignment, roman/arabic, (), ), .,     etc.
    wNumberingTab As Integer       ' Space between 1st indent and 1st-line text
    wBorderSpace As Integer        ' Space between border and text(twips)
    wBorderWidth As Integer        ' Border pen width (twips)
    wBorders As Integer            ' Byte 0: bits specify which borders; Nibble 2: border style; 3: color                                     index*/
End Type

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Function SelLineSpacing(rtbTarget As RichTextBox, SpacingRule As Long, Optional LineSpacing As Long = 20)
[green]    ' SpacingRule
    ' Type of line spacing. To use this member, set the PFM_SPACEAFTER flag in the dwMask member. This member can be one of the following values.
    ' 0 - Single spacing. The dyLineSpacing member is ignored.
    ' 1 - One-and-a-half spacing. The dyLineSpacing member is ignored.
    ' 2 - Double spacing. The dyLineSpacing member is ignored.
    ' 3 - The dyLineSpacing member specifies the spacingfrom one line to the next, in twips. However, if dyLineSpacing specifies a value that is less than single spacing, the control displays single-spaced text.
    ' 4 - The dyLineSpacing member specifies the spacing from one line to the next, in twips. The control uses the exact spacing specified, even if dyLineSpacing specifies a value that is less than single spacing.
    ' 5 - The value of dyLineSpacing / 20 is the spacing, in lines, from one line to the next. Thus, setting dyLineSpacing to 20 produces single-spaced text, 40 is double spaced, 60 is triple spaced, and so on.[/green]

    Dim Para As PARAFORMAT2
    With Para
        .cbSize = Len(Para)
        .dwMask = PFM_LINESPACING
        .bLineSpacingRule = SpacingRule
        .dyLineSpacing = LineSpacing
    End With
    
    SendMessage rtbTarget.hwnd, EM_SETPARAFORMAT, ByVal 0&, Para
End Function[/blue]

And an example of calling it for double line spacing would be:

SelLineSpacing RichTextBox1, 2
 
strongm Thanks for that code snippet.
I am having trouble to call the routine... It complaints Sub Or Function defined and highlights the
Code:
Private Sub RichTextBox1_Change()
[COLOR=black yellow]SelLineSpacing[/color] RichTextBox1, 2
End Sub
What I am doing wrong?

My requirement is something like this..
I have an RTB acts something like a text editor. No formating is allowed, using single size and type font. All are working fine. When you typing into that Its line spacing is 1 and that is what I wanted. But what happens if I copy something from other format web or word it pastes into the RTB with double or more LineSpacing. I want to avoid this. How can I ??
I can't use a textbox instead of RTB becuase I want some elements of RTB to be used.

Thanks for any help

Zameer Abdulla
Visit Me
 
If you have placed the SelLineSpacing function in a module you need to make it Public rather than Privte
 
Oho.. Some time my eyes are too small to see things..
I will have to test it when I am at home.. I will give a try and come back to you later..
Thanks

Zameer Abdulla
JVBP MDS
Jack of Visual Basic Programming, Master in Dining & Sleeping
Visit Me
 
Yeah strongm, I am able to set the LineSpacing now. Still I can't set it when I paste something from word or web. I am using it in the change event of the RTB.
Thanks

Zameer Abdulla
JVBP MDS
Jack of Visual Basic Programming, Master in Dining & Sleeping
Visit Me
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top