Code : Tout sélectionner
Enumeration
#button1
#button2
#button3
#button4
#button5
EndEnumeration
icon2 = ExtractIcon_(0,"Shell32.dll", 131)
icon3 = ExtractIcon_(0,"Shell32.dll", 55)
icon4 = LoadIcon_(0,#IDI_ASTERISK)
icon5 = LoadIcon_(0,#IDI_EXCLAMATION)
FontID0 = LoadFont(0,"Courier New", 12)
FontID1 = LoadFont(1,"Comic sans MS", 15,#PB_Font_Underline )
Procedure Bticotext(idbt,x.f,y.f,larg.f,haut.f,iconid,txt$,font,coultext,coulbout)
Define hautimg.f,largimg.f,imgze.f
CI=CreateImage(idbt, larg, haut)
hdc=StartDrawing(ImageOutput(idbt))
SelectObject_(hdc, font)
; possibilité de régler l'espace entre lettres
; SetTextCharacterExtra_(hdc, 1)
; Dessine l'image
Box(0,0,larg,haut,coulbout)
GetIconInfo_(iconid,@info.ICONINFO)
hautimg=info\xHotspot
largimg=info\yHotspot
If hautimg > haut-2: hautimg=hautimg/10*8: EndIf
If largimg > larg-2: largimg=largimg/10*8: EndIf
If hautimg < (haut-2)/2: hautimg=hautimg*1.8:largimg=largimg*1.8: EndIf
dbimg=5 ; distance de bord gauche/image
cthimg=(haut-hautimg)/2 ;centre l'image en hauteur
DrawImage(iconid,dbimg,cthimg,largimg,hautimg)
; Position du texte
DrawingMode(#PB_2DDrawing_Transparent)
hautxt=TextHeight(txt$)
largtxt=TextWidth (txt$)
ditxt=largimg+dbimg+3 ; distance image/texte
ctxt=(haut-hautxt)/2 ; centre le text en hauteur
DrawText(ditxt,ctxt,txt$,coultext)
StopDrawing ()
ButtonImageGadget(idbt,x,y,larg,haut,ImageID(idbt))
EndProcedure
If OpenWindow(0,0,0,820,600,"Test Boutons")
Bticotext(#button1,10,100,190,36,icon2,"Premier Bouton",FontID0,#Blue,$F1F1F1)
Bticotext(#button2,220,100,150,36,icon3,"2em Bouton",FontID1 ,#Red,$DAE1DE)
Bticotext(#button3,10,150,150,36,icon4,"3em Bouton",FontID0,#Blue,$5AB5BD)
Bticotext(#button4,220,150,160,72,icon5,"4em Bouton",FontID1,#Gray,$E4BBAF)
Bticotext(#button5,10,250,160,72,icon4,"5em Bouton",FontID1,#Black,GetSysColor_(#COLOR_BTNFACE))
Repeat
;Debug #PB_gadget_Default
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
Select EventGadget()
Case #button1
;votre code
MessageBeep_(#MB_ICONEXCLAMATION)
;MessageBeep_(#MB_ICONASTERISK)
EndSelect
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
DeleteObject_(font)
End