Что нового

_GUICtrlCreateTable - Создание таблицы в GUI

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
Функция для создания таблицы в 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
 

XpycT

Скриптер
Сообщения
380
Репутация
133
Спасибо за "Полезняшку".

Появился вопрос, а как сделать таблицу в которой размер ячеек разный???
 
Автор
CreatoR

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
XpycT [?]
как сделать таблицу в которой размер ячеек разный?
Ну так функция же принимает параметры... или что конкретно имеется в виду?
 

XpycT

Скриптер
Сообщения
380
Репутация
133
CreatoR сказал(а):
что конкретно имеется в виду?

Вот так думаю будет понятней что имеелось в виду
Колонка с Именем
$width = 200
Колонка с Датой
$width = 150
Колонка с Другой Информацией
$width = 300
 
Автор
CreatoR

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8,671
Репутация
2,481
XpycT [?]
Вот так думаю будет понятней что имеелось в виду
Уу, задача не из простых. Нужно ковырять полезняшку, но это уже в другом разделе.
Добавлено:
Сообщение автоматически объединено:

Кстати можно сделать передачу массива данных в такую функцию...
 

Redline

AutoIT Гуру
Сообщения
506
Репутация
375
XpycT сказал(а):
Вот так думаю будет понятней что имеелось в виду
Колонка с Именем
$width = 200
Колонка с Датой
$width = 150
Колонка с Другой Информацией
$width = 300

Вот Table UDF - можно делать более сложные таблицы
 

white raven

Новичок
Сообщения
3
Репутация
0
[Данные, строки] Re: _GUICtrlCreateTable - Создание таблицы в GUI

Код:
#include "Table.au3"
#include <GUIConstantsEx.au3>
#include <SliderConstants.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#include <WinAPI.au3>

;----- GUI (Double Buffered) -----
$GUI = GUICreate("", 600, 600)

;----- Make sure GUI exists BEFORE creating Tables -----
GUISetState()

;----- Lock GUI until tables drawn -----


;----- Table Example 4 -----
$Table4 = _GUICtrlTable_Create(0, 0, 24, 16, 26, 8, 0)
_GUICtrlTable_Set_CellColor_All($Table4, 0xD2F0FF)
_GUICtrlTable_Set_RowHeight($Table4, 1, 35)
_GUICtrlTable_Set_Justify_All($Table4, 1, 1)
_GUICtrlTable_Set_TextFont_All($Table4, 8.5, 800, 0, "Tahoma")
_GUICtrlTable_Set_CellColor_Row($Table4, 1, 0x555555)
_GUICtrlTable_Set_TextColor_All($Table4, 0x555555)
_GUICtrlTable_Set_TextColor_Row($Table4, 1, 0xFFFFFF)
_GUICtrlTable_Set_TextColor_Column($Table4, 1, 0xFFFFFF)
    _GUICtrlTable_Set_CellColor_Column($Table4, 1, 0x555555)

_GUICtrlTable_Set_Text_Row($Table4, 1, "click|Пн|Вт|Ср|Чт|Пт|Сб|Вс")
_GUICtrlTable_Set_Text_Row($Table4, 2, "0|")
_GUICtrlTable_Set_Text_Row($Table4, 3, "1|")
_GUICtrlTable_Set_Text_Row($Table4, 4, "2|")
_GUICtrlTable_Set_Text_Row($Table4, 5, "3|")
_GUICtrlTable_Set_Text_Row($Table4, 6, "4|")
_GUICtrlTable_Set_Text_Row($Table4, 7, "5|")
_GUICtrlTable_Set_Text_Row($Table4, 8, "6|")
_GUICtrlTable_Set_Text_Row($Table4, 9, "7|")
_GUICtrlTable_Set_Text_Row($Table4, 10, "8|")
_GUICtrlTable_Set_Text_Row($Table4, 11, "9|")
_GUICtrlTable_Set_Text_Row($Table4, 12, "10|")
_GUICtrlTable_Set_Text_Row($Table4, 13, "11|")
_GUICtrlTable_Set_Text_Row($Table4, 14, "12|")
_GUICtrlTable_Set_Text_Row($Table4, 15, "13|")
_GUICtrlTable_Set_Text_Row($Table4, 16, "14|")
_GUICtrlTable_Set_Text_Row($Table4, 17, "15|")
_GUICtrlTable_Set_Text_Row($Table4, 18, "16|")
_GUICtrlTable_Set_Text_Row($Table4, 19, "17|")
_GUICtrlTable_Set_Text_Row($Table4, 20, "18|")
_GUICtrlTable_Set_Text_Row($Table4, 21, "19|")
_GUICtrlTable_Set_Text_Row($Table4, 22, "20|")
_GUICtrlTable_Set_Text_Row($Table4, 23, "21|")
_GUICtrlTable_Set_Text_Row($Table4, 24, "22|")
_GUICtrlTable_Set_Text_Row($Table4, 25, "23|")
_GUICtrlTable_Set_Border_Table($Table4, 0x555555)


GUICtrlSetPos(_GUICtrlTable_CellGetID($Table4, 1, 1),200,200)
GUICtrlSetState(_GUICtrlTable_CellGetID($Table4, 1, 1),$GUI_ENABLE)
msgbox(0,0,_GUICtrlTable_CellGetID($Table4, 1, 1))
;----- Unlock GUI to show tables -----

;----- Loop -----
While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg
		Case $GUI_EVENT_CLOSE
			Exit
		Case _GUICtrlTable_CellGetID($Table4, 1, 1)
			msgbox(0,0,0)
	EndSwitch
WEnd


помогите...
у меня такая проблема:
нужно, чтобы при нажатии на отдельный элемент таблицы выходил MsgBox
p.s udf Table.au3
:stars: :'(
 

AZJIO

Меценат
Меценат
Сообщения
2,874
Репутация
1,194
white raven
А чем ListView не устраивает? В нём полный набор управления интерактивной таблицой. А Label это надпись, не для взаимодействия, а для показа.
Можно при клике на GUI - $GUI_EVENT_PRIMARYDOWN проверять относительные координаты мыши, и если они внутри указанного квадрата, то выполнить то-то и то-то.
 
Верх