Scroll to bottom of Textbox

  • Thread starter Thread starter Mel Weaver
  • Start date Start date
Try this

this.textBox1.SelectionStart = textBox1.Text.Length;
this.textBox1.ScrollToCaret();

Shak.
 
Mel,

You can use the previously posted responses if you don't mind the caret
position being moved. If you do not want to change the caret position, then
you will have to send the WM_VSCROLL message to the textbox, like so:

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

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam,
IntPtr lParam);

// Scroll to the bottom, but don't move the caret position.
SendMessage(textBox1.Handle, WM_VSCROLL, (IntPtr) SB_BOTTOM, IntPtr.Zero);

Hope this helps.
 
Nicholas,

do you know how to disable the context menu of displayed vertical and
horizontal scroll bar in the textbox?. How to insert my own menu there
overiding scrollbar menu?

Shak.


Nicholas Paldino said:
Mel,

You can use the previously posted responses if you don't mind the caret
position being moved. If you do not want to change the caret position, then
you will have to send the WM_VSCROLL message to the textbox, like so:

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

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam,
IntPtr lParam);

// Scroll to the bottom, but don't move the caret position.
SendMessage(textBox1.Handle, WM_VSCROLL, (IntPtr) SB_BOTTOM, IntPtr.Zero);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mel Weaver said:
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel
 
Shakir,

I think that it can be done, but it would take a LOT of work. I was
able to get the menu to not come up, but unfortunately, it messed with how
the cursor was displayed, as well as the scrolling.

What it involves is intercepting the WM_NCHITTEST message. This is sent
to the control to query what elements are where. If the result indicated
that the hittest was for the vertical scrollbar, then I changed it to
indicate that it was part of the client. This caused the context menu to
pop up, but not much else.

I imagine it is possible by installing hooks for the current thread. It
would involve determining when the WM_NCHITTEST message is sent. Once you
do that, you would have to have the mouse event hook cancel out the sending
of the event to the textbox, if it was determined that the menu was going to
be shown.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Shakir Hussain said:
Nicholas,

do you know how to disable the context menu of displayed vertical and
horizontal scroll bar in the textbox?. How to insert my own menu there
overiding scrollbar menu?

Shak.


message news:[email protected]...
Mel,

You can use the previously posted responses if you don't mind the caret
position being moved. If you do not want to change the caret position, then
you will have to send the WM_VSCROLL message to the textbox, like so:

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

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam,
IntPtr lParam);

// Scroll to the bottom, but don't move the caret position.
SendMessage(textBox1.Handle, WM_VSCROLL, (IntPtr) SB_BOTTOM, IntPtr.Zero);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mel Weaver said:
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel
 
Thanks man,

Shak.


Nicholas Paldino said:
Shakir,

I think that it can be done, but it would take a LOT of work. I was
able to get the menu to not come up, but unfortunately, it messed with how
the cursor was displayed, as well as the scrolling.

What it involves is intercepting the WM_NCHITTEST message. This is sent
to the control to query what elements are where. If the result indicated
that the hittest was for the vertical scrollbar, then I changed it to
indicate that it was part of the client. This caused the context menu to
pop up, but not much else.

I imagine it is possible by installing hooks for the current thread. It
would involve determining when the WM_NCHITTEST message is sent. Once you
do that, you would have to have the mouse event hook cancel out the sending
of the event to the textbox, if it was determined that the menu was going to
be shown.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Shakir Hussain said:
Nicholas,

do you know how to disable the context menu of displayed vertical and
horizontal scroll bar in the textbox?. How to insert my own menu there
overiding scrollbar menu?

Shak.


message news:[email protected]...
Mel,

You can use the previously posted responses if you don't mind the caret
position being moved. If you do not want to change the caret
position,
then
you will have to send the WM_VSCROLL message to the textbox, like so:

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

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam,
IntPtr lParam);

// Scroll to the bottom, but don't move the caret position.
SendMessage(textBox1.Handle, WM_VSCROLL, (IntPtr) SB_BOTTOM, IntPtr.Zero);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel
 
Nicholas,

Quickly noticed that the scrollbar of the preview window of outlook express
shows the custom context menu.


Shak.


Shakir Hussain said:
Nicholas,

do you know how to disable the context menu of displayed vertical and
horizontal scroll bar in the textbox?. How to insert my own menu there
overiding scrollbar menu?

Shak.


message news:[email protected]...
Mel,

You can use the previously posted responses if you don't mind the caret
position being moved. If you do not want to change the caret position, then
you will have to send the WM_VSCROLL message to the textbox, like so:

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

[DllImport("user32.dll", CharSet=CharSet.Auto)]
private static extern int SendMessage(IntPtr hWnd, int wMsg, IntPtr wParam,
IntPtr lParam);

// Scroll to the bottom, but don't move the caret position.
SendMessage(textBox1.Handle, WM_VSCROLL, (IntPtr) SB_BOTTOM, IntPtr.Zero);

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Mel Weaver said:
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel
 
Back
Top