1stPK Posted November 10 Share Posted November 10 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. expandcollapse popup#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 More sharing options...
Nine Posted November 10 Share Posted November 10 #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 water and ioa747 1 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
1stPK Posted November 11 Author Share Posted November 11 (edited) 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 November 11 by 1stPK Link to comment Share on other sites More sharing options...
Dan_555 Posted November 11 Share Posted November 11 (edited) 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 November 11 by Dan_555 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Nine Posted November 11 Share Posted November 11 (edited) 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 November 11 by Nine 1stPK 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
argumentum Posted November 11 Share Posted November 11 #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 🤷♂️ 1stPK 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
1stPK Posted November 11 Author Share Posted November 11 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 More sharing options...
1stPK Posted November 12 Author Share Posted November 12 expandcollapse popup#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 More sharing options...
argumentum Posted November 12 Share Posted November 12 3 hours ago, 1stPK said: GUIGetMsg() GUIGetMsg() should go to a variable, then do the if/then/else. 1stPK 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Nine Posted November 12 Share Posted November 12 What about $GUI_EVENT_FOCUS and $GUI_EVENT_BLUR ? Never used them before ! 1stPK 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now