Mini UDF - buttons erstellen leicht gemacht

  • Hey Leute

    ich hatte grade ziemlich langeweile und weil ich es nervig finde immer komplizierte pixelwerte für den abstand zum Rand, für die Breite und für die Höhe zu bemessen hab ich mir gedacht ich schreib mal ein winziges UDFchen um mir das einfacher zu machen:D

    Spoiler anzeigen
    [autoit]

    #include <GuiConstantsEx.au3>
    Global $realleft,$realtop,$realwidth,$realheight
    #region Beispiel Anfang
    GUICreate("ButtonCreate Test", 190, 190)
    _buttonsetup(10, 10, 50, 50)
    $button1 = _buttoncreate("1", 1, 1, 1, 1)
    _buttoncreate("2", 2, 1, 1, 1)
    _buttoncreate("3", 3, 1, 1, 1)
    _buttoncreate("4", 1, 2, 2, 1)
    _buttoncreate("5", 3, 2, 1, 2)
    _buttoncreate("6", 1, 3, 2, 1)
    GUISetState()
    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $button1
    MsgBox(0, "", "hallo")
    EndSwitch
    WEnd
    #endregion Beispiel Ende
    ; #INDEX# =======================================================================================================================
    ; Title .........: StandartButton
    ; Language ......: English
    ; Description ...: Function: create buttons easily.
    ; Author(s) .....: DFPWare
    ; ===============================================================================================================================
    ; #CURRENT# =====================================================================================================================
    ;_buttoncreate
    ;_buttonsetup
    ; ===============================================================================================================================
    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _buttonsetup
    ; Description ...: sets the realwidth, -height, -left, -top for _buttoncreate
    ; Syntax.........: _buttonsetup($iVerticalSpace, $iHorizontalSpace, $iCellWidth, $iCellHeight)
    ; Parameters ....: $iHorizontalSpace - left distance to border
    ; $iVerticalSpace - top distance to border
    ; $iCellWidth - width of the button
    ; $iCellHeight - height of the button
    ; Return value(s): -
    ; Author ........: DFPWare
    ; Example .......: No
    ; ===============================================================================================================================
    Func _buttonsetup($iHorizontalSpace, $iVerticalSpace, $iCellWidth, $iCellHeight)
    $realleft = $iHorizontalSpace
    $realtop = $iVerticalSpace
    $realwidth = $iCellWidth
    $realheight = $iCellHeight
    EndFunc ;==>_buttonsetup
    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _buttoncreate
    ; Description ...: creates a button easily
    ; Syntax.........: _buttoncreate($Text,$left,$top,$width,$height)
    ; Parameters ....: $Text - Text on the button
    ; $left - left distance to border
    ; $top - top distance to border
    ; $width - width of the button
    ; $height - height of the button
    ; Return value(s): Control ID
    ; Author ........: DFPWare
    ; Example .......: No
    ; ===============================================================================================================================
    Func _buttoncreate($Text, $left, $top, $width, $height)
    Local $left1, $top1, $width1, $height1
    $retvar = GUICtrlCreateButton($Text, $realleft + (($realleft + $realwidth) * ($left - 1)), $realtop + (($realtop + $realheight) * ($top - 1)), $realwidth + (($realleft + $realwidth) * ($width - 1)), $realheight + (($realtop + $realheight) * ($height - 1)))
    Return $retvar
    EndFunc ;==>_buttoncreate

    [/autoit]

    PS: mit Beispiel;)

  • Für den Anfang zwar gut, aber noch sehr ausbaubedürftig:
    - sehr langer Text
    - eine startup-func um den width und height von 10 und 50 umzustellen

    MfG AntiSpeed

    Nur keine Hektik - das Leben ist stressig genug

  • So ich hoffe hiermit sind beide Probleme gelöst(auch wenn ich es seeeehr unübersichtlich finde):

    [autoit]

    Func _buttoncreate($Text,$left,$top,$width,$height)
    ;User Einstellungen:
    Local $realwidth = 50
    Local $realheight = 50
    Local $realleft = 10
    Local $realtop = 10
    ;User Einstellungen Ende
    Local $left1,$top1,$width1,$height1
    $retvar = GUICtrlCreateButton($Text,$realleft+(($realleft+$realwidth)*($left-1)),$realtop+(($realtop+$realheight)*($top-1)),$realwidth+(($realleft+$realwidth)*($width-1)),$realheight+(($realtop+$realheight)*($height-1)))
    Return $retvar
    EndFunc

    [/autoit]
  • DFPWare: AntiSpeed meinte wohl eher eine Funktion wie

    [autoit]

    Func SetupGrid($iCellWidth, $iCellHeight, $iHorizontalSpace, $iVerticalSpace)
    ...
    EndFunc

    [/autoit]


    Dann kann man am Anfang des Skripts einfach die Größe festlegen, ohne deine UDF anzufassen.
    Zusätzlich kannst du dann für jedes Steuerelement eine Funktion erstellen, die auf diese Werte zugreift.
    Die Idee ist aber wirklich gut.

  • Änder das mal so um (besserer Stil) :

    [autoit]

    Global $realleft,$realtop,$realwidth,$realheight ;das hier steht ganz anfang (nach den includes)
    Func _buttonsetup($iHorizontalSpace, $iVerticalSpace, $iCellWidth, $iCellHeight)
    $realleft = $iHorizontalSpace
    $realtop = $iVerticalSpace
    $realwidth = $iCellWidth
    $realheight = $iCellHeight
    EndFunc

    [/autoit]


    MfG AntiSpeed

    Nur keine Hektik - das Leben ist stressig genug