Jump to content

To have the hint text automatically disappear when the input cell is clicked.


Recommended Posts

please help me with the following code
to have the hint text automatically disappear when the input cell is clicked.
when the input cell loses focus. This ensures that the hint text will disappear when clicked, and reappear if the input cell is left blank when it loses focus.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

; Create GUI
GUICreate("Test Suggestion", 300, 100)
Local $hintText = "suggested content..."
Local $input = GUICtrlCreateInput($hintText, 10, 10, 280, 30)
Local $isHintVisible = True  ; Variable that tracks the state of the hint

GUISetState(@SW_SHOW)

; GUI Loop
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch

    ; Remove hint line when user clicks input box for the first time
    If GUICtrlRead($input) = $hintText And _IsMouseOverControl($input) And $isHintVisible Then
        GUICtrlSetData($input, "")
        $isHintVisible = False
    EndIf

    ; Restore hint line if input field is empty when focus is lost
    If GUICtrlRead($input) = "" And Not _IsMouseOverControl($input) And Not $isHintVisible Then
        GUICtrlSetData($input, $hintText)
        $isHintVisible = True
    EndIf
WEnd

; Function to check if the mouse is over the control
Func _IsMouseOverControl($ctrlID)
    Local $aPos = ControlGetPos("", "", $ctrlID)
    If IsArray($aPos) Then
        Local $x = MouseGetPos(0)
        Local $y = MouseGetPos(1)
        If $x >= $aPos[0] And $x <= $aPos[0] + $aPos[2] And $y >= $aPos[1] And $y <= $aPos[1] + $aPos[3] Then
            Return True
        EndIf
    EndIf
    Return False
EndFunc

 

Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <GuiEdit.au3>

Example()

Func Example()
  GUICreate("Test Suggestion", 300, 100)
  Local $idButton = GUICtrlCreateButton("OK", 10, 70, 100, 20)
  Local $input = GUICtrlCreateInput("", 10, 10, 280, 30)
  _GUICtrlEdit_SetCueBanner($input, "suggested content...")

  GUISetState()

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
EndFunc   ;==>Example

 

Link to comment
Share on other sites

13 hours ago, Nine said:
#include <GUIConstants.au3>
#include <GuiEdit.au3>

Example()

Func Example()
  GUICreate("Test Suggestion", 300, 100)
  Local $idButton = GUICtrlCreateButton("OK", 10, 70, 100, 20)
  Local $input = GUICtrlCreateInput("", 10, 10, 280, 30)
  _GUICtrlEdit_SetCueBanner($input, "suggested content...")

  GUISetState()

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
    EndSwitch
  WEnd
EndFunc   ;==>Example

 

instead of pressing the "OK" button, just move the mouse out of the input box, or focus the mouse in another position. Then the suggestion content will automatically reappear?
 

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>

Example()

Func Example()
    GUICreate("Test Suggestion", 300, 100)
    Local $input = GUICtrlCreateInput("", 10, 10, 280, 30)
    _GUICtrlEdit_SetCueBanner($input, "suggested content...")

    GUISetState()

    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $GUI_EVENT_PRIMARYDOWN ; Left click event
                ; Check if input field is empty and does not have focus
                If GUICtrlRead($input) = "" And ControlGetFocus("Test Suggestion") <> $input Then
                    _GUICtrlEdit_SetCueBanner($input, "suggested content...")
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>Example

 

Edited by 1stPK
Link to comment
Share on other sites

The question is: Do you want to write your own version of what already exists as a single command ?

You have to have a control which can take away the focus from the inputbox.
Press tab to switch to the other inputbox and back and see how the suggestion text appears...
 

#include <GUIConstantsEx.au3>
#include <GuiEdit.au3>

Example()

Func Example()
    GUICreate("Test Suggestion", 300, 100)
    Local $input = GUICtrlCreateInput("", 10, 10, 280, 30)
    Local $input1 = GUICtrlCreateInput("", 10, 40, 280, 30)
    _GUICtrlEdit_SetCueBanner($input, "suggested content...")
    _GUICtrlEdit_SetCueBanner($input1, "Not suggested content...")

    GUISetState()

    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>Example

add this before GuiSetState() :
    Local $label = GUICtrlCreateLabel("give me focus",10,70,280,20)
    ControlFocus($hwnd,"",$label)

to see that both input boxes initially display the hint text.

Edited by Dan_555

Some of my script sourcecode

Link to comment
Share on other sites

Maybe this hack :

#include <GUIConstants.au3>
#include <GuiEdit.au3>

Example()

Func Example()
  Local $hGUI = GUICreate("Test Suggestion", 300, 100)
  Local $idButton = GUICtrlCreateButton("", 0, 0, 0, 0)
  Local $input = GUICtrlCreateInput("", 10, 10, 280, 30)
  _GUICtrlEdit_SetCueBanner($input, "suggested content...")

  GUISetState()

  While True
    Switch GUIGetMsg()
      Case $GUI_EVENT_CLOSE
        ExitLoop
      Case $GUI_EVENT_PRIMARYDOWN
        If GUIGetCursorInfo()[4] <> $input Then ControlFocus($hGUI, "", $idButton)
    EndSwitch
  WEnd
