473,378 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

scroll richtextbox

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?
Nov 21 '05 #1
3 1762
Hi Dayne!

"Dayne" schrieb
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
Nov 21 '05 #2
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 "
Next


End With

--
Ken Halter - MS-MVP-VB - http://www.vbsight.com
Please keep all discussions in the groups..
Nov 21 '05 #3
"Ken Halter" <Ken_Halter@Use_Sparingly_Hotmail.com> schrieb:
With RichTextBox1
For i As Integer = 0 To 100


.SelectionStart = .Text.Length


Well, in .NET you can use '.TextLength' too :-).

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Wilfried Mestdagh | last post by:
Hello, textBox += someData + "\r\n"; does not scroll the visible text to the end. How do I perform that ? Also this way seems to me a lot of reallocating memory. Is there better way to add...
6
by: Rachel Suddeth | last post by:
I have the index of a line in the Lines array of a RichTextBox. I would like to have it scroll so that line displays at the top. Is there no way to do this? The only way I can see to make it...
3
by: Rachel Suddeth | last post by:
I want to react to scrolls in a RichTextBox (I want to let the user know when he has changed to a new printable page.) I have handled the VScroll() event, but that only responds to scrollbar...
4
by: One Handed Man | last post by:
Ive been working on this since yesterday and its bugging me. Although the event is firing, The box does not scroll. Can anyone see what Im doing wrong. I suspect it is stupidly simple. TIA
2
by: JonnyT | last post by:
I searched high and low for an answer on how to auto scroll a richtextbox and now I finally have it. Since it took me a while to get a good efficient way of doing it that didn't require focus to...
1
by: Daniel Friend | last post by:
How do I scroll to the bottom of RichTextBox Currently tried RichTextBox1.SelectionStart=len(RichTextBox1.text) RichTextBox1.ScrollToCaret This does not work. What is the best what to...
6
by: UJ | last post by:
I've got a multiline textbox that I'm using to display messages. Is there an easy way to have it scroll to the end after I add a line to the text of the box? TIA - Jeff.
1
by: dotnetnoob | last post by:
i have a Dialog form with richtextbox that basically display a legal agreement and when the user drag the scroll thumb down to the end of scrolling which suppose to mean the user have read it then...
1
by: teo | last post by:
hallo I'm with vs2005 fw 2..0 is there a way to "freeze" the richtextbox, so to avoid user from editing it? I can Enable=False, but it no more scrolls and the font-color becomes grayed. ...
2
by: =?Utf-8?B?SmVzcGVyLCBEZW5tYXJr?= | last post by:
Hi, I have a somewhat long calculation report printed out in a RichTextBox. To find or monitor a particular value, users scroll down to the location of the data in the RichTextBox. However, when...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.