Aide pour positionner une région (GDI)

Résolu
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 - 26 mars 2009 à 00:44
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 - 26 mars 2009 à 10:41
Coucou,

2 petites questions.

1)
j'ai besoin d'une aide pour positionner une région autour d'un objet Label.
La region doit faire la taille de mon Label et l'entourer de 3 pixels (avec bout arrondi de 5).
Voici mon bout de code, je galère, merci.

    Dim hregion As Long
    Dim hbrush As Long
    
    With objFormHdc
        .AutoRedraw = True
        .ScaleMode = vbTwips
        .Cls

            hregion = CreateRoundRectRgn(lzX-3, lzY+3, lzWidth, lzHeight, 5, 5)
            hbrush = CreateSolidBrush(vbYellow)
            DeleteObject SelectObject(.hdc, hbrush)
            PaintRgn .hdc, hregion       
   End With

2)

Est t'il nécessaire de faire un DeleteObject sur le hregion ? Ça libérerai sa mémoire ?

3 réponses

Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
26 mars 2009 à 08:10
Private Declare Function CreateRoundRectRgn Lib "gdi32.dll" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long, ByVal X3 As Long, ByVal Y3 As Long) As Long
Private Declare Function CreateSolidBrush Lib "gdi32.dll" (ByVal crColor As Long) As Long
Private Declare Function DeleteObject Lib "gdi32.dll" (ByVal hObject As Long) As Long
Private Declare Function FillRgn Lib "gdi32.dll" (ByVal hdc As Long, ByVal hRgn As Long, ByVal hBrush As Long) As Long

Private Sub Form_Load()
Me.ScaleMode = vbPixels
End Sub

Private Sub Form_Paint()
Dim hRgn As Long
Dim hBrush As Long
hRgn = CreateRoundRectRgn(Label1.Left - 3, Label1.Top - 3, Label1.Left + Label1.Width + 5, Label1.Top + Label1.Height + 5, 5, 5)
hBrush = CreateSolidBrush(vbYellow)

FillRgn Me.hdc, hRgn, hBrush

DeleteObject hBrush
DeleteObject hRgn
End Sub
3
Renfield Messages postés 17287 Date d'inscription mercredi 2 janvier 2002 Statut Modérateur Dernière intervention 27 septembre 2021 74
26 mars 2009 à 08:04
comment sont valorisées lzX, lzY, lzWidth et lzHeight ?

Gaffe!

DeleteObject SelectObject(.hdc, hbrush)

ici, tu as détruit le hBrush d'origine...

ce n'est pas la bonne marche a suivre...

hbrush = CreateSolidBrush(vbYellow)
hBrush = SelectObject(.hdc, hbrush)

'# ici, hBrush contient l'ancien Brush, qu'il nous faut restaurer.

'# ici, on replace l'ancien brush, et on détruit le notre.
DeleteObject SelectObject(.hdc, hbrush)

et oui, il faut détruire ta région.
0
Duke49 Messages postés 552 Date d'inscription jeudi 12 octobre 2006 Statut Non membre Dernière intervention 24 janvier 2023 4
26 mars 2009 à 10:41
J'aurai gagné 2 heures si j'aurai posté avant
Grand merci [../auteur/RENFIELD/2359.aspx Renfield] !!!
0
Rejoignez-nous