Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Scroll to bottom of Textbox

7 views
Skip to first unread message

Mel Weaver

unread,
Jun 23, 2004, 11:03:32 AM6/23/04
to
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel


John Wood

unread,
Jun 23, 2004, 11:07:55 AM6/23/04
to
Set the start of the seleciton to be the length of the text.

--
John Wood
EMail: first name, dot, second name at priorganize.com


"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message
news:%234MA%23KTWE...@tk2msftngp13.phx.gbl...

Shakir Hussain

unread,
Jun 23, 2004, 11:13:08 AM6/23/04
to
Try this

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

Shak.


"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message

news:#4MA#KTWEH...@tk2msftngp13.phx.gbl...

Nicholas Paldino [.NET/C# MVP]

unread,
Jun 23, 2004, 11:20:58 AM6/23/04
to
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]
- m...@spam.guard.caspershouse.com

"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message

news:%234MA%23KTWE...@tk2msftngp13.phx.gbl...

Shakir Hussain

unread,
Jun 23, 2004, 12:00:33 PM6/23/04
to
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 [.NET/C# MVP]" <m...@spam.guard.caspershouse.com> wrote in
message news:uXBWfXT...@TK2MSFTNGP11.phx.gbl...

Nicholas Paldino [.NET/C# MVP]

unread,
Jun 23, 2004, 2:59:29 PM6/23/04
to
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]
- m...@spam.guard.caspershouse.com

"Shakir Hussain" <sh...@fakedomain.com> wrote in message
news:usFT4sTW...@TK2MSFTNGP10.phx.gbl...

Shakir Hussain

unread,
Jun 23, 2004, 3:23:49 PM6/23/04
to
Thanks man,

Shak.


"Nicholas Paldino [.NET/C# MVP]" <m...@spam.guard.caspershouse.com> wrote in

message news:eb4gmRVW...@TK2MSFTNGP09.phx.gbl...

Shakir Hussain

unread,
Jun 23, 2004, 3:29:00 PM6/23/04
to
Nicholas,

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


Shak.


"Shakir Hussain" <sh...@fakedomain.com> wrote in message
news:usFT4sTW...@TK2MSFTNGP10.phx.gbl...

0 new messages