_GUICtrlCreate_MultiLineLabel

  • Hiho, ich weiß nicht ob es das bereits gibt, oder ob jemand es gebrauchen kann, aber mir persönlich ist es zu doof entweder viele einzelne Labels zu erstellen oder jedes mal ein Editfeld zu nutzen, also hab ich hier mal 2 kleine Funktionen zum erstellen von Mehrzeiligen Labels geschrieben. Wie gesagt, vielleicht kanns jemand gebrauchen ;)

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit]

    Dim $Lines[3]
    $Lines[0] = "Hi"
    $Lines[1] = "My Name is Hans"
    $Lines[2] = "The L stands for Danger!"

    [/autoit] [autoit][/autoit] [autoit]

    #Region ### START Koda GUI section ### Form=
    $Form1 = GUICreate("Form1", 625, 445, 193, 125)
    $Color = GUICtrlCreateButton("Color", 8, 376, 75, 25, 0)
    $ML_Control = _GUICtrlCreate_MultiLineLabel($Lines, 8, 8)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Color
    _GUICtrl_MultiLineLabel_SetColor($ML_Control, 0xFF89FF, 0x000000)
    EndSwitch
    WEnd
    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GUICtrlCreate_MultiLineLabel
    ; Description ...: Creates a MultiLineLabel in a GUI
    ; Parameters.....: $Lines = Array of Lines to Create
    ; ...............: $x & y = X and Y Position of the MultiLineLabel to Create
    ; ...............: $dist = The distance between the Labels (15-20 is recommend for normal textformat)
    ; ...............: $Font = The Fontstyle to use in the Control (As String)
    ; ...............: $Front & $BackColor = The Front and Background Color beeing used in the Control | Set this to 'trans' for an transparent color
    ; Author ........: Felix Lehmann alias eF_Hacks (http://www.autoit.de)
    ; Modified.......: If you modify this Script, please enter your name here
    ; Remarks .......: Change the states of the single controls by using ControlSet..
    ; Related .......: -
    ; Link ..........; http://www.autoit.de
    ; ===============================================================================================================================
    Func _GUICtrlCreate_MultiLineLabel($Lines, $x, $y, $dist = 15, $Font = 'MS Sans Serif', $FrontColor = 0x000000, $BackColor = 0xF0F0F0)
    If Not IsArray($Lines) Then SetError(-1, 0, -1)
    If Not IsString($Font) Then SetError(-2, 0, -2)
    Local $Labels[1]
    $y =- $dist
    For $x = 0 To UBound($Lines) - 1
    $y += $dist
    $Labels[$x] = GUICtrlCreateLabel($Lines[$x], $x, $y)
    Switch $FrontColor
    Case 'trans'
    GUICtrlSetColor($Labels[$x], $GUI_BKCOLOR_TRANSPARENT)
    Case Else
    GUICtrlSetColor($Labels[$x], $FrontColor)
    EndSwitch
    Switch $BackColor
    Case 'trans'
    GUICtrlSetBkColor($Labels[$x], $GUI_BKCOLOR_TRANSPARENT)
    Case Else
    GUICtrlSetBkColor($Labels[$x], $BackColor)
    EndSwitch
    $iUbound = UBound($Labels)
    ReDim $Labels[$iUbound + 1]
    Next
    Return $Labels
    EndFunc ;==>_GUICtrlCreate_MultiLineLabel

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _GUICtrl_MultiLineLabel_SetColor
    ; Description ...: Sets the Color's of a previous created MultiLineLabel
    ; Parameters.....: $Control = The Handle of the Control returned from _GUICtrlCreate_MultiLineLabel
    ; ...............: $Front & $BackColor = The Front and Background Color beeing used in the Control
    ; Author ........: Felix Lehmann alias eF_Hacks (http://www.autoit.de)
    ; Modified.......: If you modify this Script, please enter your name here
    ; Remarks .......: Change the states of the single controls by using ControlSet..
    ; Related .......: -
    ; Link ..........; http://www.autoit.de
    ; ===============================================================================================================================
    Func _GUICtrl_MultiLineLabel_SetColor($Control, $Foreground, $Background)
    If Not IsArray($Control) Then SetError(-1, 1, -1)
    Local $iUbound = UBound($Control)
    For $x = 0 To $iUbound -1
    GUICtrlSetColor($Control[$x], $Foreground)
    GUICtrlSetBkColor($Control[$x], $Background)
    Next
    Return 1
    EndFunc ;==>_GUICtrl_MultiLineLabel_SetColor

    [/autoit]
  • Guck mal hier:

    Spoiler anzeigen
    [autoit]

    #include <GUIConstantsEx.au3>
    #include <StaticConstants.au3>
    #include <WindowsConstants.au3>

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    $Form1 = GUICreate("Form1", 625, 445, 193, 125)
    $Color = GUICtrlCreateButton("Color", 8, 376, 75, 25, 0)
    $ML_Control = GUICtrlCreateLabel("Hi" & @CRLF & "My Name is Hans" & @CRLF & "The L stands for Danger!", 8, 8)
    GUISetState(@SW_SHOW)
    #EndRegion ### END Koda GUI section ###

    [/autoit] [autoit][/autoit] [autoit]

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $Color
    GUICtrlSetColor($ML_Control, 0xFF89FF)
    GUICtrlSetBkColor($ML_Control, 0x000000)
    EndSwitch
    WEnd

    [/autoit]

    Sowas ist doch schon längst mit den Standardfunktionen möglich!

  • Ach.. ich wollt auch mal ne unnötige UDF schreiben ;)
    Edit: Sicher geht es so wie du's gemacht hast, aber ab ganzen Texten würde mir das zu doof werden :D

    Oder willst du damit ne readme in ein GUI einbauen? xD

    Ganz nebenbei lässt die Funktion nett mit _FileReadToArray kombinieren ^^

    Einmal editiert, zuletzt von eF_Hacks (15. September 2009 um 16:12)

  • Also deine Idee finde ich nicht schlecht. Könnte sie öfter mal gebrauchen, da ich bei der Version von Deepred schon öfter verzweifelt bin nach 5 Sätzen.