473,785 Members | 2,325 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Scroll to the end of a text box.

UJ
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.
Feb 1 '06 #1
6 8807
UJ wrote:
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.


The only way I've found, is to use Windows messages ... Not nice but the only
solution I ever found.
using System.Runtime. InteropServices ;

[DllImport("user 32.dll", EntryPoint="Sen dMessageA")]
static extern uint SendMessage(Sys tem.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

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

TextBox report ;

void printError(stri ng msg)
{
...
// auto scroll to bottom of text control
SendMessage( this.report.Han dle, WM_VSCROLL, SB_BOTTOM, 0);
}
cyrille
Feb 1 '06 #2
Jeff,

Here's a very simple technique that works with a RichTextBox; should
work with a regular TextBox also:

RichTextBox.Sel ect(RichTextBox .TextLength, 0);
RichTextBox.Scr ollToCaret();

Hope this helps,
John Bendiksen

# Cyrille37 # wrote:
UJ wrote:
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.


The only way I've found, is to use Windows messages ... Not nice but the only
solution I ever found.
using System.Runtime. InteropServices ;

[DllImport("user 32.dll", EntryPoint="Sen dMessageA")]
static extern uint SendMessage(Sys tem.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

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

TextBox report ;

void printError(stri ng msg)
{
...
// auto scroll to bottom of text control
SendMessage( this.report.Han dle, WM_VSCROLL, SB_BOTTOM, 0);
}
cyrille


Feb 1 '06 #3
Jeff,

Here's a very simple technique that works with a RichTextBox; should
work with a regular TextBox also:

RichTextBox.Sel ect(RichTextBox .TextLength, 0);
RichTextBox.Scr ollToCaret();

Hope this helps,
John Bendiksen

# Cyrille37 # wrote:
UJ wrote:
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.


The only way I've found, is to use Windows messages ... Not nice but the only
solution I ever found.
using System.Runtime. InteropServices ;

[DllImport("user 32.dll", EntryPoint="Sen dMessageA")]
static extern uint SendMessage(Sys tem.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

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

TextBox report ;

void printError(stri ng msg)
{
...
// auto scroll to bottom of text control
SendMessage( this.report.Han dle, WM_VSCROLL, SB_BOTTOM, 0);
}
cyrille


Feb 1 '06 #4
JohnAtAphelion wrote:
Jeff,

Here's a very simple technique that works with a RichTextBox; should
work with a regular TextBox also:

RichTextBox.Sel ect(RichTextBox .TextLength, 0);
RichTextBox.Scr ollToCaret();
hello,

I'm afraid that not the right solution.

Before found the solution with Windows Message, it was the first thing I've used.
But it does not work it the control has not got focus.


Hope this helps,
John Bendiksen

# Cyrille37 # wrote:
UJ wrote:
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.


The only way I've found, is to use Windows messages ... Not nice but the only
solution I ever found.
using System.Runtime. InteropServices ;

[DllImport("user 32.dll", EntryPoint="Sen dMessageA")]
static extern uint SendMessage(Sys tem.IntPtr hwnd, uint wMsg, uint wParam, uint
lParam);

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

TextBox report ;

void printError(stri ng msg)
{
...
// auto scroll to bottom of text control
SendMessage( this.report.Han dle, WM_VSCROLL, SB_BOTTOM, 0);
}
cyrille


Feb 2 '06 #5
Cyrille37,

Not sure why it didn't work for you...

In my 'process control' type application, I am updating 4 RichTextBoxes
continuously with status information (probably similar to Jeff's
situation). None of them ever have focus; in fact, they are not even
selectable by the user. They all scroll properly to the last added
text using this technique.

Happy coding,
John Bendiksen

Feb 2 '06 #6
On Wed, 1 Feb 2006 11:41:13 -0500, "UJ" <fr**@nowhere.c om> wrote:
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.


Set HideSelection to false.

Oz
--
A: Because it fouls the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Feb 4 '06 #7

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

Similar topics

2
1810
by: GrantS | last post by:
I am trying to convert the VB.Net code example povided by http://authors.aspalliance.com/JimRoss/Articles/MaintainScrollPos.aspx into C# (ASP.Net)without success. No errors are thrown in the VB code provided on the website. Once I have this example running correctly, I will need to use the concept in a more complex project. The code I am using involves an webform and an htc file. The code for ScrollPos.htc (which is located in a folder...
2
9931
by: abs | last post by:
How to detect that user started to scroll the page ? Separately vertical and horizontal scroll. Is it possible ? Regards, ABS
4
134390
by: justdummy | last post by:
Hi, I am struggling with a problem for sometimes. I need to display a table in a html and if the height of the table goes beyond 200 px then a vertical scrollbar should alone appear without any horizontal scroll bar. If the height of the table is less than 200 px then no scroll bars should appear. Here is the html below. I tried to wrap the table around a <div> tag but its doesn't work out as the scroll bar appear close to the scroll bar...
7
5114
by: J-T | last post by:
My website is fine when it is viewed in 1280 by 1024 pixel ,but in smaller resulotions there is a horizontal scrollbar down the page.How can I set it to be viewed the same for all resulotions? Thanks
2
17384
by: JonnyT | last post by:
I searched high and low for an answer on how to auto scroll a richtextbox and now I finally have it. Since it took me a while to get a good efficient way of doing it that didn't require focus to the control or the scrolltocaret method I decided that it would be worth posting to anyone who might have similar concerns. For the record this works well in an environment where you cannot have focus going to the richtextbox....such as a chat...
1
7186
by: Ima Loozer | last post by:
On one of my forms I have a text box sized and shaped to display multiple lines. The max content of the field is such that the text box may display less than all of the data in the field. Therefore I have the vertical scroll bar enabled for the text box object. When a user is working with this form and that text box has focus, I would like the wheel mouse to scroll the content of that field rather than scroll through the records on the...
6
10706
by: =?Utf-8?B?U2hhcm9u?= | last post by:
I'm using the VScrollBar and set it as follow: m_vScrollBar.Minimum = -19602; m_vScrollBar.Maximum = 0; m_vScrollBar.SmallChange = 1; m_vScrollBar.LargeChange = 1089; m_vScrollBar.Value = m_vScrollBar.Maximum; The scroll bar is set to start from the bottom.
2
1987
by: Tripmaker | last post by:
I'm trying to set u a scroll bar to be attached to the text area with a border around it. The problem is my text area appears as a small screen above the bordered/scrolled text area. Here is my code: notesText = new JTextArea(); notesText.setLineWrap(true); notesText.setWrapStyleWord(true); JScrollPane scroll = new JScrollPane(notesText); scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
1
2311
by: crazy works | last post by:
hello guys, i have problem in the scroll bar on my css code , i am trying to use that css menu from that link http://www.cssplay.co.uk/menus/slide_fly.html it actually works very good but i want to use it on the right side from my site not in the left side so i edited the ccs code but the scroll bar didnt works really good ,it scroll so much on the left side , here is screen shot http://qbael.com/upload/mn/screen.JPG and here is my full...
3
2601
by: PrabodhanP | last post by:
I have CSS based mouseover scrolling for divContent embeded in my webpage.It works fine in IE,but not working in mozilla-FF. It is located at the location.. http://www.integrityads.net/fashions/collection.htm Also it is not resolution compatible,i.e. alignment totally messed up when i increased the resolution.Please suggest. Code is as follows:- <HTML><HEAD> <meta http-equiv="Content-Language" content="en-us"> <TITLE>Collections</TITLE>...
0
9481
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
10341
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
10155
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
10095
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
9954
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...
0
6741
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
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.