Jump to content
Sign in to follow this  
Wakaman

Form Advanced Feature question

Recommended Posts

Wakaman

Hello,

Someone please help me out. I am looking to design a form similar to the Microsoft Windows login screen that have an "option>>" button that will expand with more fields when clicked. For example I will have:

Username: _________

paswword: _________

Then and Advanced button that when click will expand the form to show

Domain Name__

etc

Any help will be appreciated

Share this post


Link to post
Share on other sites
GEOSoft

#include<WindowsConstants.au3>
#Include<GUIConstantsEx.au3>
$iWidth = 300
$iHeight = 200
$Toggle = True
$Frm_main = GUICreate("Welcome", $iWidth, $iHeight)
GUISetState()

$Frm_1 = GUICreate("window 1", $iWidth, $iHeight*2, 0, 0, $WS_CHILD, -1, $Frm_main)
$Btn_Expand = GUICtrlCreateButton("Show Details", ($iWidth/2)-40, $iHeight - 60, 80, 30)
GUISetBkColor(0xff0000)
GUISetState()

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Btn_Expand
            _ToggleWindow()
    EndSwitch
WEnd

Func _ToggleWindow()
    If $Toggle Then
        WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight *2)
        GUICtrlSetData($Btn_Expand, "Hide Details")
    Else
        WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight)
        GUICtrlSetData($Btn_Expand, "Show Details")
    EndIf
    $Toggle = NOT $Toggle
EndFunc

EDIT: Made it a simple 2 windows instead of 3. The only reason for using 2 windows is to give you a separate known area to create the additional controls in.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Wakaman

Thanks. This is exactly what I am looking for. I noticed you use WinMove to resize windows, is there a build in Function to move buttons as well? For example, when I click on "Show Details" it stays in the middle, and I am trying to move it to the bottom when the window expands.

Thank You

#include<WindowsConstants.au3>
#Include<GUIConstantsEx.au3>
$iWidth = 300
$iHeight = 200
$Toggle = True
$Frm_main = GUICreate("Welcome", $iWidth, $iHeight)
GUISetState()

$Frm_1 = GUICreate("window 1", $iWidth, $iHeight*2, 0, 0, $WS_CHILD, -1, $Frm_main)
$Btn_Expand = GUICtrlCreateButton("Show Details", ($iWidth/2)-40, $iHeight - 60, 80, 30)
GUISetBkColor(0xff0000)
GUISetState()

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Btn_Expand
            _ToggleWindow()
    EndSwitch
WEnd

Func _ToggleWindow()
    If $Toggle Then
        WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight *2)
        GUICtrlSetData($Btn_Expand, "Hide Details")
    Else
        WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight)
        GUICtrlSetData($Btn_Expand, "Show Details")
    EndIf
    $Toggle = NOT $Toggle
EndFunc

EDIT: Made it a simple 2 windows instead of 3. The only reason for using 2 windows is to give you a separate known area to create the additional controls in.

Share this post


Link to post
Share on other sites
GEOSoft

I knew I should have left in the third window.

You could also just add a second button to the bottom of the second window and use the same toggle function. You will then have to hide the first button and show the second, and reverse that operation again on the next toggle.

Give me a while to get a few things done and I'll modify it.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
GEOSoft

#include<WindowsConstants.au3>
#Include<GUIConstantsEx.au3>
$iWidth = 300
$iHeight = 200
$Toggle = True
$Frm_main = GUICreate("Welcome", $iWidth, $iHeight)
GUISetState()

$Frm_1 = GUICreate("window 1", $iWidth, $iHeight*2, 0, 0, $WS_CHILD, -1, $Frm_main)
$Btn_Expand = GUICtrlCreateButton("Show Details", ($iWidth/2)-40, $iHeight - 60, 80, 30)
$Btn_Collapse = GUICtrlCreateButton("Hide Details", ($iWidth/2)-40, ($iHeight *2) - 90, 80, 30)
GUICtrlSetState($Btn_Collapse, $GUI_HIDE)
GUISetBkColor(0xff0000)
GUISetState()

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Btn_Expand, $Btn_Collapse
            _ToggleWindow()
    EndSwitch
WEnd

Func _ToggleWindow()
    If $Toggle Then
        GUICtrlSetState($Btn_Collapse, $GUI_SHOW)
        GUICtrlSetState($Btn_Expand, $GUI_HIDE)
        WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight *2)
        ;GUICtrlSetData($Btn_Expand, "Hide Details")
    Else
        GUICtrlSetState($Btn_Collapse, $GUI_HIDE)
        GUICtrlSetState($Btn_Expand, $GUI_SHOW)
        WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight)
        ;GUICtrlSetData($Btn_Expand, "Show Details")
    EndIf
    $Toggle = NOT $Toggle
