ASut Posted September 11, 2010 Share Posted September 11, 2010 (edited) I have follow the e.g given by Tvern in post http://www.autoitscript.com/forum/index.php?showtopic=119508&view=findpost&p=830560 But it won't work for the input field, at the beginning the button is not disable,in order to make it disable, we need to type something,and delete them. how can I make the button disable by default. #include <GUIConstants.au3> $Form1 = GUICreate("Form1", 269, 179, 193, 115) $input = GUICtrlCreateinput("", 80, 48, 97, 17) $Button = GUICtrlCreateButton("Button", 96, 88, 75, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $input if StringLen(GUICtrlRead($Input))<> 0 then GUICtrlSetState($Button,$GUI_ENABLE) Else GUICtrlSetState($Button,$GUI_DISABLE) EndIf EndSwitch WEnd Edited September 11, 2010 by ASut Link to comment Share on other sites More sharing options...
Synct Posted September 11, 2010 Share Posted September 11, 2010 Have it use GUICtrlSetState($Button,$GUI_DISABLE) at the beginning of your code, such as how you would normally set a variable starting value. The variable will set that state at the beginning so when it is displayed it will display disabled. Link to comment Share on other sites More sharing options...
Tvern Posted September 11, 2010 Share Posted September 11, 2010 Have it use GUICtrlSetState($Button,$GUI_DISABLE) at the beginning of your code, such as how you would normally set a variable starting value. The variable will set that state at the beginning so when it is displayed it will display disabled. While this is correct for making sure the button starts disabled, the button still won't update properly, because an input does not set GUIGetMsg() every time it's contents change. The easiest way to solve this is to check the contents of the input on each loop and check if it has changed, then take action accordingly, like this: #include <GUIConstants.au3> Local $sInput, $sOldInput = 1 ;make the value of $sOldInput different from $sInput to trigger an update when it forst runs. $Form1 = GUICreate("Form1", 269, 179, 193, 115) $input = GUICtrlCreateinput("", 80, 48, 97, 17) $Button = GUICtrlCreateButton("Button", 96, 88, 75, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ;Case $input is removed because it's unreliable for what you want to do. EndSwitch $sInput = GUICtrlRead($input) If $sInput <> $sOldInput Then ;only run when the input has changed to prevent flicker If $sInput Then GUICtrlSetState($Button,$GUI_ENABLE) Else GUICtrlSetState($Button,$GUI_DISABLE) EndIf $sOldInput = $sInput ;allows to check if the content has changed on the next run. EndIf WEnd Link to comment Share on other sites More sharing options...
Synct Posted September 11, 2010 Share Posted September 11, 2010 I stand corrected. You might have better luck in the GUI support forum.Graphical User Interface (GUI) Help and Support Link to comment Share on other sites More sharing options...
ASut Posted September 11, 2010 Author Share Posted September 11, 2010 thanks all for helping me to slove my probelm, here is the new code wrote by myself,is it make sense? and how can I highlight the code in the forum? #include <GUIConstants.au3> $Form1 = GUICreate("Form1", 269, 179, 193, 115) $input = GUICtrlCreateinput("", 80, 48, 97, 17) $Button = GUICtrlCreateButton("Button", 96, 88, 75, 25, 0) GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit ;Case $input is removed because it's unreliable for what you want to do. EndSwitch if GUICtrlRead($input)="" then if BitAND(GUICtrlgetState($Button),$GUI_DISABLE) then GUICtrlSetState($Button,$GUI_ENABLE) Else if BitAND(GUICtrlgetState($Button),$GUI_ENABLE) then GUICtrlSetState($Button,$GUI_DISABLE) EndIf WEnd Link to comment Share on other sites More sharing options...
Tvern Posted September 11, 2010 Share Posted September 11, 2010 Yeah that's also a good way of doing it, except that it's the exact opposite from what I thought you wanted. (the button enables when the input is empty) To highlight the code you can use the [ autoit] and [ /autoit] tags (minus the space) Link to comment Share on other sites More sharing options...
ASut Posted September 12, 2010 Author Share Posted September 12, 2010 Yeah that's also a good way of doing it, except that it's the exact opposite from what I thought you wanted. (the button enables when the input is empty) To highlight the code you can use the [ autoit] and [ /autoit] tags (minus the space) thanks Link to comment Share on other sites More sharing options...
ASut Posted September 12, 2010 Author Share Posted September 12, 2010 New question to the $input = GUICtrlCreateinput("", 80, 48, 97, 17) how can I limit it can only type letters and numbers, any symbol is not allowed, if the user have input some symbol, when he press the button, the warming msg box will appear or just keep the button in disable satate. Link to comment Share on other sites More sharing options...
Tvern Posted September 12, 2010 Share Posted September 12, 2010 You can do this in at least 3 ways: 1. Whenever the input has changed, check if the new string has unwanted symbols, remove them and set the text in the input to the result string. 2. Whenever the input has changed, check if the new string has unwanted symbols, leave them in the string, but disable the button. 3. Whenever the button is pressed, check if the new string has unwanted symbols, show a messagebox and to the main loop. For option 1 you're best off using StringRegExpReplace. It might seem a little confusing at first, but it's very usefull. To write the string back to the input, use GuiCtrlSetData. For option 2 and 3 just check if the string is valid with StringIsAlNum( Link to comment Share on other sites More sharing options...
ASut Posted September 13, 2010 Author Share Posted September 13, 2010 You can do this in at least 3 ways:1. Whenever the input has changed, check if the new string has unwanted symbols, remove them and set the text in the input to the result string.2. Whenever the input has changed, check if the new string has unwanted symbols, leave them in the string, but disable the button.3. Whenever the button is pressed, check if the new string has unwanted symbols, show a messagebox and to the main loop.For option 1 you're best off using StringRegExpReplace. It might seem a little confusing at first, but it's very usefull. To write the string back to the input, use GuiCtrlSetData.For option 2 and 3 just check if the string is valid with StringIsAlNum(thanks by using option 2,I got what I want. 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