473,839 Members | 1,361 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RichTextbox scroll to a line

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 scroll is with ScrollToCaret() . But I
don't know how to set the "caret" to a particular line.

Any suggestions?

-Rachel
Nov 17 '05 #1
6 29241
Hi Rachel,
one way to do it would be the following:

//have to set focus first on the rich text box for scrolling to work
this.richTextBo x1.Focus();

//move the caret to the correct place <IMPO>This is a character position not
line position</IMPO>
this.richTextBo x1.SelectionSta rt = 50;

this.richTextBo x1.ScrollToCare t();
I don't think there is a method for setting to caret to an individual line,
so you will have to calculate the position of the caret by knowing how many
characters there are in each line (plus the \r\n)

Hope that helps
Mark.
"Rachel Suddeth" wrote:
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 scroll is with ScrollToCaret() . But I
don't know how to set the "caret" to a particular line.

Any suggestions?

-Rachel

Nov 17 '05 #2
"Mark R. Dawson" <Ma*********@di scussions.micro soft.com> wrote:
I don't think there is a method for setting to caret to an individual line,
so you will have to calculate the position of the caret by knowing how many
characters there are in each line (plus the \r\n)


Small point: the line delimiter that RichTextBox uses is simply '\n' in my
testing.
Nov 17 '05 #3
Maybe I should just track the current character position intead. Now that I
think of it, that's just as easy to do -- it's just that the line index was
what I needed for other purposes, so it's what I was tracking. But it's easy
to do GetLineFromChar Index(), and not so easy the other way 'round. I don't
feel a whole lot of confidence that I can always count on exactly one
character between each line... (which is what I'm seeing in my testing...
just the '\n' -- which is translated to a "/r/n" in the .Rtf property.

In order for ScrollToCaret to do what I really want, I'll also need to know
whether my initial position is above or below the place I want to scroll to,
and if it's above (so I'm scrolling down)... oh, thats the problem, though.
I can figure out how many lines are showing in the control, but to get the
"caret" down that many lines (so that my desired line will end up as the
first line, not the last), I will still need to be able to find a character
position n lines down ...

Why is this so hard? Some part of the control has to know which line its
characters are on to draw them correctly... why don't I have access to that
info?

I could try GetCharIndexFro mPosition() where the Position argument has a Y
close to RichTextBox.Cli entSize.Height * 2, and then ScrollToCaret a second
time... maybe that would work, but it seems unnecessarily complicated, and I
don't know how it would look.

-Rachel

"Mark R. Dawson" <Ma*********@di scussions.micro soft.com> wrote in message
news:27******** *************** ***********@mic rosoft.com...
Hi Rachel,
one way to do it would be the following:

//have to set focus first on the rich text box for scrolling to work
this.richTextBo x1.Focus();

//move the caret to the correct place <IMPO>This is a character position not line position</IMPO>
this.richTextBo x1.SelectionSta rt = 50;

this.richTextBo x1.ScrollToCare t();
I don't think there is a method for setting to caret to an individual line, so you will have to calculate the position of the caret by knowing how many characters there are in each line (plus the \r\n)

Hope that helps
Mark.
"Rachel Suddeth" wrote:
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 scroll is with ScrollToCaret() . But I
don't know how to set the "caret" to a particular line.

Any suggestions?

-Rachel

Nov 17 '05 #4
Rachel Suddeth <ra****@bldhoun d.com> wrote:
Why is this so hard?


I've never tried using the following, but it looks promising:
<http://tinyurl.com/btoza>.
Nov 17 '05 #5
Thanks... it's worth a try.

"Cool Guy" <co*****@abc.xy z> wrote in message
news:1g******** *******@cool.gu y.abc.xyz...
Rachel Suddeth <ra****@bldhoun d.com> wrote:
Why is this so hard?


I've never tried using the following, but it looks promising:
<http://tinyurl.com/btoza>.

Nov 17 '05 #6
Looks like this will work. At least I've tested with this (in Leave event of
TextBox1):
// const int EM_LINESCROLL = 0x00B6;
SendMessage( RichTextbox1.Ha ndle, 0x00b6, 0, int.Parse( TextBox1.Text) );


and it does indeed scroll down the number of lines I type into TextBox1.Text

Nov 17 '05 #7

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

Similar topics

2
2731
by: JRB | last post by:
I have a thread adding lines of text to a richtextbox on my windows form about every 1 second. I want the last line of text to always be visible, which it is until the box gets filled up. The last line is always visible if the cursor is on the richtextbox, But if I'm working on another richtextbox on the form, the one that is continually getting text doesn't scroll down automatically. Is there any way to get it to automatically show the...
3
9420
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 clicks. If the user slides the "thumb", I seem to get no indication. Anyone know how to get notified of the thumb slide from a RichTextBox? I can derive from RichTextBox and trap messages if need be, but I have not been able to figure out what to...
2
17397
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 the control or the scrolltocaret method I decided that it would be worth posting to anyone who might have similar concerns. For the record this works well in an environment where you cannot have focus going to the richtextbox....such as a chat...
7
2071
by: Richard | last post by:
When you give focus to a RichTextBox, then it goes to the textCursor, but i don't want to give the richtextbox focus, cause there is being written a lot in it, and I have to do something else at the same time, then if I don't give it focus, and I add some text to it, then it don't automaticly scrolls down to the textcursor, is there a way to make the RichTextBox scroll down to the textcursor, without giving it focus?? Richard
0
4168
by: John Smith | last post by:
I have text files and I get binary offsets of text portion of these files from VB6 program with RichTextBox. I use VB.Net 2003 and need to select and highlight the text between given offsets. RichTextBox does not highlight the correct string as it treats new line pair as one character. Is there a way to highlight the correct string ? How do I translate real binary offsets to richtextbox offsets ? To reproduce: I have placed a text box...
1
2282
by: Bruce F | last post by:
From a newbie... I want to load text into a RichTextBox one line at a time so that I can change the font color of each line depending on conditions. 1. How to load line by line? 2. How to change font color as each line loads?
0
2079
by: Brian Keating | last post by:
Hi there, Does anyone know if i can determin if the scroll position is at the bottom of my textbox? I can get the scroll position fine, but how do i know if it's actually at the bottom? thanks in advance Brian.
2
1124
by: neoupadhyay | last post by:
Hi Mate, Well i have a datagrid and i use scroll bar on it via "Div" the code is below, its working fine, but i wannt only single scroll line which is verticale...thts i scroll up and down not to left or right. wht i do plz suggest me,...if there is any other way then told me to implement...thnx <div style="OVERFLOW: auto; Width: 217px;">
2
9781
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 the user changes the input data, a recalculation is made and a new report is generated. This resets the RichTextBox vertical scroll bar to the top. I would like to be able to read the position the scroll bar is moved to before recalculation....
0
9855
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9697
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10295
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9426
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7830
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4492
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4065
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3136
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.