Re: RichTextBox Display the latest line
From: Herfried K. Wagner [MVP] (hirf-spam-me-here_at_gmx.at)
Date: 07/14/04
- Next message: Shakir Hussain: "Re: How to highlight programmatically selected item in listview"
- Previous message: Herfried K. Wagner [MVP]: "Re: How to add a custom control to a standalone .exe file application (no extra .dll)"
- In reply to: dale zhang: "RichTextBox Display the latest line"
- Next in thread: Muthu: "Re: RichTextBox Display the latest line"
- Messages sorted by: [ date ] [ thread ]
Date: 15 Jul 2004 01:13:08 +0200
* zhangd@tycoelectronics.com (dale zhang) scripsit:
> I am using a richtextbox to display multiple lines of received data.
> When we receive more lines of data, we could use scrollbar to see
> them. But how could we display the latest data all the time (i mean
> that data will move up automatically if there are more lines to
> display)?
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.
-- Herfried K. Wagner [MVP] <URL:http://dotnet.mvps.org/>
- Next message: Shakir Hussain: "Re: How to highlight programmatically selected item in listview"
- Previous message: Herfried K. Wagner [MVP]: "Re: How to add a custom control to a standalone .exe file application (no extra .dll)"
- In reply to: dale zhang: "RichTextBox Display the latest line"
- Next in thread: Muthu: "Re: RichTextBox Display the latest line"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|