473,394 Members | 1,802 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,394 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?
Jul 21 '05 #1
4 1312
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
Jul 21 '05 #2
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #3
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..
Jul 21 '05 #4
"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/>
Jul 21 '05 #5

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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.