1. Herfried K. Wagner’s VB.Any
  2. .NET
  3. Frequently Asked Questions

Preventing controls from redrawing

Preventing controls from redrawing
<URL:https://dotnet.currifex.org/dotnet/faqs/disableredrawing/en/>
----------------------------------------------------------------------------

Preventing controls from redrawing

Disable redrawing of a control:

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

Private Const WM_SETREDRAW As Int32 = &HB
.
.
.
With Me.RichTextBox1
    SendMessage( _
        .Handle, WM_SETREDRAW, New IntPtr(CInt(False)), IntPtr.Zero _
    )

    ' Manipulate contents.
    For i As Integer = 0 To .TextLength
        .SelectionStart = i
        .SelectionLength = 1
        .SelectionColor = Color.Red
        .SelectionFont = New Font(.SelectionFont, FontStyle.Bold)
    Next i
    SendMessage( _
        .Handle, WM_SETREDRAW, New IntPtr(CInt(True)), IntPtr.Zero _
    )
    .Refresh()
End With
///