Sign in to follow this  
Followers 0

_GUICtrlCreateRadioCBox() UDF

4 posts in this topic

Posted (edited)

Hi all,

This is a simple UDF that allows to create radio button or checkbox with text align to different sides:

;Example

#include <GuiConstants.au3>

$Gui = GuiCreate("_GUICtrlCreateRadioCBox Demo")

$Radio_1 = _GUICtrlCreateRadioCBox("My Custom Radio at the Right", "Right", 0, 20, 30)
$Radio_2 = _GUICtrlCreateRadioCBox("My Custom Radio at the Bottom", "Bottom", 0, 20, 80)
$Radio_3 = _GUICtrlCreateRadioCBox("My Custom Radio at the Left", "Left", 0, 20, 150, 150)
$Radio_4 = _GUICtrlCreateRadioCBox("My Custom Radio at the top", "Top", 0, 20, 200)

$CheckBox = _GUICtrlCreateRadioCBox("My Custom CheckBox with text at the Left", "Left", 1, 20, 290, 215)

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


;The UDF

;===============================================================================
; Function Name:    _GUICtrlCreateRadioCBox()
; Description:     Create a radio/checkbox control, with ability to set text from different directions.
; Syntax:          _GUICtrlCreateRadioCBox($sText, $sDirection, $iMode [,$Left [,$Top [,$Width [,$Height [,$Style [,$exStyle ]]]]]])
;
; Parameter(s):    $sText      - The text of the control.
;                  $sDirection - a string that indicate the text align direction (Right, Left, Top, Bottom).
;                  $iMode      - Indicates what should be createed, Radio button or CheckBox control.
;                                $iMode = 0 Radio button, $iMode <> 0 CheckBox.
;                  $Left       - The left side of the control.
;                  $Top        - The top of the control.
;                  $Width      - [optional] The width of the control (default is the previously used width).
;                  $Height     - [optional] The height of the control (default is the previously used height).
;                  $Style      - [optional] Defines the style of the control (default is -1).
;                  $exStyle    - [optional] Defines the extended style of the control (default is -1).
;
; Requirement(s):  None.
;
; Return Value(s): On Seccess:
;                    Return 2-elements array:
;                      $RetArr[0] = Identifier (controlID) of the Radio/CheckBox.
;                      $RetArr[0] = Identifier (controlID) of the Label with the text.
;                  On Failure:
;                     @error set to 1 if "Left" direction used, and $Width not defined (Default keyword or -1).
;                     If unable to create control(s), returned 0 in the host 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, $sDirection, $iMode, $Left, $Top, $Width=Default, $Height=Default, $Style=-1, $exStyle=-1)
	Local $RetArr[2]
	Local $rLeft = $Left, $rTop = $Top
	
	Switch $sDirection
		Case "Bottom"
			$Top += 20
		Case "Top"
			$rTop += 18
		Case "Left"
			If $Width = Default Or $Width = -1 Then Return SetError(1, 0, 0)
			$Width -= 10
			$rLeft += $Width
			$Top += 3
		Case Else
			$Left += 22
			$Top += 3
	EndSwitch
	
	If $iMode = 0 Then
		$RetArr[0] = GUICtrlCreateRadio("", $rLeft, $rTop, 20, 20, $Style, $exStyle)
	Else
		$RetArr[0] = GUICtrlCreateCheckbox("", $rLeft, $rTop, 20, 20, $Style, $exStyle)
	EndIf
	$RetArr[1] = GUICtrlCreateLabel($sText, $Left, $Top, $Width, $Height, $Style, $exStyle)
	Return $RetArr
EndFunc

Edit: Spell; Buttom replaced with Bottom, thanks martin :)

Edited by MsCreatoR

Share this post


Link to post
Share on other sites



Posted

Hi all,

This is a simple UDF that allows to create radio button or checkbox with text align to different sides:

;Example

#include <GuiConstants.au3>

$Gui = GuiCreate("_GUICtrlCreateRadioCBox Demo")

