473,467 Members | 2,026 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Scroll to bottom of Textbox

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

Mel
Nov 16 '05 #1
7 69277
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:%2******************@tk2msftngp13.phx.gbl...
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel

Nov 16 '05 #2
Try this

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

Shak.
"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message
news:#4**************@tk2msftngp13.phx.gbl...
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel

Nov 16 '05 #3
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]
- mv*@spam.guard.caspershouse.com

"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel

Nov 16 '05 #4
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]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uX*************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel


Nov 16 '05 #5
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]
- mv*@spam.guard.caspershouse.com

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com> wrote in message news:uX*************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel



Nov 16 '05 #6
Thanks man,

Shak.
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:eb**************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Shakir Hussain" <sh**@fakedomain.com> wrote in message
news:us**************@TK2MSFTNGP10.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com> wrote

in
message news:uX*************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
> Hello,
> How do you scroll to the bottom of a multiline textbox in code?
>
> Mel
>
>



Nov 16 '05 #7
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:us**************@TK2MSFTNGP10.phx.gbl...
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]" <mv*@spam.guard.caspershouse.com> wrote in message news:uX*************@TK2MSFTNGP11.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Mel Weaver" <Mel@[remove spam]insdirect.com> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
Hello,
How do you scroll to the bottom of a multiline textbox in code?

Mel



Nov 16 '05 #8

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

Similar topics

4
by: Mad Scientist Jr | last post by:
I have a textbox that i am adding to (in codebehind of ASP.NET) and need to ensure that the focus is scrolled to the bottom of the textbox each time the page refreshes, and then set focus to a 2nd...
0
by: Alex Moskalyuk | last post by:
I am using System.Windows.Forms.TextBox to publish some real-time data that's coming off the external devices. My data is fed into the TextBox with proper precautions not to exceed the MaxSize...
1
by: JC | last post by:
I'm sure you've all seen the save scroll position from 4 guys from rolla which can be found here > http://aspnet.4guysfromrolla.com/articles/111704-1.aspx BUT try to get that to work AND still be...
3
by: Rob T | last post by:
I have a multiline textbox that shows a log. When I keep adding items to the textbox, I would like it to autoscroll to the bottom. I thought moving the cursor to the end would do it like (ie....
3
by: Rvo | last post by:
I have a userform which contains a textbox (System.Windows.forms.textbox) with multiline set to True. This box contains a certain number of characters which reach below the bottom of the box....
6
by: UJ | last post by:
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.
0
by: Rachel | last post by:
I am developing an application for Windows Mobile devices using C#. I have a form that has several controls (labels and textboxes that are dynamically created on opening the form) and a vertical...
0
by: Brian Keating | last post by:
Hi there, Does anyone know if i can determin if the scroll position is at the bottom of my textbox? I can get the scroll position fine, but how do i know if it's actually at the bottom? ...
1
by: NehaDas | last post by:
Hello Everyone ! Iam relatively new to .NET C# and m still in the process of exploring various options. Any help with regard to this query will be highly appreciated ... Iam working on an...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
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 ...

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.