Sign in to follow this  
Followers 0

_GUICtrlCreateRadioCBox() UDF

4 posts in this topic

#1 ·  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

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites



#2 ·  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 :)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

#3 ·  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 ^_^

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

#4 ·  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?


My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

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