Imports System.Windows.Forms
Imports System.Drawing
Namespace Utilities
Public Class Win32
Public Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (ByVal hDestDC As Integer, ByVal x As Integer, _
ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hSrcDC As Integer, _
ByVal xSrc As Integer, ByVal ySrc As Integer, _
ByVal dwRop As Integer) As Integer
Public Declare Function GetWindowDC Lib "user32" Alias "GetWindowDC" (ByVal hwnd As Integer) As Integer
Public Declare Function ReleaseDC Lib "user32" Alias "ReleaseDC" (ByVal hwnd As Integer, ByVal hdc As Integer) As Integer
Public Const SRCCOPY As Integer = &HCC0020
End Class
Public Class ControlFunctions
Public Shared Function CreateBitmap(ByVal Control As Control) As Bitmap
If Control.Width > 0 AndAlso Control.Height > 0 Then
Dim gDest As Graphics
Dim hdcDest As IntPtr
Dim hdcSrc As Integer
Dim hWnd As Integer = Control.Handle.ToInt32
CreateBitmap = New Bitmap(Control.Width, Control.Height)
gDest = gDest.FromImage(CreateBitmap)
hdcSrc = Win32.GetWindowDC(hWnd)
hdcDest = gDest.GetHdc
Win32.BitBlt(hdcDest.ToInt32, 0, 0, Control.Width, Control.Height, hdcSrc, 0, 0, Win32.SRCCOPY)
gDest.ReleaseHdc(hdcDest)
Win32.ReleaseDC(hWnd, hdcSrc)
End If
End Function
End Class
Public Class UpdateFlashPreventer
Sub New()
End Sub
Sub New(ByVal controlToUpdate As Control)
_control = controlToUpdate
End Sub
Private _control As Control
Private pic As PictureBox
Public Property Control() As Control
Get
Return _control
End Get
Set(ByVal Value As Control)
_control = Value
End Set
End Property
Private _inUpdate As Boolean
Public ReadOnly Property InUpdate() As Boolean
Get
Return _inUpdate
End Get
End Property
Public Sub BeginUpdate()
If Not _control Is Nothing Then
If Not _control.Parent Is Nothing Then
_inUpdate = True
pic = New PictureBox
pic.Size = _control.Size
pic.Image = ControlFunctions.CreateBitmap(_control)
pic.Location = _control.Location
pic.Anchor = _control.Anchor
pic.Dock = _control.Dock
_control.Parent.Controls.Add(pic)
pic.BringToFront()
pic.Refresh()
End If
End If
End Sub
Public Sub EndUpdate()
If pic Is Nothing AndAlso Not _control Is Nothing Then
If TypeOf _control.Parent.Controls(0) Is PictureBox Then
pic = CType(_control.Parent.Controls(0), PictureBox)
End If
End If
If Not _control Is Nothing AndAlso Not _control.Parent Is Nothing AndAlso Not pic Is Nothing Then
pic.SendToBack()
_control.Parent.Controls.Remove(pic)
pic.Dispose()
pic = Nothing
Me._inUpdate = False
End If
End Sub
End Class