Results 1 to 28 of 28

Thread: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

  1. #1

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Resolved [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    how can i show the scrollbars on RichTextBox?
    i'm trying use the scrollbar property, but it's ignored and give me an error on run-time:
    "run-time error '383': the property is read-only"
    strange... why these error message?
    Code:
    rtbCodeText.ScrollBars = rtfBoth
    VB6 2D Sprite control

    To live is difficult, but we do it.

  2. #2

  3. #3

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by RhinoBull View Post
    Set it at design time.
    but isn't showed
    i don't know if have to do with properties that i use for open VB6 in windows 7
    i use it in usercontrol
    VB6 2D Sprite control

    To live is difficult, but we do it.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    the RTB will only show the scroll bars if it has to... if there is no need to scroll, it hides them.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by techgnome View Post
    the RTB will only show the scroll bars if it has to... if there is no need to scroll, it hides them.

    -tg
    see what i mean:
    Name:  the scrollbars aren't showed.gif
Views: 1610
Size:  22.3 KB
    VB6 2D Sprite control

    To live is difficult, but we do it.

  6. #6
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    You'll have to pay me soon, I'll be waiting for my paycheck
    The trick is the set the RightMargin wider then the width.
    Code:
    RichTextBox1.RightMargin = RichTextBox1.Width + 1000
    Note:
    I did put +1000, but you could put +100 or +10000, depending on what you need.
    Also you could select the widest line (looping line by line) using Debug.Print Me.TextWidth(LineOfRichText)
    Of course you would use a long variable instead of Debug.Print to keep the longest line, once you got the longest line then you could use

    Code:
    RichTextBox1.RightMargin = LONG_LongestLine
    One more thing, make sure the richtextbox is not wider than the RightMargin!!!
    I would simply set it at Form_Load like the first example I gave you (.width + 1000).
    Last edited by Max187Boucher; Jun 4th, 2013 at 01:09 AM. Reason: Waiting to get $$$ PAID $$$ :)

  7. #7

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by Max187Boucher View Post
    You'll have to pay me soon, I'll be waiting for my paycheck
    The trick is the set the RightMargin wider then the width.
    Code:
    RichTextBox1.RightMargin = RichTextBox1.Width + 1000
    Note:
    I did put +1000, but you could put +100 or +10000, depending on what you need.
    Also you could select the widest line (looping line by line) using Debug.Print Me.TextWidth(LineOfRichText)
    Of course you would use a long variable instead of Debug.Print to keep the longest line, once you got the longest line then you could use

    Code:
    RichTextBox1.RightMargin = LONG_LongestLine
    One more thing, make sure the richtextbox is not wider than the RightMargin!!!
    I would simply set it at Form_Load like the first example I gave you (.width + 1000).
    sorry.. aren't showed
    is because i'm using it in usercontrol?
    because, in a form, i can see the vertical scrollbar... hey but don't show the horizontal scrollbar
    VB6 2D Sprite control

    To live is difficult, but we do it.

  8. #8
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    It does work, but I guess you did not do any testing!

    Here is a small hack

    Code:
    Private Sub Form_Load()
      With RichTextBox1
        .RightMargin = .Width + 10000
        
        Do Until TextWidth(.Text) > .RightMargin
          .Text = .Text & Space(1)
        Loop
        
        Do Until TextHeight(.Text) > .Height
          .Text = .Text & vbNewLine & Space(1)
        Loop
        
      End With
    End Sub
    
    Private Sub RichTextBox1_Change()
      With RichTextBox1
        .RightMargin = .Width + 10000
        
        Do Until TextWidth(.Text) > .RightMargin
          .Text = .Text & Space(1)
        Loop
        
        Do Until TextHeight(.Text) > .Height
          .Text = .Text & vbNewLine & Space(1)
        Loop
        
      End With
    End Sub

  9. #9
    New Member NRamakrishna's Avatar
    Join Date
    Jun 2013
    Location
    Banglore
    Posts
    4

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Set design page scrollbar as Both

  10. #10

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    please test it and see what i'm doing wrong
    the vertical and horizontal scroolbars aren't showed
    Attached Files Attached Files
    VB6 2D Sprite control

    To live is difficult, but we do it.

  11. #11

  12. #12

  13. #13

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by RhinoBull View Post
    You may also want to consider coding UserControl_Resize() event to resize RTB/picture controls...
    if i understand: is write some text in vertical\horizontal for show the scrollbars, right?
    i did that:
    -in form the vertical is showed, but not horizontal
    -in usercontrol no one is showed
    see the post 5
    VB6 2D Sprite control

    To live is difficult, but we do it.

  14. #14
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by RhinoBull View Post
    You may also want to consider coding UserControl_Resize() event to resize RTB/picture controls...
    Exactly, something like this would work.
    Code:
    Private Sub UserControl_Resize()
        With rtbCodeText
        .RightMargin = .Width + 10000
        
        Do Until TextWidth(.Text) > .RightMargin
          .Text = .Text & Space(1)
        Loop
        
        Do Until TextHeight(.Text) > .Height
          .Text = .Text & vbNewLine & Space(1)
        Loop
        
      End With
      
      With rtbCodeText
        .Move .Left, .Top, UserControl.Width - 540, UserControl.Height
      End With
    End Sub

  15. #15

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by Max187Boucher View Post
    Exactly, something like this would work.
    Code:
    Private Sub UserControl_Resize()
        With rtbCodeText
        .RightMargin = .Width + 10000
        
        Do Until TextWidth(.Text) > .RightMargin
          .Text = .Text & Space(1)
        Loop
        
        Do Until TextHeight(.Text) > .Height
          .Text = .Text & vbNewLine & Space(1)
        Loop
        
      End With
      
      With rtbCodeText
        .Move .Left, .Top, UserControl.Width - 540, UserControl.Height
      End With
    End Sub
    thanks.. now works.
    but can you explain better what you did, please?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  16. #16

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    if i understand: the RightMargin is for change the limit of horizontal characters\pixels
    (and doing these, the vertical bar will show, depending of vertical chars)
    (correct me if i'm wrong)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  17. #17
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by joaquim View Post
    RightMargin is for change the limit of horizontal characters\pixels
    Yes, it is the limit of space given to write text horizontally inside the control's TextArea.

  18. #18

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by Max187Boucher View Post
    Yes, it is the limit of space given to write text horizontally inside the control's TextArea.
    question: the vertical scrollbar only shows if the text is more big than richtextbox control. why the horizontal scrollbar don't works in same way?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  19. #19
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Is there a wordwrap property? If so, make sure it is set to false... it's been a long time since I've used the RTB in a VB6 environment, but I want to say that there is a property and it is set to True by default... see if that changes anything.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  20. #20

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by techgnome View Post
    Is there a wordwrap property? If so, make sure it is set to false... it's been a long time since I've used the RTB in a VB6 environment, but I want to say that there is a property and it is set to True by default... see if that changes anything.

    -tg
    the problem is that: there isn't. try see yourself
    even the textbox don't have it, but when i put the scrollbars, works normaly
    but i'm thinking, if RTB have the hwnd property, maybe there is an API function(or way) for that. but until now i found only with rightmargin property
    VB6 2D Sprite control

    To live is difficult, but we do it.

  21. #21

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    finally i found another way
    Code:
    Option Explicit
    
    Private Const WM_USER = &H400
    
    Private Const EM_SETTARGETDEVICE = (WM_USER + 72)
    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 Sub Form_Load()
        SendMessage RichTextBox1.hwnd, EM_SETTARGETDEVICE, 0, ByVal -1&
    End Sub
    i have tested and works fine(don't forget show the scrollbars).
    so what is the diference between righmargin and these? seems these code desactivate the wordwrap property and the horizontal scrollbar is showed only after write some text.
    but i have update the code:
    module:
    Code:
    Private Const WM_USER = &H400
    
    Private Const EM_SETTARGETDEVICE = (WM_USER + 72)
    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
    
    Public Sub WordWrap(ControlHandle As Long, ActivateWordWrap As Boolean)
        If ActivateWordWrap = False Then
            SendMessage ControlHandle, EM_SETTARGETDEVICE, 0, ByVal -1&
        Else
            SendMessage ControlHandle, EM_SETTARGETDEVICE, 0, ByVal 0&
        End If
    End Sub
    how use it:
    Code:
    Private Sub Command1_Click()
        WordWrap RichTextBox1.hwnd, False
    End Sub
    these code works fine with RichTextBox control but these code, not tested with another controls, can be used with another controls
    thanks for all
    VB6 2D Sprite control

    To live is difficult, but we do it.

  22. #22
    PowerPoster
    Join Date
    Aug 2011
    Location
    B.C., Canada
    Posts
    2,887

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Nice joaquim, seems to do the trick!

  23. #23

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by Max187Boucher View Post
    Nice joaquim, seems to do the trick!
    sorry but i need ask something:
    i understand that the SendMessage() do very things.. very. but can you give me a nice tutorial about all of SendMessage() funmction?
    VB6 2D Sprite control

    To live is difficult, but we do it.

  24. #24
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by joaquim View Post
    sorry but i need ask something:
    i understand that the SendMessage() do very things.. very. but can you give me a nice tutorial about all of SendMessage() funmction?
    About Messages and Message Queues has everything you need to know about the messages that SendMessage sends. It also enumerates almost all of the available system messages.
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  25. #25

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by Bonnie West View Post
    About Messages and Message Queues has everything you need to know about the messages that SendMessage sends. It also enumerates almost all of the available system messages.
    sorry, but i never like how msdn explains.. realy...
    can you give me another link, please?(don't be mad, but i never like how they explain. maybe the english is advanced for me or something)
    VB6 2D Sprite control

    To live is difficult, but we do it.

  26. #26

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    another important tip. by some reason, the richtextbox must be updated after change the WordWrap() (that's why you moved the control). so i change my sub:
    Code:
    Option Explicit
    
    Private Const WM_USER = &H400
    
    Private Const EM_SETTARGETDEVICE = (WM_USER + 72)
    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 Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
    
    Public Sub WordWrap(ControlHandle As Long, ActivateWordWrap As Boolean)
        If ActivateWordWrap = False Then
            SendMessage ControlHandle, EM_SETTARGETDEVICE, 0, ByVal -1&
        Else
            SendMessage ControlHandle, EM_SETTARGETDEVICE, 0, ByVal 0&
        End If
        UpdateWindow ControlHandle
    End Sub
    why i did these change? because in usercontrol wasn't working
    but the move code give me the Update ideia and i used it and works
    now, i have totally tested, works fine in forms and usercontrols.
    i accept sugestions about these sub
    thanks for all
    Last edited by joaquim; Jun 9th, 2013 at 04:51 PM.
    VB6 2D Sprite control

    To live is difficult, but we do it.

  27. #27
    Default Member Bonnie West's Avatar
    Join Date
    Jun 2012
    Location
    InIDE
    Posts
    4,060

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by joaquim View Post
    sorry, but i never like how msdn explains.. realy...
    can you give me another link, please?(don't be mad, but i never like how they explain. maybe the english is advanced for me or something)
    Well, MSDN is the official documentation for the Windows API, so any other API tutorial or guide ultimately derived from it. Anyway, you may find these tutorials easier to comprehend:

    SendMessage API Tutorial

    Enum Windows & SendMessage API

    Sending Messages (scroll down to bottom)
    On Local Error Resume Next: If Not Empty Is Nothing Then Do While Null: ReDim i(True To False) As Currency: Loop: Else Debug.Assert CCur(CLng(CInt(CBool(False Imp True Xor False Eqv True)))): Stop: On Local Error GoTo 0
    Declare Sub CrashVB Lib "msvbvm60" (Optional DontPassMe As Any)

  28. #28

    Thread Starter
    PowerPoster joaquim's Avatar
    Join Date
    Apr 2007
    Posts
    3,961

    Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?

    Quote Originally Posted by Bonnie West View Post
    Well, MSDN is the official documentation for the Windows API, so any other API tutorial or guide ultimately derived from it. Anyway, you may find these tutorials easier to comprehend:

    SendMessage API Tutorial

    Enum Windows & SendMessage API

    Sending Messages (scroll down to bottom)
    thanks
    VB6 2D Sprite control

    To live is difficult, but we do it.

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