Hi, wie kann ich einen Button erstellen wo ein Bild und Text drauf ist? Also so:
| ------- |
| Bild |
| ------ |
Bespielbutton
Hi, wie kann ich einen Button erstellen wo ein Bild und Text drauf ist? Also so:
| ------- |
| Bild |
| ------ |
Bespielbutton
Hi,
im englischen Forum gibt es hierzu einige individuelle Ansätze, die Du per Suche bestimmt findest. Vielleicht finde ich welche und trage sie nach ...Jan
z.B.http://www.autoitscript.com/forum/index.php?showtopic=55334&hl=button+image+caption Die einfachste aller Lösung wäre den Text in die Grafik/Icon einzubeziehen .....
Hi,
zB so:
#include <GuiConstants.au3>
$Gui = GUICreate("Test", 72, 90, -1, -1, -1)
$icon = GUICtrlCreateIcon("shell32.dll", -202, 19, 19, 32, 32)
GUICtrlSetState(-1, $GUI_DISABLE)
$button = GUICtrlCreateButton("Test", 10, 10, 52, 70, BitOR($WS_CLIPSIBLINGS, $BS_BOTTOM, $BS_MULTILINE))
GUICtrlSetFont(-1, 8, 700)
GUISetState(@SW_SHOW, $Gui)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $button
EndSelect
WEnd
Weiterhin viel Erfolg !
So ist es besser, da Disabled nicht benötigt wird -> Farbe bleibt erhalten.
#include <GuiConstants.au3>
[/autoit] [autoit][/autoit] [autoit]$Gui = GUICreate("Test", 100, 90, -1, -1, -1)
$icon = GUICtrlCreateIcon("shell32.dll", -202, 19, 19, 32, 32,0) ; --> die letzte 0, damit kein Klick-Ereignis ausgelöst wird (Click-Through)
;~ GUICtrlSetState(-1, $GUI_DISABLE) ; -> wird wegen oberem Kommentar nicht benötigt.
$button = GUICtrlCreateButton("Test", 10, 10, 52, 70, BitOR($WS_CLIPSIBLINGS, $BS_BOTTOM, $BS_MULTILINE))
GUICtrlSetFont(-1, 8, 700)
GUISetState(@SW_SHOW, $Gui)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $button
MsgBox(0, '', "ButtonClick")
EndSelect
WEnd
@progandy
gut zu wissen
auch von mir Danke
Ich komme damit irgenwie nicht klar... kann mir das einer an diesem Beispiel anpassen?
global $Button2 = GUICtrlCreateButton ("", 55,1,55,55, $BS_ICON)
GUICtrlSetImage (-1, "icons.dll", 9)
o_O Damit wirst du es wohl hinbekommen
#include <GuiConstants.au3>
[/autoit] [autoit][/autoit] [autoit]$Gui = GUICreate("Test", 200, 240, -1, -1, -1)
$button = _IconButton("test","shell32.dll", -202,10,10,40,55)
$button2 = _IconButton("test","shell32.dll", -202,10,70,100,120)
;~ GUICtrlSetState(-1, $GUI_DISABLE) ; -> wird wegen oberem Kommentar nicht benötigt.
GUICtrlSetFont(-1, 8, 700)
GUISetState(@SW_SHOW, $Gui)
While 1
$msg = GUIGetMsg()
Select
Case $msg = $GUI_EVENT_CLOSE
Exit
Case $msg = $button
_IconButtonSetIco($button,"shell32.dll",-1*Random(100,223,1))
Case $msg = $button2
_IconButtonSetIco($button2,"shell32.dll",-1*Random(100,223,1))
EndSelect
WEnd
; Gibt die Ctrl ID des Buttons zurück. Für Das Icon zu ändern müssen die unten stehenden Funktionen verwendet werden
Func _IconButton($text,$dll,$iconID,$x,$y,$w = 50,$h = 60)
Local $space, $spaceh = 9
If $w < 40 Then $w = 40
Local $space = Floor(($w-32)/2)
If $h < 55 Then $h = 55
If $h < 60 Then $spaceh = 5
GUICtrlCreateIcon($dll, $iconID, $x+$space, $y+$spaceh, 32, 32,0) ; --> die letzte 0, damit kein Klick-Ereignis ausgelöst wird (Click-Through)
Return GUICtrlCreateButton($text, $x, $y, $w, $h, BitOR($WS_CLIPSIBLINGS, $BS_BOTTOM, $BS_MULTILINE))
EndFunc
Func _IconButtonSetIco($btn,$dll, $iconID=0)
GUICtrlSetImage($btn-1,$dll, $iconID)
EndFunc
Func _IconButtonDelete($btn)
GUICtrlDelete($btn-1)
GUICtrlDelete($btn)
EndFunc
Func _IconButtonIconSetStyle($btn,$style,$styleEx)
GUICtrlSetStyle($btn-1,$style,$styleEx)
EndFunc
;Damit können dann alle GUICtrl-Funktionen auf das Icon angewendet werden
Func _IconButtonIconGetCtrlID($btn)
Return $btn-1
EndFunc
kann man nicht ne jpg oder ähnliches als bild benutzen. krieg das iwie nicht hin
gruß
Also ich habe das hier mal gefunden und gespeichert:
Das eigentliche Script:
#include "_MouseEvents.au3"
GuiCreate('Test', 500, 110)
[/autoit] [autoit][/autoit] [autoit]$picture1 = GuiCtrlCreatePic(@ScriptDir & '\Exit - Normal.bmp', 30, 30, 80, 50)
$picture2 = GuiCtrlCreatePic(@ScriptDir & '\Exit - Normal.bmp', 110, 30, 80, 50)
$picture3 = GuiCtrlCreatePic(@ScriptDir & '\Exit - Normal.bmp', 190, 30, 80, 50)
$picture4 = GuiCtrlCreatePic(@ScriptDir & '\Exit - Normal.bmp', 270, 30, 80, 50)
$picture5 = GuiCtrlCreatePic(@ScriptDir & '\Exit - Normal.bmp', 350, 30, 80, 50)
_MouseCreatePicButton($picture1, "Exit - Normal.bmp", "Exit - Hover.bmp", "Exit - Pressed.bmp")
_MouseCreatePicButton($picture2, "Exit - Normal.bmp", "Exit - Hover.bmp", "Exit - Pressed.bmp")
_MouseCreatePicButton($picture3, "Exit - Normal.bmp", "Exit - Hover.bmp", "Exit - Pressed.bmp")
_MouseCreatePicButton($picture4, "Exit - Normal.bmp", "Exit - Hover.bmp", "Exit - Pressed.bmp")
_MouseCreatePicButton($picture5, "Exit - Normal.bmp", "Exit - Hover.bmp", "Exit - Pressed.bmp")
AdLibEnable("_MouseCheckEvents", 50) ; we can use a bigger interval, at least in this example
[/autoit] [autoit][/autoit] [autoit]GuiSetState()
[/autoit] [autoit][/autoit] [autoit]While 1
Switch GuiGetMsg()
Case -3
Exit
EndSwitch
Wend
Die _MouseEvents.au3 kommt ins gleiche Verzeichnis und die sieht so aus:
#cs ====================================================================================================================================
_MouseEvents.au3
Description: Detection of mouse events for controls
AutoIt Version: 3.2.2.0
Author: alc? Heavily based on code by marfdaman (Marvin) and RazerM
post: http://www.autoitscript.com/forum/index.php?showtopic=28714
#ce ====================================================================================================================================
[/autoit] [autoit][/autoit] [autoit]#include <Array.au3>
[/autoit] [autoit][/autoit] [autoit]#include-once
[/autoit] [autoit][/autoit] [autoit]Local $HoverList[1][2]
; List of controls to be checked, see _MouseAddCtrl()
Local $HoverActive = 0
; Index of the control being hovered when executing the previous check
; (0 if the mouse was not hovering any control in the list)
Local $Found = 0
; Index of the control detected as been hovered in the current check
; (0 if the mouse is not hovering any control in the list)
Local $PressActive = 0
; Index of the control detected with mouse down in the previous check
; (0 if not detected)
Local $Pressed = 0
; Index of the control detected with mouse down in the current check
; (0 if not detected)
Global Enum $MouseEvent_Enter, $MouseEvent_Exit, $MouseEvent_Down, $MouseEvent_Up
; These values indicate the type of event that took place, see _MouseAddCtrl()
#cs ===============================================================================
_MouseAddCtrl($_ControlID, $_Functioname)
Description: Create or modify the list of controls to be checked
Parameter(s): $_ControlID -> ControlID of control to be checked
$_Functioname -> Function to be called when an event will be detected for this control
prototype of function declaration: Func Button1_MouseEvents($_ControlID, $EventType)
$_ControlID is the ControlID of the control
$EventType is the event type identifier, see the Enum
If value $_ControlID is already in the list, its function name is redefined. This allow to change the reaction of th buttons if neede
If $_Functioname = "", we do nothing (the control is "check disabled")
$_ControlID = 0 is a special case. For this value, the function passed is the function to be called when the app
detects a click outside his window. This function will not receive any arguments (no sense, no need)
The default value for this function name is "", which means do nothing, just return from the check function
Requirement: Array.au3
Return Value(s): None
#ce ===============================================================================
Func _MouseAddCtrl($_ControlID, $_Functioname)
If $_ControlID = 0 Then
$HoverList[0][1] = $_Functioname
Else
For $i = 1 to UBound($HoverList) - 1
If $HoverList[$i][0] = $_ControlID Then
$HoverList[$i][1] = $_Functioname
Return
EndIf
Next
ReDim $HoverList[UBound($HoverList) + 1][2]
$HoverList[UBound($HoverList) - 1][0] = $_ControlID
$HoverList[UBound($HoverList) - 1][1] = $_Functioname
EndIf
EndFunc
#cs ================================================================================================================================
_MouseCheckEvents()
Description: Checks whether the mouse cursor is hovering or going down/up over any of the defined controls.
If a control has matched, the function defined for this control is called
(see _MouseAddCtrl())
If we have 2 controls too close, and the mouse hovers from one to another in the same check, both
functions are called, in the correct order
To be called from AdLibEnable()
Parameter(s): None
Requirement: None
Return Value(s): None
Notes: Since this function is designed to be called from AdLibEnable(), and because of his nature, it should not return
an error
Errors in the control's functions should be treated there
The only posible error here is if we call a control's function that doesn't exist, which will be almost always
a design time error
To intercept very fast clicks, set the AdlibEnabled() interval to 100-150
For normal clicks, you can leave the default value
#ce ===============================================================================================================================
Func _MouseCheckEvents()
; we should get an array
$HoverData = GUIGetCursorInfo()
If Not IsArray($HoverData) Then
; click outside the app window
If $HoverList[0][1] <> "" Then
Call($HoverList[0][1])
EndIf
Return
EndIf
; check if the mouse is hovering or pressed over any control of the list
$Found = 0
$Pressed = 0
For $i = 1 To UBound($HoverList)-1
If $HoverData[4] = $HoverList[$i][0] Then
; the mouse is over a control of the list, grab its number
$Found = $i
If $HoverData[2] Then
; the mouse is pressed over a control of the list, grab its number
$Pressed = $i
EndIf
ExitLoop
EndIf
Next
; Determine if the mouse button state has changed since the last check
; $PressActive=0 And $Pressed=1 => MouseDown
; $PressActive=1 And $Pressed=0 => MouseUp
; $PressActive = $Pressed => no cambió
If $PressActive <> 0 Then
If $Pressed <> $PressActive Then
Call($HoverList[$PressActive][1], $HoverList[$PressActive][0], $MouseEvent_Up)
If $Pressed <> 0 Then
Call($HoverList[$Pressed][1], $HoverList[$Pressed][0], $MouseEvent_Down)
EndIf
$PressActive = $Pressed
EndIf
ElseIf $Pressed <> 0 Then
Call($HoverList[$Pressed][1], $HoverList[$Pressed][0], $MouseEvent_Down)
$PressActive = $Pressed
EndIf
; Determine if the mouse entered and/or leaved a control since the last check
; $HoverActive=0 And $Found=1 => Enter
; $HoverActive=1 And $Found=0 => Exit
; $HoverActive = $Found => no entró ni salió
If $HoverActive <> 0 Then
If $Found <> $HoverActive Then
Call($HoverList[$HoverActive][1], $HoverList[$HoverActive][0], $MouseEvent_Exit)
If $Found <> 0 Then
Call($HoverList[$Found][1], $HoverList[$Found][0], $MouseEvent_Enter)
EndIf
$HoverActive = $Found
EndIf
ElseIf $Found <> 0 Then
Call($HoverList[$Found][1], $HoverList[$Found][0], $MouseEvent_Enter)
$HoverActive = $Found
EndIf
SetError(0) ; jic
EndFunc
#cs ----------------------------------------------------------------------------
_MouseCreatePicButton($_ControlID, $_Image, $_ImageH, $_ImageP, $_Functionname = "_MousePicButtonEvents")
Description: Adds a control to the check list and create "pointers" to the images needed to
represent the states of the control
"Pointers" consist of environment variables named after the control ID and the
different states
Parameter(s): $_ControlID -> ID given to the control when it was created
$_Image -> Filename of the image for the normal state
$_ImageH -> Filename of the image for the hovered state
$_ImageP -> Filename of the image for the pressed state
$_Functionname -> function to be called when a mouse event is detected
for this control
The default function just change the picture according to the event
(see below)
Use this argument if you need another behaivor
Requirement: None
Return Value(s): None
Note: As "pointers" are created by EnvSet(), they are automatically destroyed
upon exit
#ce ----------------------------------------------------------------------------
Func _MouseCreatePicButton($_ControlID, $_Image, $_ImageH, $_ImageP, $_Functionname = "_MousePicButtonEvents")
; Add to check list
_MouseAddCtrl($_ControlID, $_Functionname)
; Create the "pointers" to the images for this button
EnvSet($_ControlID & "N", $_Image)
EnvSet($_ControlID & "H", $_ImageH)
EnvSet($_ControlID & "P", $_ImageP)
EndFunc
#cs ----------------------------------------------------------------------------
_MousePicButtonEvents($_ControlID, $_Event)
Description: Changes the picture of a control when an event is detected
To be called from _MouseCheckEvents() when an event is detected for
one of the "buttons" created with _MouseCreatePicButton
Normally, this function will be called automatically
Parameter(s): $_ControlID -> ID of the control that raised the event
$_Event -> The type of event (a value from the Enum, see above)
Requirement: None
Return Value(s): None
Note: The function asumes the pictures exist
#ce ----------------------------------------------------------------------------
Func _MousePicButtonEvents($_ControlID, $_Event)
Switch $_Event
Case $MouseEvent_Exit
GUICtrlSetImage($_ControlID, EnvGet($_ControlID & "N"))
Case $MouseEvent_Down
GUICtrlSetImage($_ControlID, EnvGet($_ControlID & "P"))
Case Else
GUICtrlSetImage($_ControlID, EnvGet($_ControlID & "H"))
EndSwitch
EndFunc
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit];--------------------------
[/autoit] [autoit][/autoit] [autoit];~ #cs ----------------------------------------------------------------------------
[/autoit] [autoit][/autoit] [autoit];~ #ce ----------------------------------------------------------------------------
;~ Func ()
;~
;~
;~ EndFunc
Zum Testen einfach noch drei BMP's mit den Dateinamen
Exit - Hover.bmp
Exit - Normal.bmp
Exit - Pressed.bmp
und der Größe 80 x 50 Pikel erstellen. Größe gem. Script.
Habe leider die Bilder nicht mit auf meinen Stick gespeichert, aber das sollte kein Problem sein sich mal schnell diese drei BMP's zu erstellen.
Gruß, Crazy-A
Ohne PicHover, also normaler Button mit Bild, das sich nicht ändert reicht die UDF von oben und das unten.
; Gibt die Ctrl ID des Buttons zurück. Für Das Icon zu ändern müssen die unten stehenden Funktionen verwendet werden
Func _IconButtonBmp($text,$dll,$x,$y,$w = 50,$h = 60,$imageLeft=9,$imageTop=9,$imageW=32,$imageH=32)
If $w < 40 Then $w = 40
If $h < 55 Then $h = 55
GUICtrlCreatePic($dll,$x+$imageLeft,$y+$imageTop,$imageW,$imageH)
GUICtrlSetState(-1,$GUI_DISABLE)
Return GUICtrlCreateButton($text, $x, $y, $w, $h, BitOR($WS_CLIPSIBLINGS, $BS_BOTTOM, $BS_MULTILINE))
EndFunc
habs jetzt auch hinbekommen^^
danke euch beiden
gruß:)
Your information allowed me to finally make a image clickable by a user! Been looking for this feature for over a month now.
Many thanks