Texte positionieren

  • Hallo,

    ich krieg das einfach nicht hin.

    1. Ich öffne meine Text-Gui (Text öffnen im Menü)
    2. Dort trage ich den Text ein und übergebe ihn an die Form
    3. Ich positioniere den Text nun mit den Pfeiltasten

    Das Problem:

    Es kommen weitere Texte hinzu.
    Diese müsste ich aber nachträglich einzeln anwählen können und in der Farbe/Größe ändern.

    Spoiler anzeigen
    [autoit]


    #include <Array.au3>
    #include <GUIConstantsEx.au3>
    #include <gdiplus.au3>
    #include <misc.au3>
    #include <WindowsConstants.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>

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

    $x = 140
    $y = 110
    Global $afont, $mnText, $Label, $mnFarbe, $mnpFarbe
    $Form1 = GUICreate("Form1", 800, 600)

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

    _Menue()

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

    $Form2 = GUICreate("Texte", 625, 443, 192, 124)
    $Edit1 = GUICtrlCreateEdit("", 32, 40, 545, 321, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL))
    GUICtrlSetData(-1, "")
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $btnMnText = GUICtrlCreateButton("Text auf Form", 400, 376, 179, 41, $WS_GROUP)
    GUISetState(@SW_SHOW, $Form1)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    Case $mnFarbe
    $afont = _ChooseFont()

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

    Case $mnText
    GUISetState(@SW_SHOW, $Form2)

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

    Case $btnMnText
    GUISetState(@SW_SHOW, $Form2)
    $mnEintrag = GUICtrlRead($Edit1)
    GUISetState(@SW_SHOW, $Form1)
    $Label = GUICtrlCreateLabel($mnEintrag, $x, $y, 146, 89)

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

    EndSwitch

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

    #Region Positionieren Text
    If _IsPressed("25") Then
    $x -= 1
    Update()
    ElseIf _IsPressed("27") Then
    $x += 1
    Update()
    ElseIf _IsPressed("26") Then
    $y -= 1
    Update()
    ElseIf _IsPressed("28") Then
    $y += 1
    Update()
    EndIf

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

    #EndRegion Positionieren Text
    WEnd

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

    Func Update()

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

    GUICtrlSetPos($Label, $x, $y)
    EndFunc ;==>Update

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

    Func _Menue()

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

    $mnpText = GUICtrlCreateMenu("Text")
    $mnText = GUICtrlCreateMenuItem("öffnen", $mnpText)

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

    $mnpFarbe = GUICtrlCreateMenu("Farbe")
    $mnFarbe = GUICtrlCreateMenuItem("öffnen", $mnpFarbe)

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

    EndFunc ;==>_Menue

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

    Die Var $Label muß irgendwie bei jedem anlegen
    erweitert werden und ich muß jede $Label editieren.... huh

    Hoffe Ihr habt das ne Idee


    Grüße
    Ilse ;)

    Einmal editiert, zuletzt von Ilse (2. August 2012 um 20:57)

  • Mach einfach die ID's von den Labels in ein Array. So kannst du alle mit relativ wenig Aufwand erstellen und ansprechen.

    Gruss Shadowigor

  • Hallo Shadowigor,

    ich habe immer meine Probleme mit Arrays
    Ich habe keine feste Anzahl...von Einträgen

    Kannst du mir vielleicht ein Beispiel mit ID'S machen?

    ;) Grüße Ilse

  • Das mit der Nicht-festen Anzahl ist kein Problem. Dafür gibts _ArrayAdd. So würdest du ein neues Label erstellen:

    Spoiler anzeigen
    [autoit]

    Global $Array[1] ; Am Anfang des Scripts
    ; ...
    _ArrayAdd($Array, GUICtrlCreateLabel("Text", 0, 0)) ; Erstelllen
    ; ...
    GUICtrlSetData($Array[1], "Hallo") ; Erstes Label verändern

    [/autoit]


    Ich hoffe damit kommst du etwas weiter. Und sonst fragst du einfach wieder. ;)

  • Spoiler anzeigen
    [autoit]

    #include <Array.au3>
    #include <GUIConstantsEx.au3>
    #include <gdiplus.au3>
    #include <misc.au3>
    #include <WindowsConstants.au3>
    #include <ButtonConstants.au3>
    #include <EditConstants.au3>

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

    $x = 140
    $y = 110
    Global $afont, $mnText, $Label, $mnFarbe, $mnpFarbe, $aLabel[1]
    $Form1 = GUICreate("Form1", 800, 600)

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

    _Menue()

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

    $Form2 = GUICreate("Texte", 625, 443, 192, 124)
    $Edit1 = GUICtrlCreateEdit("", 32, 40, 545, 321, BitOR($ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_WANTRETURN, $WS_VSCROLL))
    GUICtrlSetData(-1, "")
    GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif")
    $btnMnText = GUICtrlCreateButton("Text auf Form", 400, 376, 179, 41, $WS_GROUP)
    GUISetState(@SW_SHOW, $Form1)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit

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

    Case $mnFarbe
    $afont = _ChooseFont()

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

    Case $mnText
    GUISetState(@SW_SHOW, $Form2)

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

    Case $btnMnText
    GUISetState(@SW_SHOW, $Form2)
    $mnEintrag = GUICtrlRead($Edit1)
    GUISetState(@SW_SHOW, $Form1)

    ReDim $aLabel[UBound ($aLabel) + 1] ; Entspricht _ArrayAdd
    $aLabel[UBound($aLabel) - 1] = GUICtrlCreateLabel($mnEintrag, $x, $y, 146, 89) ; Fügst das neue Label dem Array hinzu
    $Label = $aLabel[UBound($aLabel) - 1] ; ... und setzt $Label (die Variable, die beim Update übergeben wird) auf das neueste Label
    EndSwitch

    #Region Positionieren Text
    If _IsPressed("25") Then
    $x -= 1
    Update()
    ElseIf _IsPressed("27") Then
    $x += 1
    Update()
    ElseIf _IsPressed("26") Then
    $y -= 1
    Update()
    ElseIf _IsPressed("28") Then
    $y += 1
    Update()
    EndIf

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

    #EndRegion Positionieren Text

    For $i = 1 To UBound($aLabel) - 1 ; Fängst bei [1] an, weil [0] leer ist
    If $nMsg = $aLabel[$i] Then ; Wenn eines der Labels angeklickt wurde
    $Label = $aLabel[$i] ; wird es zum aktiven Label (damit es verschoben werden kann usw)
    $aPos = ControlGetPos($Form1, '', $Label) ; Nimmst noch die aktuelle Position des Labels
    $x = $aPos[0] ; Und speicherst es in die Positionsvariablen
    $y = $aPos[1] ; ;)
    EndIf
    Next
    WEnd

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

    Func Update()

    GUICtrlSetPos($Label, $x, $y) ; Das aktive Label wird mit seinen eigenen Koordinaten verschoben
    EndFunc ;==>Update

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

    Func _Menue()

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

    $mnpText = GUICtrlCreateMenu("Text")
    $mnText = GUICtrlCreateMenuItem("öffnen", $mnpText)

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

    $mnpFarbe = GUICtrlCreateMenu("Farbe")
    $mnFarbe = GUICtrlCreateMenuItem("öffnen", $mnpFarbe)

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

    EndFunc ;==>_Menue

    [/autoit]
  • Hallo Shadowigor,

    danke für die Hilfe

    Grüß dich $Var,

    merci für das Beispiel mit Kommentaren. Nochmal etwas gelernt.

    Bin noch an den Schriften und Farben.
    Hoffe das klappt

    Liebe Grüße
    Ilse ;)

    Einmal editiert, zuletzt von Ilse (2. August 2012 um 20:56)