473,698 Members | 2,508 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Hi all,

I'm using a multiline+scrol lbar 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 7308
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("user 32", CharSet=CharSet .Auto)]
static extern bool GetScrollRange( IntPtr hWnd, int nBar, out int lpMinPos,
out int lpMaxPos);

[DllImport("user 32", CharSet=CharSet .Auto)]
static extern IntPtr SendMessage(Int Ptr 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.Se lectionStart = RichTextBox1.Te xtLength + 1;
RichTextBox1.Ap pendText(string );
GetScrollRange( RichTextBox1.Ha ndle, SB_VERT, out min, out max);
SendMessage(Ric hTextBox1.Handl e, EM_SETSCROLLPOS , 0, new POINT(0, max -
RichTextBox1.He ight));
RichTextBox1.Up date();
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.AppendT ext(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
1667
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 tried selectionstart but it is not working. Any comments will be appreciated.
4
13559
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 scrollbar in firefox/netscape (not IE) , even though the text I have in the element does not exceed the bounds. The simple example below casues this behaviour. How do I fix this? <div style="overflow:auto; height:100px; width:100px;...
3
9896
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 that I can enable vertical or horizontal scrollbars for the textbox and their wrapping but thats it for modifications of the scrollbar.
1
15696
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 to it: TextBox1.Text = "Line 1\r\nLine 2"; The problem is that a vertical scrollbar is displayed
1
3843
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 has multiline textbox inserted. I need to force insert more and more row lines, the scrollbar of gridbox displayed. Is there any another good multiline textbox control column style? Thanks
1
3807
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 vertical scrollbar of a textbox all the way down (indicating that the user at least pretended to read all of the textbox's text). How can I monitor the scrollbar and know when it has reached the end? 2. My multiline textbox has VerticalScrollBar...
0
1370
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 top? (ie, so that you start at the top of the textbox and have to scroll down through it - it is happening the other way around at the moment). Ta
0
1083
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
1508
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 in the textbox the scrollbar goes up to the top of the textbox while the message is being shown in the bottom. So I wonder how you would do to make the scrollbar go down to the bottom when the user recieves a new message. Thanks in advance.
3
4671
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). The vertical scrollbar is flickering (moving up and down and the scrollbar "square" is starting big and shrinks when the TextBox is filled). Please note that every refresh more data is added to the TextBox, and nothing is taken out (Appending...
0
8612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9171
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9032
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8905
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8880
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6532
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4373
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3053
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 we have to send another system
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.