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 63
| Private Function GetFormImage(ByRef MonForm As Form) As Bitmap
' Mémorisation des boutons actifs et des couleurs de fond de plan
Dim MesBoutonsVisibles As New List(Of String)
Dim MesControlsCouleur As New Dictionary(Of String, Color)
For Each Contr As Control In MonForm.Controls
If TypeOf Contr Is Button And Contr.Visible = True Then
MesBoutonsVisibles.Add(Contr.Name)
' on rend le bouton invisible après l'avoir mémorisé
Contr.Visible = False
End If
Select Case True
' on rend la couleur blanche après l'avoir mémorisée
Case TypeOf Contr Is Label
MesControlsCouleur.Add(Contr.Name, Contr.BackColor)
Contr.BackColor = Color.White
Case TypeOf Contr Is DataGridView
?????????
End Select
Next
Dim MaCouleur As Color = MonForm.BackColor
MonForm.BackColor = Color.White
' On force le "redessin" du formulaire pour supprimer d'éventuelles traces du menu flottant
MonForm.Refresh()
' Récupère l'image du formulaire
Dim me_gr As Graphics = MonForm.CreateGraphics
' Make a Bitmap to hold the image.
Dim bm As New Bitmap(MonForm.ClientSize.Width, MonForm.ClientSize.Height, me_gr)
Dim bm_gr As Graphics = Graphics.FromImage(bm)
Dim bm_hdc As IntPtr = bm_gr.GetHdc
' Get the form's hDC. We must do this after
' creating the new Bitmap, which uses me_gr.
Dim me_hdc As IntPtr = me_gr.GetHdc
' BitBlt the form's image onto the Bitmap.
BitBlt(bm_hdc, 0, 0, MonForm.ClientSize.Width, MonForm.ClientSize.Height, me_hdc, 0, 0, SRCCOPY)
me_gr.ReleaseHdc(me_hdc)
bm_gr.ReleaseHdc(bm_hdc)
' remise en conformité des boutons et fond de plans
For Each Nom As String In MesBoutonsVisibles
MonForm.Controls(Nom).Visible = True
Next
For Each Contr As Control In MonForm.Controls
Select Case True
Case TypeOf Contr Is Label
Contr.BackColor = MesControlsCouleur(Contr.Name)
End Select
Next
MonForm.BackColor = MaCouleur
MonForm.Refresh()
' Return the result.
Return bm
End Function |
Partager