- Сообщения
- 8,673
- Репутация
- 2,486
Функция для создания таблицы в GUI при помощи элементов Label.
Код:
;Автор: rakudave <[email protected]>
;Создание таблицы в GUI
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
;
$GUI = GUICreate("_GUICtrlCreateTable Demo", 300, 200)
GUICtrlCreateLabel("My Table:", 130, 10)
_GUICtrlCreateTable(20, 30, 16, 10, 15, 15)
GUISetState(@SW_SHOW, $GUI)
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
Exit
EndSwitch
WEnd
;=============================================================================
;
; Function Name: _GUICtrlCreateTable()
;
; Description: Creates a table, resembling the html-style
;
; Syntax: _GUICtrlCreateTable($left, $top, $rows, $cols, $width, $height, [$border])
;
; Parameter(s); $left = left side of the table
; $top = top of the table
; $rows = number of rows to be created
; $cols = number of columns to be created
; $width = width of ONE cell
; $height = height of ONE cell
; $border = [optional] thickness of the border, default: 1
;
; Return Value(s): array[rows][cols], used to set values with GUICtrlSetData
;
; Note: do NOT overwrite the returned array[0][0], it contains data for the _GUICtrlTableSpan() function
;
; Author: rakudave <[email protected]>
;=============================================================================
Func _GUICtrlCreateTable($iLeft, $iTop, $iRows, $iCols, $iWidth, $iHeight, $iBorder = 1)
Local $aTable[$iRows + 1][$iCols + 1]
$aTable[0][0] = $iLeft & "|" & $iTop & "|" & $iRows & "|" & $iCols & "|" & $iWidth & "|" & $iHeight & "|" & $iBorder
GUICtrlCreateLabel("", _
$iLeft, $iTop, $iWidth * $iRows + $iRows * $iBorder + $iBorder + 2, _
$iHeight * $iCols + $iCols * $iBorder + $iBorder + 2)
If $iBorder > 0 Then GUICtrlSetStyle(-1, $SS_BLACKFRAME)
For $x = 1 To $iRows
For $y = 1 To $iCols
GUICtrlCreateLabel("", _
($x - 1) * $iWidth + $iLeft + $x * $iBorder + 1, _
($y - 1) * $iHeight + $iTop + $y * $iBorder + 1, _
$iWidth, $iHeight)
If $iBorder > 0 Then GUICtrlSetStyle(-1, $SS_BLACKFRAME)
$aTable[$x][$y] = GUICtrlCreateLabel("", _
($x - 1) * $iWidth + $iLeft + $x * $iBorder + 4, ($y - 1) * $iHeight + $iTop + $y * $iBorder + 4, _
$iWidth - 6, $iHeight - 6)
Next
Next
Return $aTable
EndFunc
;=============================================================================
;
; Function Name: _GUICtrlTableSpan()
;
; Description: this function is used to unite some cells created by _GUICtrlCreateTable()
;
; Syntax: _GUICtrlTableSpan($id, $iFrom_Row, $iFrom_Col, $iTo_Row, $iTo_Col)
;
; Parameter(s); $id = the parameter returned by _GUICtrlCreateTable()
; $iFrom_Row = left index of the first cell to unite
; $iFrom_Col = top index of the first cell
; $iTo_Row = left index of the last cell
; $iTo_Col = top index of the last cell
;
; Return Value(s): the new parameter of the combined cell
;
; Author: rakudave <[email protected]>
;=============================================================================
Func _GUICtrlTableSpan($iID, $iFrom_Row, $iFrom_Col, $iTo_Row, $iTo_Col)
Local $aTable_Data = StringSplit($iID[0][0], "|") ;$iLeft, $iTop, $iRows, $iCols, $iWidth, $iHeight, $iBorder
For $x = $iFrom_Row To $iTo_Row
For $y = $iFrom_Col To $iTo_Col
GUICtrlDelete($iID[$x][$y])
Next
Next
GUICtrlCreateLabel("", _
$aTable_Data[1] + ($iFrom_Row - 1) * $aTable_Data[5] + $iFrom_Row * $aTable_Data[7] + 1, _
$aTable_Data[2] + ($iFrom_Col - 1) * $aTable_Data[6] + $iFrom_Col * $aTable_Data[7] + 1, _
($iTo_Row - $iFrom_Row + 1) * $aTable_Data[5] + ($iTo_Row - $iFrom_Row) * $aTable_Data[7], _
($iTo_Col - $iFrom_Col + 1) * $aTable_Data[6] + ($iTo_Col - $iFrom_Col) * $aTable_Data[7])
If $aTable_Data[7] > 0 Then GUICtrlSetStyle(-1, $SS_BLACKFRAME)
GUICtrlCreateLabel("", _
$aTable_Data[1] + ($iFrom_Row - 1) * $aTable_Data[5] + $iFrom_Row * $aTable_Data[7] + 2, _
$aTable_Data[2] + ($iFrom_Col - 1) * $aTable_Data[6] + $iFrom_Col * $aTable_Data[7] + 2, _
($iTo_Row - $iFrom_Row + 1) * $aTable_Data[5] + ($iTo_Row - $iFrom_Row) * $aTable_Data[7] - 2, _
($iTo_Col - $iFrom_Col + 1) * $aTable_Data[6] + ($iTo_Col - $iFrom_Col - 1) * $aTable_Data[7] + $aTable_Data[7] - 2)
$iID[$iFrom_Row][$iFrom_Col] = GUICtrlCreateLabel("", _
$aTable_Data[1] + ($iFrom_Row - 1) * $aTable_Data[5] + $iFrom_Row * $aTable_Data[7] + 4, _
$aTable_Data[2] + ($iFrom_Col - 1) * $aTable_Data[6] + $iFrom_Col * $aTable_Data[7] + $aTable_Data[7] + 2, _
($iTo_Row - $iFrom_Row + 1) * $aTable_Data[5] + ($iTo_Row - $iFrom_Row - 1) * $aTable_Data[7] - 4, _
($iTo_Col - $iFrom_Col + 1) * $aTable_Data[6] + ($iTo_Col - $iFrom_Col - 1) * $aTable_Data[7] - 4)
Return $iID[$iFrom_Row][$iFrom_Col]
EndFunc