473,395 Members | 1,393 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,395 software developers and data experts.

How to scroll a multiline System.windows.forms.textbox down to the last line through code?

Rvo
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. During runtime of my program I add
text at the end of the contents of the textbox. I want to display the last
lines of the box at all times.
However, the textbox always displays the first x characters.

Can I scroll down to the end of the content of the textbox after each
addition of text to the box?

Kind regards,

Romain
Nov 20 '05 #1
3 22732
TextBox1.Text += "Test the quick brown fox" & vbCrLf

TextBox1.Select(TextBox1.Text.Length - 1, 0)

TextBox1.ScrollToCaret()
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Rvo" <romainvoes@{DoesNotLikeSpam}vlaamsparlement.be> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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. During runtime of my program I add text at the end of the contents of the textbox. I want to display the last
lines of the box at all times.
However, the textbox always displays the first x characters.

Can I scroll down to the end of the content of the textbox after each
addition of text to the box?

Kind regards,

Romain

Nov 20 '05 #2
Rvo
Thanks a lot One Handed Man,

Does it nicely.

Romain
"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> schreef in
bericht news:eN**************@TK2MSFTNGP09.phx.gbl...
TextBox1.Text += "Test the quick brown fox" & vbCrLf

TextBox1.Select(TextBox1.Text.Length - 1, 0)

TextBox1.ScrollToCaret()
--

OHM ( Terry Burns )
. . . One-Handed-Man . . .

Time flies when you don't know what you're doing

"Rvo" <romainvoes@{DoesNotLikeSpam}vlaamsparlement.be> wrote in message
news:%2******************@TK2MSFTNGP10.phx.gbl...
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. During runtime of my program I

add
text at the end of the contents of the textbox. I want to display the last lines of the box at all times.
However, the textbox always displays the first x characters.

Can I scroll down to the end of the content of the textbox after each
addition of text to the box?

Kind regards,

Romain


Nov 20 '05 #3
* "Rvo" <romainvoes@{DoesNotLikeSpam}vlaamsparlement.be> scripsit:
Can I scroll down to the end of the content of the textbox after each
addition of text to the box?


My FAQ:

When using a RichTextBox control for displaying logging information, it is
useful to scroll the recently added line into view. There are two ways to
accomplish this:

\\\
Private Const WM_VSCROLL As Int32 = &H115
Private Const SB_BOTTOM As Int32 = 7

Private Declare Auto Function SendMessage Lib "user32.dll" ( _
ByVal hwnd As IntPtr, _
ByVal wMsg As Int32, _
ByVal wParam As Int32, _
ByVal lParam As Int32 _
) As Int32

Private Sub AddLine(ByVal Destination As RichTextBox, ByVal Text As String)
With Destination
.AppendText(Text & ControlChars.NewLine)
SendMessage(Destination.Handle, WM_VSCROLL, SB_BOTTOM, 0)
End With
End Sub
///

- or -

\\\
Dim ctr As Control = Me.ActiveControl
With Me.RichTextBox1
.Focus()
.AppendText("Hello World!")
.ScrollToCaret()
End With
ctr.Focus()
///

The 2nd solution has a side-effect: Setting the focus to the
RichTextBox control may raise validation events.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 20 '05 #4

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

Similar topics

18
by: jrhoads23 | last post by:
Hello, I am trying to find a way to tell if an .NET windows forms Button (System.Windows.Forms.Button) is "depressed" (pushed down). For my application, I can not use a check box control set to...
2
by: fperfect13 | last post by:
Hi, I have the folowing exception Exception : System.NullReferenceException: Object reference not set to an instance of an object. 00000019 3:30:48 PM at...
3
by: Ivan | last post by:
Hi, how to filter out non-digit chars when user writes text to System.Windows.Forms.TextBox? Thanks, Iavmn
5
by: Richard Lionheart | last post by:
Hi All, I tried creating a C# Form using Petzold's "Programming MS Windows with C#" guidance. He recommended using the namespace System.Windows.Forms. However, VS.NET claims "the type or...
2
by: John Espinosa | last post by:
I am trying to use a message box in a console application. But when I import system.windows.forms in the top line I get an error: Namespace or type 'Forms' for the Imports 'System.Windows.Forms'...
2
by: Nabeel Moeen | last post by:
Hi, the foillowing line returns a null value Type.GetType("System.Windows.Forms.TextBox") why is that so ... and what should i do if i need to compare if the control is a textbox or not? ...
4
by: Mo | last post by:
Hi, I am writing a console application to send a key sequence to an old clunky application on a regular interval using the windows scheduler. I can get it to work if it is a windows form...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...
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...
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...

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.