CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: RichTextBox

  1. #1
    Join Date
    Jul 2000
    Posts
    135

    RichTextBox

    Can someone give me an example of how to set the scrollbar value of a richtextbox.

    IF I type:

    RichTextBox1.ScrollBar = rftBoth

    I get a run time error that this field is read only. I have also tried setting the multiline value to true and I get the same error.

    Thanks.

    Ray



  2. #2
    Join Date
    Dec 1999
    Location
    Dublin, Ireland
    Posts
    1,173

    Re: RichTextBox

    Both of those properties are only available at design time.
    You could try setting the window class bits at run time thus:

    '\\ Window Style
    public Enum enWindowStyles
    WS_BORDER = &H800000
    WS_CAPTION = &HC00000 ' WS_BORDER Or WS_DLGFRAME
    WS_CHILD = &H40000000
    WS_CLIPCHILDREN = &H2000000
    WS_CLIPSIBLINGS = &H4000000
    WS_DISABLED = &H8000000
    WS_DLGFRAME = &H400000
    WS_EX_ACCEPTFILES = &H10&
    WS_EX_DLGMODALFRAME = &H1&
    WS_EX_NOPARENTNOTIFY = &H4&
    WS_EX_TOPMOST = &H8&
    WS_EX_TRANSPARENT = &H20&
    WS_GROUP = &H20000
    WS_HSCROLL = &H100000
    WS_MAXIMIZE = &H1000000
    WS_MAXIMIZEBOX = &H10000
    WS_MINIMIZE = &H20000000
    WS_MINIMIZEBOX = &H20000
    WS_OVERLAPPED = &H0&
    WS_POPUP = &H80000000
    WS_SYSMENU = &H80000
    WS_TABSTOP = &H10000
    WS_THICKFRAME = &H40000
    WS_VISIBLE = &H10000000
    WS_VSCROLL = &H200000
    End Enum

    '\\ --[IsWindowStyleSet]----------------------------------------------------------------------
    '\\ Checks for the style bit specified in the window specified.
    '\\ ----------------------------------------------------------------------------------------
    '\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code
    '\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you
    '\\ ----------------------------------------------------------------------------------------
    public Function IsWindowStyleSet(byval TheStyle as Long) as Boolean

    Dim lStyle as Long
    Dim lWSIndex as Long

    If TheStyle = WS_EX_ACCEPTFILES Or TheStyle = WS_EX_DLGMODALFRAME Or TheStyle = WS_EX_NOPARENTNOTIFY Or TheStyle = WS_EX_TOPMOST Or TheStyle = WS_EX_TRANSPARENT then
    lWSIndex = GWL_EXSTYLE
    else
    lWSIndex = GWL_STYLE
    End If

    '\\ get the current setting of that style bit
    lStyle = GetWindowLongApi(m_hwnd, lWSIndex)
    IsWindowStyleSet = (lStyle And TheStyle)

    End Function

    '\\ --[SetWindowStyle]----------------------------------------------------------------------
    '\\ Sets the style bit specified to the window specified. Note that many window style
    '\\ bits cannot be used at run time :. use this with caution
    '\\ Returns true if it succeeded
    '\\ ----------------------------------------------------------------------------------------
    '\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code
    '\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you
    '\\ ----------------------------------------------------------------------------------------
    public Function SetWindowStyle(byval NewStyle as enWindowStyles) as Boolean

    Dim lStyle as Long
    Dim lWSIndex as Long
    Dim lRet as Long

    If NewStyle = WS_EX_ACCEPTFILES Or NewStyle = WS_EX_DLGMODALFRAME Or NewStyle = WS_EX_NOPARENTNOTIFY Or NewStyle = WS_EX_TOPMOST Or NewStyle = WS_EX_TRANSPARENT then
    lWSIndex = GWL_EXSTYLE
    else
    lWSIndex = GWL_STYLE
    End If

    '\\ get the current setting of that style bit
    lStyle = GetWindowLongApi(m_hwnd, lWSIndex)

    '\\ Add the new style bit to it
    lStyle = lStyle Or NewStyle

    '\\ set it to the window
    lRet = SetWindowLongApi(m_hwnd, lWSIndex, lStyle)

    '\\ for some styles to take effect, the window must be redrawn...


    SetWindowStyle = me.IsWindowStyleSet(lStyle)

    End Function




    and call it thus:

    If SetWindowStyle(WS_VSCROLL OR WS_HSCROLL) then
    'scrollbars were enabled....
    End If




    HTH,
    Duncan

    -------------------------------------------------
    Ex. Datis: Duncan Jones
    Merrion Computing Ltd
    http://www.merrioncomputing.com
    '--8<-----------------------------------------
    NEW -The printer usage monitoring application
    '--8<------------------------------------------

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

Featured