Gitter System?

  • Hallo,
    gibt es eine Möglichkeit mit einem Gitter bzw. Koordinaten System zu arbeiten?
    Wenn ja, wie denn? Ich möchte keine Linien die mir die Koordinaten "anzeigen", sondern Blöcke an der Stelle habe. Die soll man als Button anklicken können und je nach Wunsch Text und Farbe ändern können.
    Und natürlich möchte ich auch alle Informationen auslesen können, am besten halt mit den Koordinaten wie z.B. in einem 2D Array.
    Ich hoffe ihr habt mich verstanden.
    Mit freundlichen Grüßen,
    Freaky

  • Am besten lässt du in 2 verschachtelten For Schleifen jeweils in x und y Richtung Buttons erstellen und die IDs in ein 2 D Array schreiben. Dadurch hast du einen schnellen Aufbau und die genause Möglichkeit die ButtonIDs anhand der Koordinate zu bestimmen.

    • Offizieller Beitrag

    z.B. so:

    Spoiler anzeigen
    [autoit]

    Global $aBtn[30][30]
    $hGui = GUICreate('Test', 300, 300)
    For $i = 0 To 29
    For $j = 0 To 29
    $aBtn[$i][$j] = GUICtrlCreateButton('', $i*10, $j*10, 10, 10)
    Next
    Next
    GUISetState(@SW_SHOW, $hGui)

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

    Do
    $iMsg = GUIGetMsg()
    For $i = 0 To 29
    For $j = 0 To 29
    If $iMsg = $aBtn[$i][$j] Then
    ConsoleWrite('Zeile: ' & $i+1 & ', Spalte: ' & $j+1 & @CRLF)
    ExitLoop
    EndIf
    Next
    Next
    Until $iMsg = -3

    [/autoit]
  • Hallo,

    vor einiger Zeit habe ich mal nach einer Grid-Lösung zur Erfassung und Darstellung von Daten gesucht.

    Das Table UDF von AndyBioChem (table.au3) war mir zu starr, Martins StringGrid Beispiel zu groß, zu lahm (beide im englischen Forum). Daraus habe ich mal eine kurzes Skript als (Quick and Dirty-) Studie erstellt. Über das Stadium ist es leider auch nicht herausgekommen, aber vielleicht hilfts.

    Mfg

    Reinhard

    Spoiler anzeigen
    [autoit]


    #include <WindowsConstants.au3>
    #include <StaticConstants.au3> ;Neu eingefügt
    #include <GUIConstants.au3>
    #include <GUIConstantsEx.au3>
    #include <editconstants.au3>
    ;#include <GDIPlus.au3>
    ;#include "Table.au3"
    #include <Array.au3>
    DIM $_aGUICtrlTableBordersINTERNALSTORE[1][2]
    $GUI = GUICreate("Table Test", 450, 450)
    $ip1 = GUICtrlCreateInput("",25,110,55,15, -1, $WS_EX_TOOLWINDOW)
    GUICtrlSetState ($ip1,$GUI_Hide)
    ;; should be globals and stored into table[0][0]
    DIM $xRows = 10, $xCols = 7
    DIM $xLeft = 25, $xTop = 130, $xWidth = 55, $xHeight = 13
    DIM $table2[$xrows+1][$xCols+1]
    DIM $xCurrBoxLeft = 0, $xCurrBoxTop = 0, $xGridWidth = 1
    Global $xSelMode = "" ;"RowsOnly"
    CreateTable($table2)
    func CreateTable(ByRef $xtable,$xLeft = 25, $xTop = 130, $xWidth = 55, $xHeight = 13,$xRows = 5, $xCols = 5,$xGridWidth = 1)
    local $xCurrBoxLeft = 0, $xCurrBoxTop = 0
    $xRows = ubound($xtable,1)-1
    $xCols = ubound($xtable,2)-1
    ;msgbox(0,"",$xRows&" / "&$xCols)
    For $i = 1 To $xRows ;$iRows
    For $j = 1 To $xCols ;$iColumns
    if $i = 1 then ;header
    $xtable[$i][$j] = GUICtrlCreatelabel("", $xleft + $xCurrBoxLeft, $xTop + $xCurrBoxTop, $xWidth, $xHeight)
    GUICtrlSetBkColor(-1,0xEEEEEE )
    GuiCtrlSetData(-1,"Col "&$j)
    elseif $j = 1 then ;leftBorder
    $xtable[$i][$j] = GUICtrlCreatelabel("", $xleft + $xCurrBoxLeft, $xTop + $xCurrBoxTop, $xWidth, $xHeight)
    GUICtrlSetBkColor(-1,0xEEEEEE )
    GuiCtrlSetData(-1,"Row "&$i)
    else
    $xtable[$i][$j] = GUICtrlCreateLabel("", $xleft + $xCurrBoxLeft, $xTop + $xCurrBoxTop, $xWidth, $xHeight,-1, $WS_EX_TRANSPARENT)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetCursor(-1,2)
    endif
    if $i = 1 and $j = 1 then GuiCtrlSetData(-1,"Table")
    $xCurrBoxLeft += $xWidth + $xGridWidth
    Next
    $xCurrBoxLeft = 0
    $xCurrBoxTop += $xHeight + $xGridWidth
    Next
    ;; eingefügt für table Border ;;;;;;;;;
    ReDim $_aGUICtrlTableBordersINTERNALSTORE[UBound($_aGUICtrlTableBordersINTERNALSTORE, 1) + 1][2]
    Dim $aTemp[$xRows + 1][$xCols + 1][5]
    $_aGUICtrlTableBordersINTERNALSTORE[UBound($_aGUICtrlTableBordersINTERNALSTORE) - 1][0] = $xtable[1][1]
    $_aGUICtrlTableBordersINTERNALSTORE[UBound($_aGUICtrlTableBordersINTERNALSTORE) - 1][1] = $aTemp
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    endfunc
    $table2HdlFirst = $table2[1][1]
    $table2HdlEnd = $table2[$xRows][$xCols]
    ;dim $Test[3]
    ;$test[1] = GUICtrlCreateLabel("Test",10,420,60,20)
    table_Set_Borders()
    func table_Set_Borders()
    ;; notes with GUI GUICtrlSetBkColor(-1, 0x0)werden Innlinien bei Gridweite 0 nicht gezeichnet! Austesten
    ;;outline all
    ;;top-line
    GUICtrlCreateGraphic ($xleft-1, $xtop-1, (($xWidth+$xGridWidth)*$xCols), 1)
    GUICtrlSetBkColor(-1, 0x0)
    ;;leftline
    GUICtrlCreateGraphic ($xleft-1, $xtop-1, 1, (($xHeight+$xGridWidth)*$xRows),$ss_blackrect)
    ;GUICtrlSetBkColor(-1, 0x0)
    ;; bottom line
    GUICtrlCreateGraphic ($xleft-1, $xtop-1 +(($xHeight+$xGridWidth)*$xRows), (($xWidth+$xGridWidth)*$xCols), 1,$ss_blackrect)
    ;GUICtrlSetBkColor(-1, 0x0)
    ;; right line
    GUICtrlCreateGraphic ($xleft-1 + (($xWidth+$xGridWidth)*$xCols), $xtop-1, 1 ,(($xHeight+$xGridWidth)*$xRows),$ss_blackrect)
    ;GUICtrlSetBkColor(-1, 0x0)
    ;; outline header (underline first row)
    GUICtrlCreateGraphic ($xleft-1, $xtop-1 +(($xHeight+$xGridWidth) * 1), (($xWidth+$xGridWidth)*$xCols), 1,$ss_blackrect)
    ;GUICtrlSetBkColor(-1, 0x0)
    ;; outline left Border ()
    GUICtrlCreateGraphic ($xleft-1 +(($xWidth+$xGridWidth)*1), $xtop-1, 1, (($xHeight+$xGridWidth)*$xRows),$ss_blackrect)
    ;GUICtrlSetBkColor(-1, 0x0)
    endfunc

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

    GuiSetState()
    GUIRegisterMsg($WM_COMMAND, "DB_WM_COMMAND");only used for EN_CHANGE so far
    ;----- Loop -----
    While 1
    $Msg = GUIGetMsg()
    if $msg > $table2HdlFirst-1 and $msg < $table2HdlEnd +1 then
    $RowId = INT((+$msg-$table2HdlFirst)/$xCOLS)+1
    $colId = +$msg-$table2HdlFirst-(($rowId-1)*$xCOLS)+1
    ;msgbox(0,"","Address: R"&$RowId &"C"&$colId)
    ;_GUICtrlTable_Set_CellColor_Row(ByRef $array, $iRow, $iColor = 0xFFFFFF)
    guiCtrlsetData($ip1,guiCtrlRead($table2[$rowId][$colID]))
    GUICtrlSetState ($ip1,$GUI_FOCUS)
    ;ControlFocus($gui, "", $ip1)
    tableOnClick($rowId,$colId)
    endif
    Switch $Msg
    Case $GUI_EVENT_CLOSE
    Exit
    ;case $test[1]
    ; msgbox(0,"","Test")
    EndSwitch
    Sleep(50)
    WEnd

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

    func tableOnClick($rowId,$colId)
    ;; reset format, better save formats and reset single
    For $i = 1 To $xRows ;$iRows
    For $j = 1 To $xCols ;$iColumns
    ;$xtable[$i][$j] = GUICtrlCreateLabel("R"&$i&"C"&$j, $xleft + $xCurrBoxLeft, $xTop + $xCurrBoxTop, $xWidth, $xHeight)
    if $i = 1 then ;header
    GUICtrlSetBkColor($table2[$i][$j],0xEEEEEE )
    elseif $j = 1 then ;leftBorder
    GUICtrlSetBkColor($table2[$i][$j],0xEEEEEE )
    else
    GUICtrlSetBkColor($table2[$i][$j], 0xFFFFFF)
    endif
    ;$xCurrBoxLeft += $xWidth + $xGapWidth
    Next
    ;$xCurrBoxLeft = 0
    ;$xCurrBoxTop += $xHeight + $xGapWidth
    Next
    if $xSelMode = "RowsOnly" and $RowId >1 then $colId = 1
    if $colId = 1 then _GUICtrlTable_Set_CellColor_Row($Table2, $rowId, 0xFFFF80)
    if $rowId = 1 then _GUICtrlTable_Set_CellColor_Column($Table2, $colid, 0xFFFF80)
    _GUICtrlTable_Set_CellColor_Cell($table2,$rowId,$colId,0xFFFF80)
    endfunc

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

    Func DB_WM_COMMAND($hwnd, $iMsg, $iwParam, $ilParam)
    Local $setHK = False
    $nNotifyCode = BitShift($iwParam, 16)
    $nID = BitAND($iwParam, 0x0000FFFF)
    $hCtrl = $ilParam
    If $nNotifyCode = $EN_CHANGE Then
    If $ilParam = GUICtrlGetHandle($ip1) then ;And $lastSelectedCell <> -1 Then
    ;GUICtrlSetData($lab[$labNo], GUICtrlRead($ip1))
    GUICtrlSetData($table2[$rowId][$colID], GUICtrlRead($ip1))
    ;Local $iCN = $lastSelectedCell - $lab[1];the index of the cell
    ;If IsFormula($Cells[$iCN][0]) Then ;it might be a formula
    ;EndIf
    ;$Cells[$iCN][0] = '';clear text/formula. It will be reset in SetDisplayText
    EndIf
    EndIf
    Return $GUI_RUNDEFMSG
    EndFunc ;==>DB_WM_COMMAND

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

    #region TableUDF from AndyBioChem

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

    ; #FUNCTION# ;===============================================================================
    ; Name...........: _GUICtrlTable_Set_CellColor_Row
    ; Description ...: Sets the cell background color of a row of cells
    ; Syntax.........: _GUICtrlTable_Set_CellColor_Row(ByRef $array, $iRow[, $iColor = 0xFFFFFF])
    ; Parameters ....: $array - array returned from _GUICtrlTable_Create
    ; $iRow - table row value
    ; $iColor - background color for cell ( -2 = transparent)
    ; Return values .: Success - (under construction)
    ; Failure - (under construction)
    ; Author ........: AndyBiochem
    ; ===========================================================================================
    Func _GUICtrlTable_Set_CellColor_Row(ByRef $array, $iRow, $iColor = 0xFFFFFF)
    Local $i
    If IsArray($array) = 0 Then Return
    If $iRow = 0 Then Return
    If Number($iRow) > UBound($array, 1) - 1 Then Return
    For $i = 1 To UBound($array, 2) - 1
    GUICtrlSetBkColor($array[$iRow][$i], $iColor)
    Next
    EndFunc ;==>_GUICtrlTable_Set_CellColor_Row

    ; #FUNCTION# ;===============================================================================
    ; Name...........: _GUICtrlTable_Set_CellColor_Column
    ; Description ...: Sets the cell background color of a column of cells
    ; Syntax.........: _GUICtrlTable_Set_CellColor_Col(ByRef $array, $iCol[, $iColor = 0xFFFFFF])
    ; Parameters ....: $array - array returned from _GUICtrlTable_Create
    ; $iCol - table column value
    ; $iColor - background color for cell ( -2 = transparent)
    ; Return values .: Success - (under construction)
    ; Failure - (under construction)
    ; Author ........: AndyBiochem
    ; ===========================================================================================
    Func _GUICtrlTable_Set_CellColor_Column(ByRef $array, $iCol, $iColor = 0xFFFFFF)
    Local $i
    If IsArray($array) = 0 Then Return
    If $iCol = 0 Then Return
    If Number($iCol) > UBound($array, 2) - 1 Then Return
    For $i = 1 To UBound($array, 1) - 1
    GUICtrlSetBkColor($array[$i][$iCol], $iColor)
    Next
    EndFunc ;==>_GUICtrlTable_Set_CellColor_Column

    ; #FUNCTION# ;===============================================================================
    ; Name...........: _GUICtrlTable_Set_CellColor_Cell
    ; Description ...: Sets the cell background color of a specified of cell
    ; Syntax.........: _GUICtrlTable_Set_CellColor_Cell(ByRef $array, $iRow, $iCol[, $iColor = 0xFFFFFF])
    ; Parameters ....: $array - array returned from _GUICtrlTable_Create
    ; $iRow - cell row value
    ; $iCol - cell column value
    ; $iColor - background color for cell ( -2 = transparent)
    ; Return values .: Success - (under construction)
    ; Failure - (under construction)
    ; Author ........: AndyBiochem
    ; ===========================================================================================
    Func _GUICtrlTable_Set_CellColor_Cell(ByRef $array, $iRow, $iCol, $iColor = 0xFFFFFF)
    If IsArray($array) = 0 Then Return
    If $iRow = 0 Then Return
    If $iCol = 0 Then Return
    If Number($iRow) > UBound($array, 1) - 1 Then Return
    If Number($iCol) > UBound($array, 2) - 1 Then Return
    GUICtrlSetBkColor($array[$iRow][$iCol], $iColor)
    EndFunc ;==>_GUICtrlTable_Set_CellColor_Cell

    ; #FUNCTION# ;===============================================================================
    ; Name...........: _GUICtrlTable_Set_CellColor_All
    ; Description ...: Sets the cell background color of all cells in a table
    ; Syntax.........: _GUICtrlTable_Set_CellColor_All(ByRef $array[, $iColor = 0xFFFFFF])
    ; Parameters ....: $array - array returned from _GUICtrlTable_Create
    ; $iColor - background color for cells ( -2 = transparent)
    ; Return values .: Success - (under construction)
    ; Failure - (under construction)
    ; Author ........: AndyBiochem
    ; ===========================================================================================
    Func _GUICtrlTable_Set_CellColor_All(ByRef $array, $iColor = 0xFFFFFF)
    Local $i, $j
    If IsArray($array) = 0 Then Return
    For $i = 1 To UBound($array, 1) - 1
    For $j = 1 To UBound($array, 2) - 1
    GUICtrlSetBkColor($array[$i][$j], $iColor)
    Next
    Next
    EndFunc ;==>_GUICtrlTable_Set_CellColor_All

    [/autoit]
  • Hey danke. Dies ist mir leider etwas zu langsam.
    Ich habe mich jetzt einfach für die Button Lösung entschieden aber ich bräuchte mal eben Hilfe bei einem merkwürdigen Problem:

    Spoiler anzeigen
    [autoit]

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

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

    Global $iWidth, $iHeigh, $iBlockSize = 20, $iWater
    Global $iBlue = 0x0066ff, $iGreen = 0x21610B, $iBrown = 0x693f05

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

    $iForm1 = GUICreate("FarmThingy", 134, 52)
    GUICtrlCreateLabel("Width:", 8, 2, 30, 21)
    GUICtrlCreateLabel("Heigh:", 8, 27, 30, 21)
    $iInputWidth = GUICtrlCreateInput("", 40, 2, 30, 21, BitOR($ES_CENTER, $ES_NUMBER))
    $iInputHeigh = GUICtrlCreateInput("", 40, 25, 30, 21, BitOR($ES_CENTER, $ES_NUMBER))
    $iButtonGenerate = GUICtrlCreateButton("Generate", 72, 0, 60, 50)
    GUISetState(@SW_SHOWNORMAL, $iForm1)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case -3
    Exit
    Case $iButtonGenerate
    $iWidth = GUICtrlRead($iInputWidth)
    $iHeigh = GUICtrlRead($iInputHeigh)
    GUIDelete($iForm1)
    ExitLoop
    EndSwitch
    WEnd

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

    Global $iMinimum = 4
    Global $iButtonKoordinate[$iWidth + 1][$iHeigh + 1], $iBackgroundColor[$iWidth + 1][$iHeigh + 1]

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

    $iForm2 = GUICreate("FarmThingy", $iBlockSize * $iWidth, $iBlockSize * $iHeigh,0,0)
    GUISetBkColor (0x000000, $iForm2)
    GUISetState(@SW_SHOWNORMAL, $iForm2)
    For $x = 1 To $iWidth
    For $y = 1 To $iHeigh
    $iButtonKoordinate[$x][$y] = GUICtrlCreateButton("",($x-1)*$iBlockSize, ($y-1) * $iBlockSize, $iBlockSize, $iBlockSize)
    $iBackgroundColor[$x][$y] = 0x693f05
    GUICtrlSetBkColor ($iButtonKoordinate[$x][$y],$iBackgroundColor[$x][$y])
    Next
    Next

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

    $iForm3 = GUICreate ("FarmThingy", 300,300,Default,Default,Default,Default,$iForm2)
    $iControlWheat = GUICtrlCreateRadio ("Wheat",8,2,40,21)
    $iButtonDraw = GUICtrlCreateButton ("Draw",8,25,40,25)
    GUISetState (@SW_SHOWNORMAL, $iForm3)

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case -3
    Exit
    Case $iButtonDraw
    For $i = 1 To $iWidth
    For $j = 1 To $iHeigh
    $iWater = False
    For $k = 0 To $iMinimum
    For $l = 0 To $iMinimum
    If (($i+$k <= $iWidth) And ($i-$k >= 0) And ($j+$l <= $iHeigh) And ($j-$l >= 0)) Then
    If ($iBackgroundColor [$i+$k][$j] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    ElseIf ($iBackgroundColor [$i-$k][$j] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    ElseIf ($iBackgroundColor [$i][$j+$l] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    ElseIf ($iBackgroundColor [$i][$j-$l] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    ElseIf ($iBackgroundColor [$i+$k][$j+$l] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    ElseIf ($iBackgroundColor [$i-$k][$j-$l] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    ElseIf ($iBackgroundColor [$i-$k][$j+$l] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    ElseIf ($iBackgroundColor [$i+$k][$j-$l] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    ElseIf ($iBackgroundColor [$i+$k][$j-$l] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    ElseIf ($iBackgroundColor [$i-$k][$j+$l] = $iBlue) Then
    $iWater = True
    ExitLoop 1
    EndIf
    EndIf
    Next
    Next

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

    If (($iWater = True) And ($iBackgroundColor[$i][$j] <> $iBlue)) Then
    $iBackgroundColor[$i][$j] = $iGreen
    GUICtrlSetBkColor ($iButtonKoordinate[$i][$j], $iBackgroundColor[$i][$j])
    ElseIf (($iWater = False) And ($iBackgroundColor[$i][$j] = $iGreen)) Then
    $iBackgroundColor[$i][$j] = $iBrown
    GUICtrlSetBkColor ($iButtonKoordinate[$i][$j], $iBackgroundColor[$i][$j])
    ElseIf (($iWater = False) And ($iBackgroundColor[$i][$j] = $iBrown)) Then
    $iBackgroundColor[$i][$j] = $iBlue
    GUICtrlSetBkColor ($iButtonKoordinate[$i][$j], $iBackgroundColor[$i][$j])
    EndIf
    Next
    Next
    EndSwitch
    For $i = 1 To $iWidth
    For $j = 1 To $iHeigh
    If ($nMsg = $iButtonKoordinate[$i][$j]) Then
    If ($iBackgroundColor[$i][$j] = $iBrown) Then
    $iBackgroundColor[$i][$j] = $iBlue
    GUICtrlSetBkColor ($iButtonKoordinate[$i][$j], $iBackgroundColor[$i][$j])
    Else
    $iBackgroundColor[$i][$j] = 0x693f05
    GUICtrlSetBkColor ($iButtonKoordinate[$i][$j],$iBackgroundColor[$i][$j])
    EndIf
    EndIf
    Next
    Next
    WEnd

    [/autoit]


    Also, wenn ihr bei Width und Heich einfach z.B. 30 und 30 angibt, dann lässt ihr es einfach mal generieren. Danach klickt auf den draw Button um zu sehen was eig. passiert.
    Ich glaube man sieht sofort wo das eigentliche Problem ist. Wisst ihr warum das kommt und wie ich das beheben kann?

    Einmal editiert, zuletzt von Freaky (20. Juli 2012 um 00:55)

  • So?

    Spoiler anzeigen
    [autoit]

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

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

    Global $iWidth, $iHeight, $iBlockSize = 20
    Global $iBlue = 0x0066ff, $iGreen = 0x21610B, $iBrown = 0x693f05

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

    $hGui_1 = GUICreate("FarmThingy", 139, 52)
    GUICtrlCreateLabel("Width:", 8, 2, 30, 21)
    GUICtrlCreateLabel("Height:", 8, 27, 35, 21)
    $cInputWidth = GUICtrlCreateInput("", 45, 2, 30, 21, BitOR($ES_CENTER, $ES_NUMBER))
    $cInputHeight = GUICtrlCreateInput("", 45, 25, 30, 21, BitOR($ES_CENTER, $ES_NUMBER))
    $cButtonGenerate = GUICtrlCreateButton("Generate", 77, 0, 60, 50)
    GUISetState()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $cButtonGenerate
    $iWidth = GUICtrlRead($cInputWidth)
    $iHeight = GUICtrlRead($cInputHeight)
    GUIDelete($hGui_1)
    ExitLoop
    EndSwitch
    WEnd

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

    Global $iMinimum = 4
    Global $acButtonCoordinate[$iWidth][$iHeight], $aiBackgroundColor[$iWidth][$iHeight]

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

    $hGui_2 = GUICreate("FarmThingy", $iBlockSize * $iWidth, $iBlockSize * $iHeight, 5, 5)
    GUISetBkColor(0x000000)
    For $x = 0 To $iWidth - 1
    For $y = 0 To $iHeight - 1
    $acButtonCoordinate[$x][$y] = GUICtrlCreateButton("", $x * $iBlockSize, $y * $iBlockSize, $iBlockSize, $iBlockSize)
    $aiBackgroundColor[$x][$y] = 0x693f05
    GUICtrlSetBkColor(-1, $aiBackgroundColor[$x][$y])
    Next
    Next
    GUISetState()

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

    $hGui_3 = GUICreate("FarmThingy", 300, 300, -1, -1, Default, Default, $hGui_2)
    $cControlWheat = GUICtrlCreateRadio("Wheat", 8, 2, 50, 20)
    $cButtonDraw = GUICtrlCreateButton("Draw", 8, 25, 40, 25)
    GUISetState()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $cButtonDraw
    For $i = 0 To $iWidth - 1
    For $j = 0 To $iHeight - 1
    If Mod($i, 5) Or Mod($j, 5) Then
    $aiBackgroundColor[$i][$j] = $iGreen
    GUICtrlSetBkColor($acButtonCoordinate[$i][$j], $aiBackgroundColor[$i][$j])
    Else
    $aiBackgroundColor[$i][$j] = $iBlue
    GUICtrlSetBkColor($acButtonCoordinate[$i][$j], $aiBackgroundColor[$i][$j])
    EndIf
    Next
    Next
    EndSwitch
    For $i = 0 To $iWidth - 1
    For $j = 0 To $iHeight - 1
    If $nMsg = $acButtonCoordinate[$i][$j] Then
    If $aiBackgroundColor[$i][$j] = $iBrown Then
    $aiBackgroundColor[$i][$j] = $iBlue
    GUICtrlSetBkColor($acButtonCoordinate[$i][$j], $aiBackgroundColor[$i][$j])
    Else
    $aiBackgroundColor[$i][$j] = 0x693f05
    GUICtrlSetBkColor($acButtonCoordinate[$i][$j], $aiBackgroundColor[$i][$j])
    EndIf
    EndIf
    Next
    Next
    WEnd

    [/autoit]

    Du solltest deinen Programmierstil ein bisschen ändern. Der Präfix von Controls ist nicht i sondern c. Wenn du boolsche Variablen hast auch nicht i sondern x oder f. Arrays wenn möglich mit einem a vorne weg. Soviel Klammern brauchst du nicht nutzen (ist ja kein C++). Achja GUI's haben als Präfix h und nicht i. Das heißt auch nicht Heigh sondern Height. Wenn schon englisch, dann richtig ;). Und Arrays fangen bei 0 an.

    Edit:
    Hier noch das Ganze im OnEvent-Mode, was besser ist in dem Fall.

    Spoiler anzeigen
    [autoit]

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

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

    Global $iWidth, $iHeight, $iBlockSize = 20
    Global $iBlue = 0x0066ff, $iGreen = 0x21610B, $iBrown = 0x693f05

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

    $hGui_1 = GUICreate("FarmThingy", 139, 52)
    GUICtrlCreateLabel("Width:", 8, 2, 30, 21)
    GUICtrlCreateLabel("Height:", 8, 27, 35, 21)
    $cInputWidth = GUICtrlCreateInput("", 45, 2, 30, 21, BitOR($ES_CENTER, $ES_NUMBER))
    $cInputHeight = GUICtrlCreateInput("", 45, 25, 30, 21, BitOR($ES_CENTER, $ES_NUMBER))
    $cButtonGenerate = GUICtrlCreateButton("Generate", 77, 0, 60, 50)
    GUISetState()

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

    While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
    Case $GUI_EVENT_CLOSE
    Exit
    Case $cButtonGenerate
    $iWidth = GUICtrlRead($cInputWidth)
    $iHeight = GUICtrlRead($cInputHeight)
    GUIDelete($hGui_1)
    ExitLoop
    EndSwitch
    WEnd

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

    Opt("GUIOnEventMode", 1)

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

    Global $iMinimum = 4
    Global $acButtonCoordinate[$iWidth][$iHeight], $aiBackgroundColor[$iWidth][$iHeight]

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

    $hGui_2 = GUICreate("FarmThingy", $iBlockSize * $iWidth, $iBlockSize * $iHeight, 5, 5)
    GUISetBkColor(0x000000)
    For $iX = 0 To $iWidth - 1
    For $iY = 0 To $iHeight - 1
    $acButtonCoordinate[$iX][$iY] = GUICtrlCreateButton("", $iX * $iBlockSize, $iY * $iBlockSize, $iBlockSize, $iBlockSize)
    $aiBackgroundColor[$iX][$iY] = 0x693f05
    GUICtrlSetBkColor(-1, $aiBackgroundColor[$iX][$iY])
    GUICtrlSetOnEvent(-1, "_Select")
    Next
    Next
    GUISetState()

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

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

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

    $hGui_3 = GUICreate("FarmThingy", 300, 300, -1, -1, Default, Default, $hGui_2)
    $cControlWheat = GUICtrlCreateRadio("Wheat", 8, 2, 50, 20)
    $cButtonDraw = GUICtrlCreateButton("Draw", 8, 25, 40, 25)
    GUISetState()

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

    GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
    GUICtrlSetOnEvent($cButtonDraw, "_Draw")

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

    While 1
    Sleep(100)
    WEnd

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

    Func _Exit()
    Exit
    EndFunc

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

    Func _Draw()
    For $iX = 0 To $iWidth - 1
    For $iY = 0 To $iHeight - 1
    If Mod($iX, 5) Or Mod($iY, 5) Then
    $aiBackgroundColor[$iX][$iY] = $iGreen
    GUICtrlSetBkColor($acButtonCoordinate[$iX][$iY], $aiBackgroundColor[$iX][$iY])
    Else
    $aiBackgroundColor[$iX][$iY] = $iBlue
    GUICtrlSetBkColor($acButtonCoordinate[$iX][$iY], $aiBackgroundColor[$iX][$iY])
    EndIf
    Next
    Next
    EndFunc

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

    Func _Select()
    For $iX = 0 To $iWidth - 1
    For $iY = 0 To $iHeight - 1
    If @GUI_CtrlId = $acButtonCoordinate[$iX][$iY] Then
    If $aiBackgroundColor[$iX][$iY] = $iBrown Then
    $aiBackgroundColor[$iX][$iY] = $iBlue
    GUICtrlSetBkColor($acButtonCoordinate[$iX][$iY], $aiBackgroundColor[$iX][$iY])
    Else
    $aiBackgroundColor[$iX][$iY] = 0x693f05
    GUICtrlSetBkColor($acButtonCoordinate[$iX][$iY], $aiBackgroundColor[$iX][$iY])
    EndIf
    EndIf
    Next
    Next
    EndFunc

    [/autoit]

    4 Mal editiert, zuletzt von m-obi (20. Juli 2012 um 09:32)