Sign in to follow this  
Followers 0
Terenz

Inputbox focus/not focus

7 posts in this topic

#1 ·  Posted (edited)

Hi,

I want to make a func to clean one or more inputbox on click. My script:

#include <GUIConstants.au3>

$Form1 = GUICreate("Form1", 242, 99)
$Input1 = GUICtrlCreateInput("Some text", 40, 24, 121, 21)
$Input2 = GUICtrlCreateInput("", 40, 50, 121, 21)
$btn1 = GUICtrlCreateButton("Initial focus", 180, 70)
GUICtrlSetState($btn1, $GUI_Focus)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    _Focus($Form1, $Input1, "")
WEnd

Func _Focus($hHandle, $Control, $Data)
    If ControlGetHandle($hHandle, "", ControlGetFocus($hHandle)) = GUICtrlGetHandle($Control) Then
        If GUICtrlRead($Control) <> "" Then
            GUICtrlSetData($Control, $Data)
            Do
            Until ControlGetHandle($hHandle, "", ControlGetFocus($hHandle)) <> GUICtrlGetHandle($Control)
        EndIf
    EndIf
EndFunc   ;==>_Focus

Work fine but has only one big problem, i can't close the GUI if the $Input1 is focused ( by Do Until )

How i can resolve? Thanks

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites



Terenz,

What exactly do you want to happen? Saying "clean one or more inputbox on click" is extremely vague - which input and what click where? :huh:

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Click "inside" a inputbox and if the inputbox has some text delete it


Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Terenz,

Understood. Is this a "prompt" text to suggest what needs to be entered there or any old text that was already entered? :huh:

M23

Edited by Melba23
Typo

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Any old text. I'll set an "default" text to the inputbox, if user click on inputbox it will automatically delete, then the user write something and click on another thing, if click again on inputbox the txt will be automaticcally delete etc.


Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Share this post


Link to post
Share on other sites

Terenz,

Perhaps like this: ;)

#include <GUIConstantsEx.au3>
#include <WinAPI.au3>

Global $aInput[2]

$hGUI = GUICreate("Test", 500, 500)

$aInput[0] = GUICtrlCreateInput("Some text 1", 10, 10, 200, 20)
$aInput[1] = GUICtrlCreateInput("Some text 2", 10, 40, 200, 20)

GUISetState()

While 1

    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP
            For $i = 0 To UBound($aInput) - 1
                If _WinAPI_GetFocus() = GUICtrlGetHandle($aInput[$i]) Then
                    GUICtrlSetData($aInput[$i], "")
                    ExitLoop
                EndIf
            Next
    EndSwitch

WEnd

Any use? :)

M23

1 person likes this

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

Was just doing something like this, when I found this post.
Thought I'd add an alternative.
 

#include <GUIConstantsEx.au3>

$hGUI = GUICreate("GUI", 220, 100)

$iInput1 = GUICtrlCreateInput("Default", 10, 10, 200, 20)
$iInput2 = GUICtrlCreateInput("Default", 10, 40, 200, 20)
$iButton = GUICtrlCreateButton("OK",100,70)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $GUI_EVENT_PRIMARYUP
            $aInfo = GUIGetCursorInfo()
            _ClearData($aInfo[4]) ; Pass control ID to function
        Case $iButton
            _ResetData()
    EndSwitch
WEnd

Func _ClearData(Const $Ctrl)
    If Not $Ctrl Or $Ctrl = $iButton Then ; Return if it's a control we do not want cleared
        Return
    EndIf
    GUICtrlSetData($Ctrl, "")
EndFunc

Func _ResetData()
    GUICtrlSetData($iInput1, "Input 1")
    GUICtrlSetData($iInput2, "Input 2")
EndFunc
Edited by JohnOne

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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