$Radio_1 = _GUICtrlCreateRadioCBox("My Custom Radio at the Right", "Right", 0, 20, 30)
$Radio_2 = _GUICtrlCreateRadioCBox("My Custom Radio at the Buttom", "Buttom", 0, 20, 80)
$Radio_3 = _GUICtrlCreateRadioCBox("My Custom Radio at the Left", "Left", 0, 20, 150, 150)
$Radio_4 = _GUICtrlCreateRadioCBox("My Custom Radio at the top", "Top", 0, 20, 200)

$CheckBox = _GUICtrlCreateRadioCBox("My Custom CheckBox with text at the Left", "Left", 1, 20, 290, 215)

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


;The UDF

;===============================================================================
; Function Name:    _GUICtrlCreateRadioCBox()
; Description:     Create a radio/checkbox control, with ability to set text in different directions.
; Syntax:          _GUICtrlCreateRadioCBox($sText, $sDirection, $iMode [,$Left [,$Top [,$Width [,$Height [,$Style [,$exStyle ]]]]]])
;
; Parameter(s):    $sText      - The text of the control.
;                  $sDirection - a string that indicate the text align direction (Right, Left, Top, Buttom).
;                  $iMode      - Indicates what should be createed, Radio button or CheckBox control.
;                                $iMode = 0 Radio button, $iMode <> 0 CheckBox.
;                  $Left       - The left side of the control.
;                  $Top        - The top of the control.
;                  $Width      - [optional] The width of the control (default is the previously used width).
;                  $Height     - [optional] The height of the control (default is the previously used height).
;                  $Style      - [optional] Defines the style of the control (default is -1).
;                  $exStyle    - [optional] Defines the extended style of the control (default is -1).
;
; Requirement(s):  None.
;
; Return Value(s): On Seccess:
;                    Return 2-elements array:
;                      $RetArr[0] = Identifier (controlID) of the Radio/CheckBox.
;                      $RetArr[1] = Identifier (controlID) of the Label with the text.
;                  On Failure:
;                     @error set to 1 if "Left" direction used, and $Width not defined (Default keyword or -1).
;                     If unable to create control(s), returned 0 in the host element of the array.
;
; Author(s):       G.Sandler a.k.a CreatoR
;
; Example(s):
;		Will create radio button with text align to the buttom
;     _GUICtrlCreateRadioCBox("My Custom Radio at the Buttom", "Buttom", 0, 20, 80)
;===============================================================================
Func _GUICtrlCreateRadioCBox($sText, $sDirection, $iMode, $Left, $Top, $Width=Default, $Height=Default, $Style=-1, $exStyle=-1)
	Local $RetArr[2]
	Local $rLeft = $Left, $rTop = $Top
	
	Switch $sDirection
		Case "Buttom"
			$Top += 20
		Case "Top"
			$rTop += 18
		Case "Left"
			If $Width = Default Or $Width = -1 Then Return SetError(1, 0, 0)
			$Width -= 10
			$rLeft += $Width
			$Top += 3
		Case Else
			$Left += 22
			$Top += 3
	EndSwitch
	
	If $iMode = 0 Then
		$RetArr[0] = GUICtrlCreateRadio("", $rLeft, $rTop, 20, 20, $Style, $exStyle)
	Else
		$RetArr[0] = GUICtrlCreateCheckbox("", $rLeft, $rTop, 20, 20, $Style, $exStyle)
	EndIf
	$RetArr[1] = GUICtrlCreateLabel($sText, $Left, $Top, $Width, $Height, $Style, $exStyle)
	Return $RetArr
EndFunc

Nice idea MsCreatoR.

(Perhaps you could correct Buttom to Bottom) which brings me to the next point; you seem to have a parameter (I need to get my glasss to verify this), which is call SexStyle! Maybe you've posted in the wrong forum :)

Share this post


Link to post
Share on other sites

Posted

Nice idea MsCreatoR.

Thanks, i thought so too.

Perhaps you could correct Buttom to Bottom

Thanks, corrected first post :)

you seem to have a parameter (I need to get my glasss to verify this), which is call SexStyle!

I can't find it ^_^

Share this post


Link to post
Share on other sites

Posted

Nice work! Is there any change of you encorporating your hover udf with this to make it appear like it's hovering when you're over the label?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0