EndFunc


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
ResNullius

@George,

Anything wrong with one window and GuiCtrlSetResizing() ?

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

$iWidth = 300
$iHeight = 200
$Toggle = True
$Frm_main = GUICreate("Welcome", $iWidth, $iHeight)
GUISetState()

$inpOne = GUICtrlCreateInput("INPUT HERE", 10, 10)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

$inpTwo = GUICtrlCreateInput("... AND HERE", 10, 40)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

$Btn_Expand = GUICtrlCreateButton("Show Details", ($iWidth / 2) - 40, $iHeight - 60, 80, 30)
GUICtrlSetResizing(-1, $GUI_DOCKSTATEBAR)

$lblHiddenMsg = GUICtrlCreateLabel("The devil is in the details, hidden or otherwise", 10, $iHeight * 2 - 200)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

GUISetBkColor(0xff0000)
GUISetState()

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Btn_Expand
            _ToggleWindow()
    EndSwitch
WEnd

Func _ToggleWindow()

    If $Toggle Then
        WinMove($Frm_main, "", Default, Default, $iWidth, $iHeight * 2)
        GUICtrlSetData($Btn_Expand, "Hide Details")
    Else
        WinMove($Frm_main, "", Default, Default, $iWidth, $iHeight)
        GUICtrlSetData($Btn_Expand, "Show Details")
    EndIf
    $Toggle = Not $Toggle
EndFunc   ;==>_ToggleWindow

Share this post


Link to post
Share on other sites
GEOSoft

@George,

Anything wrong with one window and GuiCtrlSetResizing() ?

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

$iWidth = 300
$iHeight = 200
$Toggle = True
$Frm_main = GUICreate("Welcome", $iWidth, $iHeight)
GUISetState()

$inpOne = GUICtrlCreateInput("INPUT HERE", 10, 10)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

$inpTwo = GUICtrlCreateInput("... AND HERE", 10, 40)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

$Btn_Expand = GUICtrlCreateButton("Show Details", ($iWidth / 2) - 40, $iHeight - 60, 80, 30)
GUICtrlSetResizing(-1, $GUI_DOCKSTATEBAR)

$lblHiddenMsg = GUICtrlCreateLabel("The devil is in the details, hidden or otherwise", 10, $iHeight * 2 - 200)
GUICtrlSetResizing(-1, $GUI_DOCKALL)

GUISetBkColor(0xff0000)
GUISetState()

While 1
    $hMsg = GUIGetMsg()
    Switch $hMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Btn_Expand
            _ToggleWindow()
    EndSwitch
WEnd

Func _ToggleWindow()

    If $Toggle Then
        WinMove($Frm_main, "", Default, Default, $iWidth, $iHeight * 2)
        GUICtrlSetData($Btn_Expand, "Hide Details")
    Else
        WinMove($Frm_main, "", Default, Default, $iWidth, $iHeight)
        GUICtrlSetData($Btn_Expand, "Show Details")
    EndIf
    $Toggle = Not $Toggle
EndFunc   ;==>_ToggleWindow

Nothing at all and I actually did one that way but decided to opt for the 2 windows so he could see what was happening and to provide a separate container for the controls, which of corse he doesn't need. At one point I also had a 3 window Demo where it only used one button which was the only control on the 3rd window. The Main Window was a container, the second held the input controls.

I resized the first and moved the third and the second was always oversized. If that makes any sense. I think my intention there was to put the original inputs on the first, the expanded details on the second and the button on the third. But I got off track someplace, probably when the old oversize/resize trick popped into mind.


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
Wakaman

Thanks GeoSoft for the original code and AdmiralAlkex for the ControlMove() idea. I decided to use the ControlMove() function and it worked well. See my Toggle form code below just in case it might be helpful to anyone.

Question: My current issue now with the code is that, I can not use the key board tab key to move from one input field to the other. It just hightlight the field and I have to use the mouse to click on next field..Anyone experienced this before or is something I am missing in the form.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <ComboConstants.au3>
#include <StaticConstants.au3>



;GUI Look and Feel
$iWidth = 354;300
$iHeight = 176;200
$Toggle = True