EndFunc   ;==>Example

You can TAB or click away from the input box...

Edited by Nine
Link to comment
Share on other sites

#include <GUIConstants.au3>
#include <GuiEdit.au3>

Example()
Func Example()
    Local $hGUI = GUICreate("Test Suggestion", 300, 100)
    Local $idButton = GUICtrlCreateButton("", 0, 0, 0, 0)
    Local $input = GUICtrlCreateInput("", 10, 10, 280, 30)
    Local $input1 = GUICtrlCreateInput("", 10, 40, 280, 30)
    _GUICtrlEdit_SetCueBanner($input, "suggested content...")
    _GUICtrlEdit_SetCueBanner($input1, "Not suggested content...")
    GUISetState()
    While True
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete()
                ExitLoop
            Case $GUI_EVENT_PRIMARYDOWN
                $aInfo = GUIGetCursorInfo()
                If @error Then ContinueLoop
                If $aInfo[4] = 0 Then GUICtrlSetState($idButton, $GUI_FOCUS)
        EndSwitch
    WEnd
EndFunc   ;==>Example

🤷‍♂️

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

3 hours ago, Nine said:

Có thể là mẹo này  :

#include <GUIConstants.au3> 
#include <GuiEdit.au3>
 
Ví dụ ( ) 

Hàm Ví dụ ( ) 
  Local  $hGUI  =  GUICreate ( "Gợi ý kiểm tra" ,  300 ,  100 ) 
  Local  $idButton  =  GUICtrlCreateButton ( "" ,  0 ,  0 ,  0 ,  0 ) 
  Local  $input  =  GUICtrlCreateInput ( "" ,  10 ,  10 ,  280 ,  30 ) 
  _ GUICtrlEdit _ SetCueBanner ( $input ,  "nội dung được đề xuất..." ) 

  GUISetState ( ) 

  While  True 
    Switch  GUIGetMsg ( ) 
      Case  $GUI_EVENT_CLOSE 
        ExitLoop 
      Case  $GUI_EVENT_PRIMARYDOWN 
        If  GUIGetCursorInfo ( ) [ 4 ]  <>  $input  Then  ControlFocus ( $hGUI ,  "" ,  $idButton ) 
    EndSwitch 
  WEnd 
EndFunc    ;==>Ví dụ

Bạn có thể nhấn TAB hoặc nhấp chuột ra khỏi hộp nhập liệu...

thank you so much this is the way i needed.

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>

Local $hGUI = GUICreate("ToolTip Example", 300, 200)

Local $btn = GUICtrlCreateButton("Hover over me", 100, 50, 100, 30)
GUICtrlSetOnEvent($btn, "OnButtonClick")

Local $acc_e = GUICtrlCreateInput('Nhập tài khoản', 15, 20, 220, 18)
GUISetState()

Local $bToolTipVisibleButton = False
Local $bToolTipVisibleInput = False

While 1
    Local $aCursorInfo = GUIGetCursorInfo($hGUI)

    If $aCursorInfo[4] = $btn Then
        If Not $bToolTipVisibleButton Then
            ToolTip("This is a button tooltip", MouseGetPos(0), MouseGetPos(1))
            $bToolTipVisibleButton = True
        EndIf
    ElseIf $bToolTipVisibleButton Then
        ToolTip("")
        $bToolTipVisibleButton = False
    EndIf

    If $aCursorInfo[4] = $acc_e Then
        If Not $bToolTipVisibleInput Then
            ToolTip("This is an input tooltip", MouseGetPos(0), MouseGetPos(1))
            $bToolTipVisibleInput = True
            If GUICtrlRead($acc_e) = 'Nhập tài khoản' Then
                GUICtrlSetData($acc_e, '')
            EndIf
        EndIf
    ElseIf $bToolTipVisibleInput Then
        ToolTip("")
        $bToolTipVisibleInput = False
        If GUICtrlRead($acc_e) = '' Then
            GUICtrlSetData($acc_e, 'Nhập tài khoản')
        EndIf
    EndIf

    ; Theo dõi sự kiện focus và blur của ô input
 Switch GUIGetMsg()
    Case $GUI_EVENT_CLOSE
        Exit
    Case $acc_e
        ; Kiểm tra focus và blur bằng cách theo dõi sự kiện tiêu điểm
        If GUIGetMsg() = $GUI_EVENT_FOCUS Then
            OnInputFocus()
        ElseIf GUIGetMsg() = $GUI_EVENT_BLUR Then
            OnInputBlur()
        EndIf
EndSwitch


    Sleep(10)
WEnd

Func OnInputFocus()
    If GUICtrlRead($acc_e) = 'Nhập tài khoản' Then
        GUICtrlSetData($acc_e, '')
    EndIf
EndFunc

Func OnInputBlur()
    If GUICtrlRead($acc_e) = '' Then
        GUICtrlSetData($acc_e, 'Nhập tài khoản')
    EndIf
EndFunc

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...