Что нового

Создание Radio или CheckBox с возможностью указания расположения текста

CreatoR

Must AutoIt!
Команда форума
Администратор
Сообщения
8 175
Репутация
2 331
_GUICtrlCreateRadioCBox - Создаёт элемент Radio или CheckBox с возможностью указания расположения статического текста у элемента (справо, слево, внизу, вверху).

Код:
#include <GUIConstantsEx.au3>

$Gui = GUICreate("_GUICtrlCreateRadioCBox Demo")

$Radio_1 = _GUICtrlCreateRadioCBox("Элемент Radio с текстом по правой стороне", "Right", 0, 20, 30)
$Radio_2 = _GUICtrlCreateRadioCBox("Элемент Radio с текстом снизу", "Bottom", 0, 20, 80)
$Radio_3 = _GUICtrlCreateRadioCBox("Элемент Radio с текстом по левой стороне", "Left", 0, 20, 150, 240)
$Radio_4 = _GUICtrlCreateRadioCBox("Элемент Radio с текстом сверху", "Top", 0, 20, 200)

$CheckBox = _GUICtrlCreateRadioCBox("Элемент CheckBox с текстом по левой стороне", "Left", 1, 20, 290, 260)

GUISetState()

While 1
	$Msg = GUIGetMsg()
	
	Switch $Msg
		Case $GUI_EVENT_CLOSE
			Exit
		Case $Radio_1[1]
			ControlClick($Gui, "", $Radio_1[0])
		Case $Radio_2[1]
			ControlClick($Gui, "", $Radio_2[0])
		Case $Radio_3[1]
			ControlClick($Gui, "", $Radio_3[0])
		Case $Radio_4[1]
			ControlClick($Gui, "", $Radio_4[0])
		Case $CheckBox[1]
			ControlClick($Gui, "", $CheckBox[0])
	EndSwitch
WEnd

;===============================================================================
; Function Name:    _GUICtrlCreateRadioCBox()
; Description:     Create a radio/checkbox control, that allows to set text in several Positions.
; Syntax:          _GUICtrlCreateRadioCBox($sText,$sPosition,$iMode[,$iLeft[,$iTop[,$iWidth[,$iHeight[,$iStyle[,$iExStyle]]]]])
;
; Parameter(s):    $sText      - The text of the control.
;                  $sPosition  - a string that indicates the text align Position (Right, Left, Top, Bottom).
;                  $iMode      - Indicates what should be created, Radio button or CheckBox control.
;                                $iMode = 0 Radio button, $iMode <> 0 CheckBox.
;                  $iLeft       - Left position of the control.
;                  $iTop        - Top position of the control.
;                  $iWidth      - [optional] Width of the control (default is the previously used width).
;                  $iHeight     - [optional] Height of the control (default is the previously used height).
;                  $iStyle      - [optional] Styles for the control (default is -1).
;                  $iExStyle    - [optional] Extended styles for the control (default is -1).
;
; Requirement(s):  None.
;
; Return Value(s): On Seccess:
;                    Return 2-elements array:
;                      $RetArr[0] = Identifier (controlID) of  Radio/CheckBox.
;                      $RetArr[0] = Identifier (controlID) of Label that is holding the text data.
;                  On Failure:
;                     @error set to 1 if "Left" Position used, and $iWidth not defined (Default keyword or -1).
;                     If unable to create control(s), returned 0 in the first element of the array.
;
; Author(s):       G.Sandler a.k.a CreatoR
;
; Example(s):
;		Will create radio button with text align to the Bottom
;     _GUICtrlCreateRadioCBox("My Custom Radio at the Bottom", "Bottom", 0, 20, 80)
;===============================================================================
Func _GUICtrlCreateRadioCBox($sText, $sPosition, $iMode, $iLeft, $iTop, $iWidth=Default, $iHeight=Default, $iStyle=-1, $iExStyle=-1)
	Local $RetArr[2]
	Local $Left = $iLeft, $Top = $iTop
	
	Switch $sPosition
		Case "Bottom"
			$iTop += 20
		Case "Top"
			$Top += 18
		Case "Left"
			If $iWidth = Default Or $iWidth = -1 Then Return SetError(1, 0, 0)
			$iWidth -= 10
			$Left += $iWidth
			$iTop += 3
		Case Else
			$iLeft += 22
			$iTop += 3
	EndSwitch
	
	If $iMode = 0 Then
		$RetArr[0] = GUICtrlCreateRadio("", $Left, $Top, 20, 20, $iStyle, $iExStyle)
	Else
		$RetArr[0] = GUICtrlCreateCheckbox("", $Left, $Top, 20, 20, $iStyle, $iExStyle)
	EndIf
	
	$RetArr[1] = GUICtrlCreateLabel($sText, $iLeft, $iTop, $iWidth, $iHeight, $iStyle, $iExStyle)
	Return $RetArr
EndFunc
 
Верх