473,406 Members | 2,439 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to keep a multiline + vertical scrollbar textbox on the LAST line?

Hi all,

I'm using a multiline+scrollbar textbox to log output as my program
runs. Basically, I pass a reference to the class instance that's
currently doing stuff, and the instance can tack on whatever it needs
to the text property.

Initially I had trouble with getting the textbox to refresh
as-the-program ran, but the TextBox.Refresh() method took care of that
for me.

Now the problem is that the output lines run longer than the visible
textbox - so the most recent messages can't be seen until the routine
is completely finished.

I would like the textbox to "auto-scroll-to-the-bottom-line" every time
I tack a new line into it. How can I do this?

Thanks for any ideas,

cdj

Jan 25 '07 #1
2 7292
I had to do this once a long time back. After searching and searching the
only solution I could find was to do what is posted below. Also, I ended up
using a RichTextBox as it's buffer would hold more data.

I don't claim to know if this is the best way, but it was the only way I
could find via google and asking around a couple years ago, and it ended up
working.
I had to p/invoke 2 win32 functions and create a point class:

[DllImport("user32", CharSet=CharSet.Auto)]
static extern bool GetScrollRange(IntPtr hWnd, int nBar, out int lpMinPos,
out int lpMaxPos);

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

class POINT
{
public int x;
public int y;
public POINT()
{
}
public POINT(int x, int y)
{
this.x = x;
this.y = y;
}
}

Then, using my RichTextBox as below in a function where I passed in a
string:

RichTextBox1.SelectionStart = RichTextBox1.TextLength + 1;
RichTextBox1.AppendText(string);
GetScrollRange(RichTextBox1.Handle, SB_VERT, out min, out max);
SendMessage(RichTextBox1.Handle, EM_SETSCROLLPOS, 0, new POINT(0, max -
RichTextBox1.Height));
RichTextBox1.Update();
Hope that helps.
Jan 26 '07 #2


On Jan 25, 4:16 pm, "Pete" <m...@ineedhelp.orgwrote:
I had to p/invoke 2 win32 functions and create a point class:
Thanks for the suggestion. After digging around, I found that using
TextBox.AppendText(string text), rather than TextBox.Text += text gives
the auto-scroll-to-bottom I needed - and much easier than going down to
the WinAPI.

Jan 26 '07 #3

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

Similar topics

2
by: pothik05 | last post by:
I have a multiline textbox (with scrollbar) on a form. I add lines to the textbox at runtime. If the number of lines crosses the visible area in the textbox, I want the scrollbar to scrolldown. I...
4
by: Rob T. | last post by:
I am using a div tag to make an element that contains some text. I have specified overflow: auto; in my stylesheet. If I use font-size/line-height to specify the font information I get a vertical...
3
by: buht | last post by:
Hello Everyone, Fairly new to c# here and have a question regarding scrollbars, particularly a vertical scrollbar. It looks like my options are restricted for the textbox scrollbars being...
1
by: Olav Tollefsen | last post by:
I have added a MultiLine TextBox to my aspx page: <asp:TextBox ID="TextBox1" runat="server" BorderStyle="None" ReadOnly="True" TextMode="MultiLine"></asp:TextBox> Then I add two lines of text...
1
by: ABC | last post by:
I tried KDNGrid's (www.knowdotnet.com) Multiline textbox column style for datagrid. It is very good but has some bug on wrong handle datagrid height that cannot display the scrollbar when a row...
1
by: Flack | last post by:
Hey guys, I have two questions regarding the vertical srollbar of a multiline textbox. 1. I have an "Ok" button that is initially disabled. I want it to be enabled when the user scrolls the...
0
by: charlie1 | last post by:
I have a text box that has a vertical scrollbar on the right hand side - whever the textbox is opened, the vertical scrollbar defaults to the bottom. How can I make the scrollbar default to the...
0
by: shihab | last post by:
Hai all, How to keep a multiline + vertical scrollbar textbox on the LAST line in Asp.net with c# ,when refreshing page? thanx, sihab
3
by: PatruX | last post by:
Hi, I have a multilined textbox in a chat program, this textbox recieves incoming messages and shows them to the user. The problem is with the vertical scrollbar. Every time a new message appears...
3
by: Avi | last post by:
Hi all, I have a web page with Multiline TextBox. Every 3 seconds I refresh the page and display all received messages in this TextBox. When the TextBox is updated (The Text property is set). ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.