By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,908 Members | 2,041 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,908 IT Pros & Developers. It's quick & easy.

Scroll to the end of a text box.

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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("user32.dll", EntryPoint="SendMessageA")]
static extern uint SendMessage(System.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

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

TextBox report ;

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

P: n/a
Jeff,

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

RichTextBox.Select(RichTextBox.TextLength, 0);
RichTextBox.ScrollToCaret();

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("user32.dll", EntryPoint="SendMessageA")]
static extern uint SendMessage(System.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

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

TextBox report ;

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


Feb 1 '06 #3

P: n/a
Jeff,

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

RichTextBox.Select(RichTextBox.TextLength, 0);
RichTextBox.ScrollToCaret();

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("user32.dll", EntryPoint="SendMessageA")]
static extern uint SendMessage(System.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

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

TextBox report ;

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


Feb 1 '06 #4

P: n/a
JohnAtAphelion wrote:
Jeff,

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

RichTextBox.Select(RichTextBox.TextLength, 0);
RichTextBox.ScrollToCaret();
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("user32.dll", EntryPoint="SendMessageA")]
static extern uint SendMessage(System.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

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

TextBox report ;

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


Feb 2 '06 #5

P: n/a
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

P: n/a
On Wed, 1 Feb 2006 11:41:13 -0500, "UJ" <fr**@nowhere.com> 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 discussion thread is closed

Replies have been disabled for this discussion.