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 program or something similar. If
you are able to set focus to the form then use this method
richtextbox.sel ectionstart = richtextbox.tex tlength
richtextbox.scr olltocaret()
I think that should do it...can't remember offhand...somet hing like
that though.
Now if you cannot set the focus to the richtextbox then this will work
well for you.
When you want to display text in the richtext box use the
..appendtext("s ometext") method. That's what it's there for.
Then you will need the sendmessage API...
Public Declare Function SendMessage Lib "user32.dll " Alias _
"SendMessag eA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal
wParam As Integer, ByVal lParam As Integer) As Integer
and you will also need a couple constants...
Public Const EM_GETLINECOUNT = &HBA
Public Const EM_LINESCROLL = &HB6
Now the way I do it works great for me....
I figure out how many line are in the richtextbox before adding my new
text to it....I do that with the following...
Dim intLines As Integer = SendMessage(ric htextbox.Handle ,
EM_GETLINECOUNT , 0, 0)
then add your text
richtextbox.app endtext("your text here")
you will know how many lines to scroll down with by running the
EM_GETLINECOUNT after you added your new text like so
Private intLinesToAdd as integer = (SendMessage(ri chtextbox.Handl e,
EM_GETLINECOUNT , 0, 0) - intTotalLines)
Now that you know how many lines have been added...you know how many
lines your scroll bar needs to scroll down.
We use this line to scroll the scroll bar down...
SendMessage(ric htextbox.Handle , EM_LINESCROLL, 0, intLinesToAdd)
I've changed it a little from my original code to make it easier for
you to use...I hope it still works how it's suppose to. If not I
think you get the jist of it.
JonnyT 2 17374
Hi Jonny,
Thank you for sharing this with us.
Cor 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 program or something similar. If you are able to set focus to the form then use this method
richtextbox.sel ectionstart = richtextbox.tex tlength richtextbox.scr olltocaret()
I think that should do it...can't remember offhand...somet hing like that though.
Now if you cannot set the focus to the richtextbox then this will work well for you. When you want to display text in the richtext box use the .appendtext("so metext") method. That's what it's there for. Then you will need the sendmessage API...
Public Declare Function SendMessage Lib "user32.dll " Alias _ "SendMessag eA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
and you will also need a couple constants...
Public Const EM_GETLINECOUNT = &HBA Public Const EM_LINESCROLL = &HB6
Now the way I do it works great for me....
I figure out how many line are in the richtextbox before adding my new text to it....I do that with the following...
Dim intLines As Integer = SendMessage(ric htextbox.Handle , EM_GETLINECOUNT , 0, 0)
then add your text
richtextbox.app endtext("your text here")
you will know how many lines to scroll down with by running the EM_GETLINECOUNT after you added your new text like so
Private intLinesToAdd as integer = (SendMessage(ri chtextbox.Handl e, EM_GETLINECOUNT , 0, 0) - intTotalLines)
Now that you know how many lines have been added...you know how many lines your scroll bar needs to scroll down. We use this line to scroll the scroll bar down...
SendMessage(ric htextbox.Handle , EM_LINESCROLL, 0, intLinesToAdd)
I've changed it a little from my original code to make it easier for you to use...I hope it still works how it's suppose to. If not I think you get the jist of it.
JonnyT
Hi Jonny,
Thank you for sharing this with us.
Cor 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 program or something similar. If you are able to set focus to the form then use this method
richtextbox.sel ectionstart = richtextbox.tex tlength richtextbox.scr olltocaret()
I think that should do it...can't remember offhand...somet hing like that though.
Now if you cannot set the focus to the richtextbox then this will work well for you. When you want to display text in the richtext box use the .appendtext("so metext") method. That's what it's there for. Then you will need the sendmessage API...
Public Declare Function SendMessage Lib "user32.dll " Alias _ "SendMessag eA" (ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
and you will also need a couple constants...
Public Const EM_GETLINECOUNT = &HBA Public Const EM_LINESCROLL = &HB6
Now the way I do it works great for me....
I figure out how many line are in the richtextbox before adding my new text to it....I do that with the following...
Dim intLines As Integer = SendMessage(ric htextbox.Handle , EM_GETLINECOUNT , 0, 0)
then add your text
richtextbox.app endtext("your text here")
you will know how many lines to scroll down with by running the EM_GETLINECOUNT after you added your new text like so
Private intLinesToAdd as integer = (SendMessage(ri chtextbox.Handl e, EM_GETLINECOUNT , 0, 0) - intTotalLines)
Now that you know how many lines have been added...you know how many lines your scroll bar needs to scroll down. We use this line to scroll the scroll bar down...
SendMessage(ric htextbox.Handle , EM_LINESCROLL, 0, intLinesToAdd)
I've changed it a little from my original code to make it easier for you to use...I hope it still works how it's suppose to. If not I think you get the jist of it.
JonnyT This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Corepaul |
last post by:
I am new to Access 2000. My operating system is Windows 2000.
In the early stage of development I noticed something weird. On my form, I have
a Command Button named "btnAlbumUp". The first time that I reference this
button in VBA code, the Visual Basic Editor capitalizes the P changing
btnAlbumUp.SetFocus
to
|
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 text to a textbox ?
--
rgds, Wilfried
|
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...
|
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...
|
by: 23s |
last post by:
Is there any way I can send a vertical value to a form's scroll position?
I have a full-screen form that, at launch, contains an empty tab sheet.
At run time, the user can dynamically append a rich textbox to the tab
sheet. The rich textbox is placed at 0,0 (upper left corner) within the tab
sheet and is initially 1 "line" tall to accomodate the user's first line of
text.
The rich text box is, in actuality, a user control of mine...
| |
by: Al |
last post by:
Hello,
How can I turn off auto scrolling in RIchTextBox?
Thanks
|
by: Terry Olsen |
last post by:
The following code works fine in a TextBox for auto-scrolling:
If AutoScroll = True Then
txtChat.Select(txtChat.Text.Length, 0)
txtChat.ScrollToCaret()
End If
If I set AutoScroll to True then when text is appended to the TextBox, it
scrolls down to show it if necessary. When I set AutoScroll to false, it
doesn't scroll, allowing me to read whatever is currently visible.
|
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...
|
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....
|
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...
|
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,...
| |
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...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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...
|
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...
|
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();...
|
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...
| |
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...
| |