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

Scroll after appendText in RichTextBox

P: n/a
Hi,

I am trying to find the command to scroll the richtextbox to the latest
appended string at the bottom. I have tried update, refresh and scroll to
caret but it does not seem to work

Thanks

Joey
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Joseph Lee wrote:
I am trying to find the command to scroll the richtextbox to the latest
appended string at the bottom. I have tried update, refresh and scroll to
caret but it does not seem to work


Hi Joseph,

it only works if the RTF-Box has the focus (and therefore a caret).

Is that is a problem for you here is a small workaround using WinAPI
SendMessage:

using System.Runtime.InteropServices;

[...]

//WinAPI-Declaration for SendMessage
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(
IntPtr window, int message, int wparam, int lparam);

const int WM_VSCROLL = 0x115;
const int SB_BOTTOM = 7;
private void button1_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < 100; i++)
{
//Let's add some text to the rtfbox
richTextBox1.Text += "Hallo Welt ";
}
//Scroll to the bottom, without focus
SendMessage(richTextBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
}

Cheers

Arne Janning
Nov 16 '05 #2

P: n/a
Yes, that was what I am searching for.
Thanks :)

Joey

"Arne Janning" <sp*****************@msn.com> wrote in message
news:#v**************@TK2MSFTNGP09.phx.gbl...
Joseph Lee wrote:
I am trying to find the command to scroll the richtextbox to the latest
appended string at the bottom. I have tried update, refresh and scroll to caret but it does not seem to work


Hi Joseph,

it only works if the RTF-Box has the focus (and therefore a caret).

Is that is a problem for you here is a small workaround using WinAPI
SendMessage:

using System.Runtime.InteropServices;

[...]

//WinAPI-Declaration for SendMessage
[DllImport("user32.dll")]
public static extern IntPtr SendMessage(
IntPtr window, int message, int wparam, int lparam);

const int WM_VSCROLL = 0x115;
const int SB_BOTTOM = 7;
private void button1_Click(object sender, System.EventArgs e)
{
for (int i = 0; i < 100; i++)
{
//Let's add some text to the rtfbox
richTextBox1.Text += "Hallo Welt ";
}
//Scroll to the bottom, without focus
SendMessage(richTextBox1.Handle, WM_VSCROLL, SB_BOTTOM, 0);
}

Cheers

Arne Janning

Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.