VB Implementation Force Redraw window a certain area

Source: Internet
Author: User

This example demonstrates how to force a redraw of an area of a window. Sometimes this is needed, such as when you use the LockWindowUpdate API function to speed up the data loading of a control.

Create a new project and add a module with the following code:

Private Type RECT
Left as Long
Top as Long
Right as Long
Bottom as Long
End Type
Private Type Pointapi
X as Long
Y as Long
End Type
Private Declare Function getwindowrect Lib "user32" (ByVal hWnd as Long, lprect as RECT) as Long
Private Declare Function getclientrect Lib "user32" (ByVal hWnd as Long, lprect as RECT) as Long
Private Declare Function invalidaterect Lib "user32" (ByVal hWnd as Long, lprect as RECT, ByVal berase as long) as long
Private Declare Function screentoclient Lib "user32" (ByVal hWnd as Long, lppoint as POINTAPI) as Long
Public Sub Repaintwindow (ByRef objthis as Object, Optional ByVal bclientareaonly as Boolean = True)
Dim TR as RECT
Dim TP as Pointapi
If (bclientareaonly) Then
GetClientRect Objthis.hwnd, TR
Else
GetWindowRect Objthis.hwnd, TR
tp.x = TR.LEFT:TP.Y = Tr.top
ScreenToClient Objthis.hwnd, TP
Tr.left = Tp.x:tr.top = Tp.y
tp.x = TR.RIGHT:TP.Y = Tr.bottom
ScreenToClient Objthis.hwnd,
TP tr.right = Tp.x:tr.bottom = Tp.y
End If
InvalidateRect Objthis.hwnd, TR, 1
End Sub
Place a button and list box on the form. Make the list box large enough to observe the effect. Then add the following code:
Private Sub Command1_Click ()
Repaintwindow List1
End Sub
Private Sub Form_Load ()
Dim I as Long
For i = 1 to 200
List1.AddItem "TestItem" & I
Next I
End Sub

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.