473,729 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scroll to the end of a text box.

UJ
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.
Feb 1 '06 #1
6 8803
UJ wrote:
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.


The only way I've found, is to use Windows messages ... Not nice but the only
solution I ever found.
using System.Runtime. InteropServices ;

[DllImport("user 32.dll", EntryPoint="Sen dMessageA")]
static extern uint SendMessage(Sys tem.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

const int WM_VSCROLL = 0x115;
const int SB_BOTTOM = 7;

TextBox report ;

void printError(stri ng msg)
{
...
// auto scroll to bottom of text control
SendMessage( this.report.Han dle, WM_VSCROLL, SB_BOTTOM, 0);
}
cyrille
Feb 1 '06 #2
Jeff,

Here's a very simple technique that works with a RichTextBox; should
work with a regular TextBox also:

RichTextBox.Sel ect(RichTextBox .TextLength, 0);
RichTextBox.Scr ollToCaret();

Hope this helps,
John Bendiksen

# Cyrille37 # wrote:
UJ wrote:
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.


The only way I've found, is to use Windows messages ... Not nice but the only
solution I ever found.
using System.Runtime. InteropServices ;

[DllImport("user 32.dll", EntryPoint="Sen dMessageA")]
static extern uint SendMessage(Sys tem.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

const int WM_VSCROLL = 0x115;
const int SB_BOTTOM = 7;

TextBox report ;

void printError(stri ng msg)
{
...
// auto scroll to bottom of text control
SendMessage( this.report.Han dle, WM_VSCROLL, SB_BOTTOM, 0);
}
cyrille


Feb 1 '06 #3
Jeff,

Here's a very simple technique that works with a RichTextBox; should
work with a regular TextBox also:

RichTextBox.Sel ect(RichTextBox .TextLength, 0);
RichTextBox.Scr ollToCaret();

Hope this helps,
John Bendiksen

# Cyrille37 # wrote:
UJ wrote:
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.


The only way I've found, is to use Windows messages ... Not nice but the only
solution I ever found.
using System.Runtime. InteropServices ;

[DllImport("user 32.dll", EntryPoint="Sen dMessageA")]
static extern uint SendMessage(Sys tem.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

const int WM_VSCROLL = 0x115;
const int SB_BOTTOM = 7;

TextBox report ;

void printError(stri ng msg)
{
...
// auto scroll to bottom of text control
SendMessage( this.report.Han dle, WM_VSCROLL, SB_BOTTOM, 0);
}
cyrille


Feb 1 '06 #4
JohnAtAphelion wrote:
Jeff,

Here's a very simple technique that works with a RichTextBox; should
work with a regular TextBox also:

RichTextBox.Sel ect(RichTextBox .TextLength, 0);
RichTextBox.Scr ollToCaret();
hello,

I'm afraid that not the right solution.

Before found the solution with Windows Message, it was the first thing I've used.
But it does not work it the control has not got focus.


Hope this helps,
John Bendiksen

# Cyrille37 # wrote:
UJ wrote:
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.


The only way I've found, is to use Windows messages ... Not nice but the only
solution I ever found.
using System.Runtime. InteropServices ;

[DllImport("user 32.dll", EntryPoint="Sen dMessageA")]
static extern uint SendMessage(Sys tem.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

const int WM_VSCROLL = 0x115;
const int SB_BOTTOM = 7;

TextBox report ;

void printError(stri ng msg)
{
...
// auto scroll to bottom of text control
SendMessage( this.report.Han dle, WM_VSCROLL, SB_BOTTOM, 0);
}
cyrille


Feb 2 '06 #5
Cyrille37,

Not sure why it didn't work for you...

In my 'process control' type application, I am updating 4 RichTextBoxes
continuously with status information (probably similar to Jeff's
situation). None of them ever have focus; in fact, they are not even
selectable by the user. They all scroll properly to the last added
text using this technique.

Happy coding,
John Bendiksen

Feb 2 '06 #6
On Wed, 1 Feb 2006 11:41:13 -0500, "UJ" <fr**@nowhere.c om> wrote:
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.


Set HideSelection to false.

Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 4 '06 #7

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

Similar topics

2
1810
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB code provided on the website. Once I have this example running correctly, I will need to use the concept in a more complex project. The code I am using involves an webform and an htc file. The code for ScrollPos.htc (which is located in a folder...
2
9929
by: abs | last post by:
How to detect that user started to scroll the page ? Separately vertical and horizontal scroll. Is it possible ? Regards, ABS
4
134389
by: justdummy | last post by:
Hi, I am struggling with a problem for sometimes. I need to display a table in a html and if the height of the table goes beyond 200 px then a vertical scrollbar should alone appear without any horizontal scroll bar. If the height of the table is less than 200 px then no scroll bars should appear. Here is the html below. I tried to wrap the table around a <div> tag but its doesn't work out as the scroll bar appear close to the scroll bar...
7
5112
by: J-T | last post by:
My website is fine when it is viewed in 1280 by 1024 pixel ,but in smaller resulotions there is a horizontal scrollbar down the page.How can I set it to be viewed the same for all resulotions? Thanks
2
17366
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...
1
7179
by: Ima Loozer | last post by:
On one of my forms I have a text box sized and shaped to display multiple lines. The max content of the field is such that the text box may display less than all of the data in the field. Therefore I have the vertical scroll bar enabled for the text box object. When a user is working with this form and that text box has focus, I would like the wheel mouse to scroll the content of that field rather than scroll through the records on the...
6
10704
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the VScrollBar and set it as follow: m_vScrollBar.Minimum = -19602; m_vScrollBar.Maximum = 0; m_vScrollBar.SmallChange = 1; m_vScrollBar.LargeChange = 1089; m_vScrollBar.Value = m_vScrollBar.Maximum; The scroll bar is set to start from the bottom.
2
1978
by: Tripmaker | last post by:
I'm trying to set u a scroll bar to be attached to the text area with a border around it. The problem is my text area appears as a small screen above the bordered/scrolled text area. Here is my code: notesText = new JTextArea(); notesText.setLineWrap(true); notesText.setWrapStyleWord(true); JScrollPane scroll = new JScrollPane(notesText); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
1
2307
by: crazy works | last post by:
hello guys, i have problem in the scroll bar on my css code , i am trying to use that css menu from that link http://www.cssplay.co.uk/menus/slide_fly.html it actually works very good but i want to use it on the right side from my site not in the left side so i edited the ccs code but the scroll bar didnt works really good ,it scroll so much on the left side , here is screen shot http://qbael.com/upload/mn/screen.JPG and here is my full...
3
2598
by: PrabodhanP | last post by:
I have CSS based mouseover scrolling for divContent embeded in my webpage.It works fine in IE,but not working in mozilla-FF. It is located at the location.. http://www.integrityads.net/fashions/collection.htm Also it is not resolution compatible,i.e. alignment totally messed up when i increased the resolution.Please suggest. Code is as follows:- <HTML><HEAD> <meta http-equiv="Content-Language" content="en-us"> <TITLE>Collections</TITLE>...
0
8930
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
9428
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
9218
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
8163
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...
0
4536
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...
0
4799
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3244
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
2699
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2171
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.