$Frm_main = GUICreate("Main Window", $iWidth, $iHeight, 263, 217, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
GUISetState()

$Frm_1 = GUICreate("window 1", $iWidth, $iHeight*2, 0, 0, $WS_CHILD, -1, $Frm_main)
$txtUserID = GUICtrlCreateLabel("Username:", 8, 80, 43, 17)
$txtUserPassword = GUICtrlCreateLabel("Password:", 8, 112, 53, 17)
$userIDInput = GUICtrlCreateInput("", 64, 72, 281, 21)
;GUICtrlSetColor(-1, 0x800000)
$userPasswordInput = GUICtrlCreateInput("", 64, 104, 281, 21, BitOR($ES_PASSWORD,$ES_AUTOHSCROLL))
;GUICtrlSetColor(-1, 0x800000)
$buttonDriveMap = GUICtrlCreateButton("OK", 72, 144, 83, 25, $WS_GROUP)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$buttonCancel = GUICtrlCreateButton("Cancel", 157, 144, 91, 25, $WS_GROUP)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Btn_Expand = GUICtrlCreateButton("Advanced >>", 255, 144, 91,25, $WS_GROUP) ;91,25
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$lblTitle = GUICtrlCreateLabel("Main Title", 40, 8, 283, 24, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x800000)
$lblTitle2 = GUICtrlCreateLabel("Sub Title", 96, 32, 176, 20, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x800000)
$DomainController = GUICtrlCreateCombo("Item1", 64, 207, 210, 21,$CBS_DROPDOWNLIST)
       GUICtrlSetData(-1, "Item2|Item3|Item3")
       GUICtrlSetState(-1, $GUI_HIDE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $msg        = GUIGetMsg()

    Select

        Case $msg = $buttonCancel
            Exit

        Case $msg = $Btn_Expand
            _ToggleWindow()

        Case $msg = $buttonDriveMap
            $oMyError  = ObjEvent("AutoIt.Error", "_ADDoError"); Install a custom error handler
            $alt_userid = GUICtrlRead($userIDInput)
            $alt_password = GUICtrlRead ($userPasswordInput)
            $strHostServer = GUICtrlRead ($DomainController)
            ExitLoop

        Case $msg = $GUI_EVENT_CLOSE
            Exit
      ExitLoop

EndSelect

WEnd
Func _ToggleWindow()
    If $Toggle Then
        WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight *1.78)
        GUICtrlSetData($Btn_Expand, "Advanced<<")
        ControlMove ("","", $buttonDriveMap,72,250);215
        ControlMove ("","",$buttonCancel, 157,250);120
        ControlMove ("","",$Btn_Expand,255,250);252
        $domainInput = GUICtrlCreateInput("ABC.COM", 64, 175, 210, 21);120
        $lbldomain = GUICtrlCreateLabel("Domain:", 8, 175, 55, 17);109
        $lblDC = GUICtrlCreateLabel("Server:", 8, 207, 55, 17)
        $DomainController = GUICtrlCreateCombo("Item1", 64, 207, 210, 21,$CBS_DROPDOWNLIST)
       GUICtrlSetData(-1, "Item2|Item3|Item3")
    Else
       WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight+30)
        GUICtrlSetData($Btn_Expand, "Advanced>>")
        ControlMove ("","", $buttonDriveMap,72,144)
        ControlMove ("","",$buttonCancel, 157,144)
        ControlMove ("","",$Btn_Expand,255,144)
    EndIf
    $Toggle = NOT $Toggle
EndFunc

Nothing at all and I actually did one that way but decided to opt for the 2 windows so he could see what was happening and to provide a separate container for the controls, which of corse he doesn't need. At one point I also had a 3 window Demo where it only used one button which was the only control on the 3rd window. The Main Window was a container, the second held the input controls.

I resized the first and moved the third and the second was always oversized. If that makes any sense. I think my intention there was to put the original inputs on the first, the expanded details on the second and the button on the third. But I got off track someplace, probably when the old oversize/resize trick popped into mind.

Share this post


Link to post
Share on other sites
GEOSoft

Thanks GeoSoft for the original code and AdmiralAlkex for the ControlMove() idea. I decided to use the ControlMove() function and it worked well. See my Toggle form code below just in case it might be helpful to anyone.

Question: My current issue now with the code is that, I can not use the key board tab key to move from one input field to the other. It just hightlight the field and I have to use the mouse to click on next field..Anyone experienced this before or is something I am missing in the form.

I don't see whats wrong there yet however I did clean up the GUI. Don't create GUI controls in a function like you did. Create them with the rest of the GUI code and at most you will have to show/hide the controls. The way you had it, every second time you clicked the Advanced button you created new controls over top of the old ones. Yo could have gotten away with it if You also use GUICtrlDelete() to delete them. That is totally unnecessary anyway since those controls are not available if the window is collapsed and the same applies to Show/Hide states.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Array.au3>
#include <ComboConstants.au3>
#include <StaticConstants.au3>



