Input control for the GUI with label and rounded corners

 


The script demonstrates the use of functions to create input fields with and without labels, and rounded corners,
where the font size changes dynamically depending on the height of Input control.

Valid value for Corner    [0=Rectangle]   to   [($Height/2)=Round],   Default=($Height/4)
 

Example1: _CreateInputWL()

#include <GUIConstants.au3>

_Example()

;----------------------------------------------------------------------------------------
Func _Example()
    Local $hGUI = GUICreate("Shipping Details", 390, 320)
    GUISetStyle(-1, $WS_EX_COMPOSITED)
    GUISetBkColor(0x0D1117)

    Local $ShippingDetails = GUICtrlCreateLabel("Shipping Address", 10, 5, 380, 30)
    GUICtrlSetFont(-1, 18, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0xFFD800)

    Local $Exit = GUICtrlCreateButton("EXIT", 20, 270, 95, 40)
    GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x0D1117)
    GUICtrlSetBkColor(-1, 0xFFD800)

    Local $Corner = -1 ; *** <- Valid value from [0=Rectangle] to [($Height/2)=Round],  Default=($Height/4) *** <-

    Local $FirstName = _CreateInputWL("First Name:", "John", 10, 50, 180, 40, 0x00FFFF, $Corner)
    Local $LastName = _CreateInputWL("Last Name:", "Doe", 200, 50, 180, 40, 0x00FFFF, $Corner)

    Local $Address = _CreateInputWL("Address:", "123 Main St", 10, 100, 230, 40, 0x00FFFF, $Corner)
    Local $Apt = _CreateInputWL("Apt:", "4B", 250, 100, 130, 40, 0x00FFFF, $Corner)

    Local $City = _CreateInputWL("City:", "Springfield", 10, 150, 140, 40, 0x00FFFF, $Corner)
    Local $State = _CreateInputWL("State:", "IL", 160, 150, 80, 40, 0x00FFFF, $Corner)
    Local $ZipCode = _CreateInputWL("Zip Code:", "627 01", 250, 150, 130, 40, 0x00FFFF, $Corner)

    Local $Email = _CreateInputWL("Email:", "jdoe627@gmail.com", 10, 200, 230, 40, 0x00FFFF, $Corner)
    Local $Phone = _CreateInputWL("Phone:", "0123456789", 250, 200, 130, 40, 0x00FFFF, $Corner)
    GUISetState(@SW_SHOW)

    Sleep(4000)

    GUICtrlSetData($Email[0], "Johndoe@gmail.com")
    GUICtrlSetData($Phone[1], "Mobile:")
    GUICtrlSetData($Phone[0], "654210789")

    ;**********************************
    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $Exit
                ExitLoop
        EndSwitch
    WEnd
    ;**********************************

EndFunc   ;==>_Example

;----------------------------------------------------------------------------------------
Func _CreateInputWL($Label, $Text, $Left, $Top, $Width, $Height, $Color, $Corner = -1)
    ; $Corner Valid value [0=Rectangle] to [($Height/2)=Round],  Default=($Height/4)

    ; Validate parameters
    If $Corner < 0 Or $Corner = Default Then $Corner = $Height / 4
    If $Corner > $Height / 2 Then $Corner = $Height / 2
    If $Width <= 0 Or $Height <= 0 Then
        Return SetError(1, 0, 0)
    EndIf
    ; graphic
    GUICtrlCreateGraphic($Left, $Top, $Width, $Height)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, $Color, $Color)
    ; body
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, $Corner, 0, $Width - ($Corner * 2), $Height) ; outer part
    GUICtrlSetGraphic(-1, $GUI_GR_RECT, 0, $Corner, $Width, $Height - ($Corner * 2)) ; inner  part
    ; corners
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, 0, $Corner * 2, $Corner * 2) ; Top-left
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, $Width - $Corner * 2, 0, $Corner * 2, $Corner * 2) ; Top-right
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, 0, $Height - $Corner * 2, $Corner * 2, $Corner * 2) ; Bottom-left
    GUICtrlSetGraphic(-1, $GUI_GR_ELLIPSE, $Width - $Corner * 2, $Height - $Corner * 2, $Corner * 2, $Corner * 2) ; Bottom-right
    GUICtrlSetState(-1, $GUI_DISABLE)

    Local $idLabel = GUICtrlCreateLabel($Label, $Left + $Corner, $Top, $Width - ($Corner * 2), $Height * 0.4)
    GUICtrlSetBkColor($idLabel, $Color)
    GUICtrlSetFont($idLabel, $Height * 0.25)
    Local $idInput1 = GUICtrlCreateInput($Text, $Left + $Corner, $Top + ($Height * 0.35), $Width - ($Corner * 2), $Height * 0.60, -1 ,$WS_EX_COMPOSITED)
    GUICtrlSetFont($idInput1, $Height * 0.35)
    GUICtrlSetBkColor($idInput1, $Color)

    Local $aRet[] = [$idInput1, $idLabel]

    Return $aRet ; Return both ID
EndFunc   ;==>_CreateInputWL
;----------------------------------------------------------------------------------------

Comments

Popular posts from this blog

ControlGetHandle ($hWnd, "", "[REGEXPCLASS:<>; INSTANCE:<>]")

Simple Calculator