|
-
Jun 3rd, 2013, 10:50 AM
#1
Thread Starter
PowerPoster
[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
-
Jun 3rd, 2013, 11:29 AM
#2
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
-
Jun 3rd, 2013, 11:33 AM
#3
Thread Starter
PowerPoster
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by RhinoBull
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
-
Jun 3rd, 2013, 11:42 AM
#4
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
-
Jun 3rd, 2013, 11:50 AM
#5
Thread Starter
PowerPoster
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by techgnome
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:
-
Jun 4th, 2013, 12:36 AM
#6
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 $$$ :)
-
Jun 4th, 2013, 05:04 AM
#7
Thread Starter
PowerPoster
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by Max187Boucher
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
-
Jun 4th, 2013, 08:26 PM
#8
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
-
Jun 5th, 2013, 04:48 AM
#9
New Member
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
Set design page scrollbar as Both
-
Jun 5th, 2013, 07:22 AM
#10
Thread Starter
PowerPoster
-
Jun 5th, 2013, 10:34 AM
#11
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
It's fine - just make it large enough to see scrollbars when you place your user control onto the form.
-
Jun 5th, 2013, 10:36 AM
#12
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
You may also want to consider coding UserControl_Resize() event to resize RTB/picture controls...
-
Jun 5th, 2013, 02:01 PM
#13
Thread Starter
PowerPoster
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
-
Jun 5th, 2013, 07:21 PM
#14
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by RhinoBull
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
-
Jun 6th, 2013, 04:38 AM
#15
Thread Starter
PowerPoster
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by Max187Boucher
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?
-
Jun 8th, 2013, 04:08 PM
#16
Thread Starter
PowerPoster
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)
-
Jun 8th, 2013, 10:45 PM
#17
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by joaquim
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.
-
Jun 9th, 2013, 06:25 AM
#18
Thread Starter
PowerPoster
Re: [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by Max187Boucher
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?
-
Jun 9th, 2013, 10:03 AM
#19
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
-
Jun 9th, 2013, 11:36 AM
#20
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?
-
Jun 9th, 2013, 01:16 PM
#21
Thread Starter
PowerPoster
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
-
Jun 9th, 2013, 02:46 PM
#22
Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?
Nice joaquim, seems to do the trick!
-
Jun 9th, 2013, 02:58 PM
#23
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by Max187Boucher
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?
-
Jun 9th, 2013, 03:21 PM
#24
Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by joaquim
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)
-
Jun 9th, 2013, 03:28 PM
#25
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by Bonnie West
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)
-
Jun 9th, 2013, 04:44 PM
#26
Thread Starter
PowerPoster
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.
-
Jun 9th, 2013, 11:32 PM
#27
Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by joaquim
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)
-
Jun 10th, 2013, 02:30 AM
#28
Thread Starter
PowerPoster
Re: [RESOLVED] [VB6(windows 7) - richtextbox] - how show the scrollbars?
 Originally Posted by Bonnie West
thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|