Inconsistent Results with RichTextBox ScrollToCaret

后端 未结 4 783
-上瘾入骨i
-上瘾入骨i 2020-12-20 16:18

I am working with a RichTextBox in C#. It exists on a TabPage. When the TabPage is selected, I aim to populate the RichTextBox, and scroll to the end. I have tried the sligh

4条回答
  •  清歌不尽
    2020-12-20 16:42

    I have the same problem, I guess a RTB is almost quite managed by Windows Messages so it sounds a bit like a rabbit warren. I don t know, therefore, the reason for the alternating output (but it has slightly a bug taste). I am concerned with this RTB.Scrolltocaret flickering output but in a VB program. Compliments for your drastic solution: It works perfectly.

    Should anyone encounter this anomaly in that programming environment, here's the VB code

    Imports System.Runtime.InteropServices
    Public Class Form
     _
    Public Shared Function SendMessage( _
    ByVal hWnd As IntPtr, _
    ByVal wMsg As Integer, _
    ByVal wParam As IntPtr, _
    ByVal lParam As IntPtr) As Integer
    End Function
    Const WM_SCROLL = 277
    Const SB_PAGEBOTTOM = 7
    Sub ScrollToBottom(ByVal RTBName As RichTextBox)
       SendMessage(RTBName.Handle, _
                   WM_SCROLL, _
                   SB_PAGEBOTTOM, _
                   IntPtr.Zero)
    End Sub 'then call ScrollToBottom instead of ScrollToCaret
    

提交回复
热议问题