scroll richtextbox

D

Dayne

My form has a richtextbox control with two button ("up" and "down") . I need
to use those buttons to scroll the text in the richtextbox "page-by-page".
Any ideas?
 
A

Arne Janning

Hi Dayne!

My form has a richtextbox control with two button ("up" and "down") . I
need
to use those buttons to scroll the text in the richtextbox "page-by-page".
Any ideas?

it only works if the RTF-Box has the focus (and therefore a caret).

Here is a small example using WinAPI-SendMessage:

Imports System.Runtime.InteropServices

'SendMessage-Declaration
<DllImport("user32.dll")> _
Private Shared Function SendMessage( _
ByVal window As IntPtr, _
ByVal message As Integer, _
ByVal wparam As Integer, _
ByVal lparam As Integer) As IntPtr
End Function

'Constants for SendMessage
Private Const WM_VSCROLL As Integer = &H115
Private Const SB_PAGEUP As Integer = 2
Private Const SB_PAGEDOWN As Integer = 3

'ScrollDown-Button
Private Sub Button1_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button1.Click

'Let's add some text to the RTF-Box
For i As Integer = 0 To 100
RichTextBox1.Text += " Hello World "
Next

'One page down
SendMessage(RichTextBox1.Handle, WM_VSCROLL, SB_PAGEDOWN, 0)
End Sub

'ScrollUp-Button
Private Sub Button2_Click( _
ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles Button2.Click

'One page up
SendMessage(RichTextBox1.Handle, WM_VSCROLL, SB_PAGEUP, 0)
End Sub


Cheers

Arne Janning
 
D

Da Tr

I don't know what I just did ,. but it worked!!..next question . I want
to list the number of "pages" to scroll... Example "1/5 Pages" .. how do
i do this?

Dayne
 
K

Ken Halter

Arne Janning wrote:

OT... a far more efficient way to add text to a box (no double buffering
or unnecessary concatenation).... Since I'm a VB6 type (just pokin'
'round here), the syntax below may not be exact... but the logic's still
valid.

With RichTextBox1
For i As Integer = 0 To 100

.SelectionStart = .Text.Length
.SelectedText = " Hello World "

End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top