1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
Private mBln_Griser As Boolean = False
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
mBln_Griser = Not mBln_Griser
Me.InvalidateAll(Me)
End Sub
Private Sub InvalidateAll( _
ByVal objControl As Control _
)
For Each objChildCtrl As Control In objControl.Controls
InvalidateAll(objChildCtrl)
Next
objControl.Invalidate()
End Sub
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
AddHandlerControlPaint(Me)
End Sub
Protected Overrides Sub OnClosed(ByVal e As System.EventArgs)
MyBase.OnClosed(e)
RemoveHandlerControlPaint(Me)
End Sub
Private Sub AddHandlerControlPaint( _
ByVal objControl As Control _
)
For Each objChildCtrl As Control In objControl.Controls
AddHandlerControlPaint(objChildCtrl)
Next
AddHandler objControl.Paint, AddressOf Control_Paint
End Sub
Private Sub RemoveHandlerControlPaint( _
ByVal objControl As Control _
)
For Each objChildCtrl As Control In objControl.Controls
RemoveHandlerControlPaint(objChildCtrl)
Next
RemoveHandler objControl.Paint, AddressOf Control_Paint
End Sub
Protected Sub Control_Paint( _
ByVal sender As Object, _
ByVal e As System.Windows.Forms.PaintEventArgs _
)
If mBln_Griser Then GriserEcran(e.Graphics, sender)
End Sub
Private Sub GriserEcran( _
ByVal objGraphics As Graphics, _
ByVal objControl As Control _
)
Dim objBitmap As Image = New Bitmap(objControl.Width, objControl.Height, Imaging.PixelFormat.Format32bppArgb)
Dim objGraph As Graphics = Graphics.FromImage(objBitmap)
objGraph.Clear(Color.Black)
Dim objColorMatrix As New Imaging.ColorMatrix
objColorMatrix.Matrix33 = 0.25
Dim objImageAttributes As New Imaging.ImageAttributes
objImageAttributes.SetColorMatrix( _
objColorMatrix _
)
objGraphics.DrawImage( _
objBitmap, objControl.ClientRectangle, _
0, 0, objBitmap.Width, objBitmap.Height, GraphicsUnit.Pixel, objImageAttributes _
)
End Sub |
Partager