Aligner un image sur un boutton

frk25 Messages postés 13 Date d'inscription samedi 24 mai 2003 Statut Membre Dernière intervention 31 mai 2005 - 29 juin 2004 à 14:46
ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 - 29 juin 2004 à 21:37
Bonjour à tous,

J'aimerais savoir si c'est possible de mettre un image aligner à gauche ou à droite d'un boutton de commande. Et si oui comment faire?

Merci à l'avance de votre aide !!! :)

3 réponses

ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
29 juin 2004 à 19:30
salut

pour cela il faut utiliser les apis :
getwindowlong pour obtenir le style actuel
setwindowlong pour ajout un autre style
invalidaterect pour mettre à jour le style

Private Const BS_BOTTOM As Long = &H800&
Private Const BS_LEFT As Long = &H100&
Private Const BS_RIGHT As Long = &H200&
Private Const BS_TOP As Long = &H400&

Private Const BS_CENTER As Long = &H300&
Private Const BS_VCENTER As Long = &HC00&

Private Const BS_LEFTTEXT As Long = &H20&
Private Const BS_RIGHTBUTTON As Long = BS_LEFTTEXT

'ajout perso
Private Const BS_NOALIGN As Long = Not (BS_BOTTOM + BS_CENTER + BS_LEFT + BS_LEFTTEXT + BS_RIGHT + BS_RIGHTBUTTON + BS_TOP + BS_VCENTER)

Private Const GWL_STYLE As Long = -16
Private Const GWL_EXSTYLE As Long = -20
Private Declare Function GetWindowLong Lib "user32.dll" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function InvalidateRect Lib "user32.dll" (ByVal hwnd As Long, ByVal lpRect As Long, ByVal bErase As Long) As Long

Private Sub Command1_Click()
Dim ret As Long

ret = GetWindowLong(Command1.hwnd, GWL_STYLE)
ret = SetWindowLong(Command1.hwnd, GWL_STYLE, (ret And BS_NOALIGN) Or BS_TOP Or BS_RIGHT)
InvalidateRect Command1.hwnd, 0&, 0&
End Sub

voilà

ShareVB
0
frk25 Messages postés 13 Date d'inscription samedi 24 mai 2003 Statut Membre Dernière intervention 31 mai 2005
29 juin 2004 à 20:10
Salut

J'avais trouver c'est commandes, mais il reste un petit problème, parce que la commande peut ajuster le style seulement pour le texte du boutton. Si l'on change la propriété Style du boutton pour le mettre à « Graphical» et qu'on ajoute une image, les fonctions API ne fonctionne plus, le texte ainsi que l'image reste toujours au même endroit.

Merci pour ton aide!!!
0
ShareVB Messages postés 2676 Date d'inscription vendredi 28 juin 2002 Statut Membre Dernière intervention 13 janvier 2016 26
29 juin 2004 à 21:37
salut

en essayant ca :
Private Const IMAGE_BITMAP As Long = 0
Private Const BM_SETIMAGE As Long = &HF7
Private Const BS_BITMAP As Long = &H80
Private Declare Function SendMessage Lib "user32.dll" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long

Private Sub Command1_Click()
Dim ret As Long

ret = GetWindowLong(Command1.hwnd, GWL_STYLE)
ret = SetWindowLong(Command1.hwnd, GWL_STYLE, (ret And BS_NOALIGN) Or BS_TOP Or BS_RIGHT Or BS_BITMAP)

SendMessage Command1.hwnd, BM_SETIMAGE, ByVal 0&, ByVal Command1.Picture.Handle

Command1.Refresh
End Sub

on s'apercois que soit on a du texte soit on a une image (au quel cas on peut définir l'alignement)
ou alors on met le style BS_OWNERDRAW et la c VB qui fait le dessin texte et image mais pas choix de l'alignement...

voilà

ShareVB
0
Rejoignez-nous