;GUI Look and Feel
$iWidth = 354;300
$iHeight = 176;200
$Toggle = True

$Frm_main = GUICreate("Main Window", $iWidth, $iHeight, 263, 217, BitOR($WS_SYSMENU,$WS_CAPTION,$WS_POPUP,$WS_POPUPWINDOW,$WS_BORDER,$WS_CLIPSIBLINGS))
GUISetState()

$Frm_1 = GUICreate("window 1", $iWidth, $iHeight*2, 0, 0, $WS_CHILD, -1, $Frm_main)
$txtUserID = GUICtrlCreateLabel("Username:", 8, 80, 43, 17)
$txtUserPassword = GUICtrlCreateLabel("Password:", 8, 112, 53, 17)
$userIDInput = GUICtrlCreateInput("", 64, 72, 281, 21, $WS_TABSTOP)
;GUICtrlSetColor(-1, 0x800000)
$userPasswordInput = GUICtrlCreateInput("", 64, 104, 281, 21, BitOR($WS_TABSTOP,$ES_PASSWORD,$ES_AUTOHSCROLL))
;GUICtrlSetColor(-1, 0x800000)
$buttonDriveMap = GUICtrlCreateButton("OK", 72, 144, 83, 25, $WS_GROUP)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$buttonCancel = GUICtrlCreateButton("Cancel", 157, 144, 91, 25, $WS_GROUP)
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$Btn_Expand = GUICtrlCreateButton("Advanced >>", 255, 144, 91,25, $WS_GROUP) ;91,25
GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
$lblTitle = GUICtrlCreateLabel("Main Title", 40, 8, 283, 24, $SS_CENTERIMAGE)
GUICtrlSetFont(-1, 12, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x800000)
$lblTitle2 = GUICtrlCreateLabel("Sub Title", 96, 32, 176, 20, BitOR($SS_CENTER,$SS_CENTERIMAGE))
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
GUICtrlSetColor(-1, 0x800000)
$lbldomain = GUICtrlCreateLabel("Domain:", 8, 185, 55, 17);109
$domainInput = GUICtrlCreateInput("ABC.COM", 64, 185, 210, 21);120
$lblDC = GUICtrlCreateLabel("Server:", 8, 217, 55, 17)
$DomainController = GUICtrlCreateCombo("Item1", 64, 217, 210, 21,$CBS_DROPDOWNLIST)
       GUICtrlSetData($DomainController, "Item2|Item3|Item3")
       ;GUICtrlSetState($DomainController, $GUI_HIDE)

GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $msg        = GUIGetMsg()

    Select

        Case $msg = $buttonCancel
            Exit

        Case $msg = $Btn_Expand
            _ToggleWindow()

        Case $msg = $buttonDriveMap
            $oMyError  = ObjEvent("AutoIt.Error", "_ADDoError"); Install a custom error handler
            $alt_userid = GUICtrlRead($userIDInput)
            $alt_password = GUICtrlRead ($userPasswordInput)
            $strHostServer = GUICtrlRead ($DomainController)
            ExitLoop

        Case $msg = $GUI_EVENT_CLOSE
            Exit
      ExitLoop

EndSelect

WEnd
Func _ToggleWindow()
    If $Toggle Then
        WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight *1.78)
        GUICtrlSetData($Btn_Expand, "Advanced<<")
        ControlMove ("","", $buttonDriveMap,72,250);215
        ControlMove ("","",$buttonCancel, 157,250);120
        ControlMove ("","",$Btn_Expand,255,250);252
        #cs
        $domainInput = GUICtrlCreateInput("ABC.COM", 64, 175, 210, 21);120
        $lbldomain = GUICtrlCreateLabel("Domain:", 8, 175, 55, 17);109
        $lblDC = GUICtrlCreateLabel("Server:", 8, 207, 55, 17)
        $DomainController = GUICtrlCreateCombo("Item1", 64, 207, 210, 21,$CBS_DROPDOWNLIST)
        #ce
       GUICtrlSetData(-1, "Item2|Item3|Item3")
    Else
       WinMove ( $Frm_main, "", Default, Default, $iWidth, $iHeight+30)
        GUICtrlSetData($Btn_Expand, "Advanced>>")
        ControlMove ("","", $buttonDriveMap,72,144)
        ControlMove ("","",$buttonCancel, 157,144)
        ControlMove ("","",$Btn_Expand,255,144)
    EndIf
    $Toggle = NOT $Toggle
EndFunc

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites
simon387

with a menu this doesnt work :\

edit: yes, was my bad, it works with a menu 2!

just had to built it on the 1th win

Edited by simon387

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  

×