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
Gitter System?
-
- [ offen ]
-
Freaky -
19. Juli 2012 um 03:33 -
Geschlossen -
Erledigt
-
-
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]
[/autoit] [autoit][/autoit] [autoit]
$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)Do
[/autoit]
$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 -
Ich finde, Buttons eignen sich für sowas nicht sehr gut.
Nimm lieber Labels, nebeneinander sehen die definitiv besser aus.
Und du kannst dir auch mal das hier anschauen, wenn's dich interessiert.lg chess
-
Danke für eure Hilfe, die Idee mit simplen Controls hatte ich auch aber gibt es da keine elegantere und schönere Lösung die wirklich ein Koordinatensystem zeigt mit Gitter etc.?
-
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]
[/autoit] [autoit][/autoit] [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)
endfuncGuiSetState()
[/autoit] [autoit][/autoit] [autoit]
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)
WEndfunc tableOnClick($rowId,$colId)
[/autoit] [autoit][/autoit] [autoit]
;; 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)
endfuncFunc DB_WM_COMMAND($hwnd, $iMsg, $iwParam, $ilParam)
[/autoit] [autoit][/autoit] [autoit]
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#region TableUDF from AndyBioChem
[/autoit] [autoit][/autoit] [autoit]; #FUNCTION# ;===============================================================================
[/autoit]
; 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 -
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>
[/autoit] [autoit][/autoit] [autoit]
#include <WindowsConstants.au3>
#include <EditConstants.au3>Global $iWidth, $iHeigh, $iBlockSize = 20, $iWater
[/autoit] [autoit][/autoit] [autoit]
Global $iBlue = 0x0066ff, $iGreen = 0x21610B, $iBrown = 0x693f05$iForm1 = GUICreate("FarmThingy", 134, 52)
[/autoit] [autoit][/autoit] [autoit]
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)While 1
[/autoit] [autoit][/autoit] [autoit]
$nMsg = GUIGetMsg()
Switch $nMsg
Case -3
Exit
Case $iButtonGenerate
$iWidth = GUICtrlRead($iInputWidth)
$iHeigh = GUICtrlRead($iInputHeigh)
GUIDelete($iForm1)
ExitLoop
EndSwitch
WEndGlobal $iMinimum = 4
[/autoit] [autoit][/autoit] [autoit]
Global $iButtonKoordinate[$iWidth + 1][$iHeigh + 1], $iBackgroundColor[$iWidth + 1][$iHeigh + 1]$iForm2 = GUICreate("FarmThingy", $iBlockSize * $iWidth, $iBlockSize * $iHeigh,0,0)
[/autoit] [autoit][/autoit] [autoit]
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$iForm3 = GUICreate ("FarmThingy", 300,300,Default,Default,Default,Default,$iForm2)
[/autoit] [autoit][/autoit] [autoit]
$iControlWheat = GUICtrlCreateRadio ("Wheat",8,2,40,21)
$iButtonDraw = GUICtrlCreateButton ("Draw",8,25,40,25)
GUISetState (@SW_SHOWNORMAL, $iForm3)While 1
[/autoit] [autoit][/autoit] [autoit]
$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
NextIf (($iWater = True) And ($iBackgroundColor[$i][$j] <> $iBlue)) Then
[/autoit]
$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
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? -
Ich kann nicht nachvollziehen was du meinst.
-
Wenn man auf den draw Button drückt, dann malt es am Ende 2 blaue Buttons nebeneinander, dies soll es aber nicht.
Es soll einfach weiter nach dem Muster gehen. Dies ist genauso unten. -
Hab den Code von Pastebin.
Wenn ich nach dem Generieren auf Draw drücke passiert garnichts. Wenn ich Buttons anklicke (blau) und dann Draw drücke, dann werden die bluauen Buttons von grünen umrandet. Soll das nicht so sein? -
So?
Spoiler anzeigen
[autoit]#include <GUIConstantsEx.au3>
[/autoit] [autoit][/autoit] [autoit]
#include <WindowsConstants.au3>
#include <EditConstants.au3>Global $iWidth, $iHeight, $iBlockSize = 20
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Global $iBlue = 0x0066ff, $iGreen = 0x21610B, $iBrown = 0x693f05$hGui_1 = GUICreate("FarmThingy", 139, 52)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
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()While 1
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $cButtonGenerate
$iWidth = GUICtrlRead($cInputWidth)
$iHeight = GUICtrlRead($cInputHeight)
GUIDelete($hGui_1)
ExitLoop
EndSwitch
WEndGlobal $iMinimum = 4
[/autoit] [autoit][/autoit] [autoit]
Global $acButtonCoordinate[$iWidth][$iHeight], $aiBackgroundColor[$iWidth][$iHeight]$hGui_2 = GUICreate("FarmThingy", $iBlockSize * $iWidth, $iBlockSize * $iHeight, 5, 5)
[/autoit] [autoit][/autoit] [autoit]
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()$hGui_3 = GUICreate("FarmThingy", 300, 300, -1, -1, Default, Default, $hGui_2)
[/autoit] [autoit][/autoit] [autoit]
$cControlWheat = GUICtrlCreateRadio("Wheat", 8, 2, 50, 20)
$cButtonDraw = GUICtrlCreateButton("Draw", 8, 25, 40, 25)
GUISetState()While 1
[/autoit]
$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
WEndDu 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>
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
#include <WindowsConstants.au3>
#include <EditConstants.au3>Global $iWidth, $iHeight, $iBlockSize = 20
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Global $iBlue = 0x0066ff, $iGreen = 0x21610B, $iBrown = 0x693f05$hGui_1 = GUICreate("FarmThingy", 139, 52)
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
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()While 1
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
Case $cButtonGenerate
$iWidth = GUICtrlRead($cInputWidth)
$iHeight = GUICtrlRead($cInputHeight)
GUIDelete($hGui_1)
ExitLoop
EndSwitch
WEndOpt("GUIOnEventMode", 1)
[/autoit] [autoit][/autoit] [autoit]Global $iMinimum = 4
[/autoit] [autoit][/autoit] [autoit]
Global $acButtonCoordinate[$iWidth][$iHeight], $aiBackgroundColor[$iWidth][$iHeight]$hGui_2 = GUICreate("FarmThingy", $iBlockSize * $iWidth, $iBlockSize * $iHeight, 5, 5)
[/autoit] [autoit][/autoit] [autoit]
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()GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
[/autoit] [autoit][/autoit] [autoit]$hGui_3 = GUICreate("FarmThingy", 300, 300, -1, -1, Default, Default, $hGui_2)
[/autoit] [autoit][/autoit] [autoit]
$cControlWheat = GUICtrlCreateRadio("Wheat", 8, 2, 50, 20)
$cButtonDraw = GUICtrlCreateButton("Draw", 8, 25, 40, 25)
GUISetState()GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
GUICtrlSetOnEvent($cButtonDraw, "_Draw")While 1
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Sleep(100)
WEndFunc _Exit()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
Exit
EndFuncFunc _Draw()
[/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]
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
EndFuncFunc _Select()
[/autoit]
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 -
Vielen Dank, genauso wollte ich das auch
Was mich jetzt aber voll irretiert ist, warum geht es zu klein mit Mod und bei mir war es so viel größer. -
Du denkst wahrscheinlich zu kompliziert.