Results 1 to 2 of 2

Thread: Line Numbers in a RichTextBox.

  1. #1

    Thread Starter
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142

    Line Numbers in a RichTextBox.

    using the PARAFORMAT2 Structure which you can find info on msdn about ...
    VB Code:
    1. '/// very top of your Form / Class
    2. Imports System.Runtime.InteropServices
    3.  
    4. '/// then to use ...
    5.  
    6.     <StructLayout(LayoutKind.Sequential)> _
    7.     Public Structure PARAFORMAT2
    8.         Public cbSize As Int32
    9.         Public dwMask As Int32
    10.         Public wNumbering As Int16
    11.         Public wReserved As Int16
    12.         Public dxStartIndent As IntPtr
    13.         Public dxRightIndent As IntPtr
    14.         Public dxOffset As IntPtr
    15.         Public wAlignment As Int16
    16.         Public cTabCount As Short
    17.         <MarshalAs(UnmanagedType.ByValArray, SizeConst:=32)> _
    18.         Public rgxTabs() As IntPtr
    19.         Public dySpaceBefore As IntPtr
    20.         Public dySpaceAfter As IntPtr
    21.         Public dyLineSpacing As IntPtr
    22.         Public sStyle As Short
    23.         Public bLineSpacingRule As Byte
    24.         Public bOutlineLevel As Byte
    25.         Public wShadingWeight As Int16
    26.         Public wShadingStyle As Int16
    27.         Public wNumberingStart As Int16
    28.         Public wNumberingStyle As Int16
    29.         Public wNumberingTab As Int16
    30.         Public wBorderSpace As Int16
    31.         Public wBorderWidth As Int16
    32.         Public wBorders As Int16
    33.     End Structure
    34.  
    35.     <DllImport("user32", CharSet:=CharSet.Auto)> _
    36.     Private Shared Function SendMessage( _
    37.             ByVal hWnd As HandleRef, _
    38.             ByVal msg As Int32, _
    39.             ByVal wParam As Int32, _
    40.             ByRef lParam As PARAFORMAT2) As Int32
    41.     End Function
    42.  
    43.     Private Const EM_GETPARAFORMAT = 1085
    44.     Private Const EM_SETPARAFORMAT = 1095
    45.     Private Const PFM_NUMBERING As Int32 = &H20
    46.     Private Const BULLET_NUMBER = 2
    47.  
    48.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    49.         Dim param As New PARAFORMAT2
    50.         '/// you must specify the size of the structure here, using Marshal.SizeOf , in VB6 it was Len( )
    51.         param.cbSize = Marshal.SizeOf(param)
    52.         '/// build up the param structure with the current layout...
    53.         SendMessage(New HandleRef(rtb, rtb.Handle), EM_GETPARAFORMAT, 0, param)
    54.         '/// wNumbering
    55.         '/// Options used for bulleted or numbered paragraphs. To use this member, set the PFM_NUMBERING flag in the dwMask member.
    56.         '/// PFN_BULLET ( 1 ) = Insert a bullet at the beginning of each selected paragraph.
    57.         '/// 2 = Uses Arabic numbers (1, 2, 3, ...).  , hence BULLET_NUMBER.
    58.         param.dwMask = PFM_NUMBERING
    59.         param.wNumbering = BULLET_NUMBER
    60.         '/// update the richtextbox...
    61.         SendMessage(New HandleRef(rtb, rtb.Handle), EM_SETPARAFORMAT, 0, param)
    62.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  2. #2
    Lively Member
    Join Date
    Dec 2009
    Posts
    99

    Re: Line Numbers in a RichTextBox.

    if you please explain how to insert line numbers to selection text in richtextbox i got error on this line

    SendMessage(New HandleRef(rtb, rtb.Handle), EM_SETPARAFORMAT, 0, param)

    "too many arguments to private shared function send message () as object"

Posting Permissions

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



Click Here to Expand Forum to Full Width