473,604 Members | 2,483 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

RichTextBox scroll position

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. Then, after recalculation, I would like to set the
scroll bar to the previous position (or merely nearby). Are these operation
possible from code.

Please do not suggest another way that I can present my data, I know it
sounds a like a newbie way of presenting data, however, it's not - the
varying nature of the data require this presentation.

regards Jesper, DK
Sep 8 '07 #1
2 9745
Jesper,

You can call the GetScrollBarInf o through the P/Invoke layer to get the
location of the slider on the vertical scrollbar for the rich text box
control. You can then call the SetScrollPos API function to set the
location of the new scroll bar.

Of course, you have to assure that that the new content is large enough
to place the slider at the position you want (or you should check before
setting the value after you repopulate the control).

i
"Jesper, Denmark" <Je***********@ discussions.mic rosoft.comwrote in message
news:ED******** *************** ***********@mic rosoft.com...
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. Then, after recalculation, I would like to set the
scroll bar to the previous position (or merely nearby). Are these
operation
possible from code.

Please do not suggest another way that I can present my data, I know it
sounds a like a newbie way of presenting data, however, it's not - the
varying nature of the data require this presentation.

regards Jesper, DK
Sep 8 '07 #2
A couple of months ago I implemented some syncronized rich edit controls.
Follwing the guidance by
http://www.codeproject.com/vb/net/RT...dScrolling.asp I altered it
somewhat for my requirements.

You are going to run into problems if the textbox is larger that 65536
pixels.
The way I solved this problem was to implement an error correction
algorithm. Code shown below.
public class ExRichTextBox : System.Windows. Forms.RichTextB ox
{

private double _Yfactor = 1.0d;
public Point ScrollPos
{
get
{
Point scrollPoint = new Point();

SendMessage(thi s.Handle, (int)WindowsMes sages.EM_GETSCR OLLPOS, 0, ref
scrollPoint);
return scrollPoint;
}
set
{
Point original = value;
if (original.Y < 0)
original.Y = 0;
if (original.X < 0)
original.X = 0;

Point factored = value;
factored.Y = (int)((double)o riginal.Y * _Yfactor);

Point result = value;

SendMessage(thi s.Handle, (int)WindowsMes sages.EM_SETSCR OLLPOS, 0, ref
factored);
SendMessage(thi s.Handle, (int)WindowsMes sages.EM_GETSCR OLLPOS, 0, ref
result);

int loopcount = 0;
int maxloop = 100;
while (result.Y != original.Y)
{
// Adjust the input.
if (result.Y original.Y)
factored.Y -= (result.Y - original.Y) / 2 - 1;
else if (result.Y < original.Y)
factored.Y += (original.Y - result.Y) / 2 + 1;

// test the new input.
SendMessage(thi s.Handle, (int)WindowsMes sages.EM_SETSCR OLLPOS, 0, ref
factored);
SendMessage(thi s.Handle, (int)WindowsMes sages.EM_GETSCR OLLPOS, 0, ref
result);

// save new factor, test for exit.
loopcount++;
if (loopcount >= maxloop || result.Y == original.Y )
{
_Yfactor = (double)factore d.Y / (double)origina l.Y;
break;
}
}
}
}
}

Sep 9 '07 #3

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

Similar topics

5
13028
by: user | last post by:
Hello When i add new lines of text to my RichTextBox, and when vertical scroll bar appear (there is more text than RichTextBox can display), RichTextBox always display "the oldest text" (vertical scrollbar is always rolled to the top). And i want to see "fresh text" (vertical scrollbar should be rolled to bottom position). How can i do that ?
2
2709
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...
6
29180
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 scroll is with ScrollToCaret(). But I don't know how to set the "caret" to a particular line. Any suggestions? -Rachel
3
9389
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
17320
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
2036
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
2
3662
by: Al | last post by:
Hi, Is there any way to replace a character at a position? Without cussing the RichTextBox to scroll. For example the following code will replaces the by removing but the side effect is that it will cause it to scroll. aRichtext.Text = aRichtext.Text.Remove(position, 1) aRichtext.Text = aRichtext.Text.Insert(position, "Y")
1
2884
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 the checkbox is enabled for the user to tick off (I agree) and the next button is enabled for user to click next. the richtextbox vscroll event only fire when user click on the scrollthumb and that's it. how do i implement it when user drag the...
0
2061
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.
0
7997
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
8419
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8065
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8280
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
5441
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3907
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2434
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
1
1526
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1266
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.