Starting with GUI

Ask questions about creating Graphical User Interfaces (GUI) in PowerShell and using WinForms controls.
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 7 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Starting with GUI

Post by jvierra »

Dan's example form covers all bases. You just have to decide what you are wanting to do.
User avatar
ogeccut
Posts: 19
Last visit: Tue Dec 07, 2021 7:41 am

Re: Starting with GUI

Post by ogeccut »

Thanks.
Attachments
BLog.psf
(54.33 KiB) Downloaded 140 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Starting with GUI

Post by jvierra »

This is all you need in the script as well as the support functions.
  1. $form1_Load={
  2.     Load-ComboBox $WQ_Test_Group 'Thailand', 'Taiwan', 'Korea',  'China', 'Singapore', 'Vietnam', 'India'
  3. }
  4.  
  5. $Button_Stage_Click= {
  6.     #TODO: Place custom script here
  7.     Write-Host $WQ_Test_Group $WQ_Test_Group.selecteditem
  8.     Write-Host $User_Name $User_Name_Text
  9.     Write-Host $Host_Name $Host_Name_Text
  10.     Remove-ADGroupMember $WQ_Test_Group.selecteditem $User_Name.Text -Confirm:$false -Whatif
  11.     Remove-ADGroupMember $WQ_Test_Group.selecteditem $User_Name.Text -Confirm:$false -WhatIf
  12. }
Please read the link I gave you. You MUST understand how forms work. You cannot guess at the answers.
User avatar
ogeccut
Posts: 19
Last visit: Tue Dec 07, 2021 7:41 am

Re: Starting with GUI

Post by ogeccut »

Thank you. This is working.
It seems i was over complicating things...
Trying to understand where are those variables are created?

I think i got it from here....

Thank you,
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Starting with GUI

Post by jvierra »

ogeccut wrote:Thank you. This is working.
It seems i was over complicating things...
Trying to understand where are those variables are created?

I think i got it from here....

Thank you,
What variables. There are no variables being created. These are all properties of the controls. Read the blog articles. You will learn a lot about PowerShell, Forms and computers.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Starting with GUI

Post by dan.potter »

Personally, I don't use the load-combobox function for a static list. Just add them in the designer. Don't use variables when you don't need them. Setting a variable just to carry it over to another event reminds me of that guy in office space that takes the forms from the customer to the engineers :D Every event equals do something.. If you don't need to take action on the index change than don't obfuscate the code.

I use the index changed event where I wouldn't expect the user to click a button such as loading a datagrid, graph etc.
User avatar
ogeccut
Posts: 19
Last visit: Tue Dec 07, 2021 7:41 am

Re: Starting with GUI

Post by ogeccut »

Thanks for the help. I was not aware you can add them in the designer, will read more about it.
And i was not aware i can use $User_Name_Text i am guessing a property of a test box in the Button click.
Will do some reading about it today, if there are more link please share.

Thank you.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Starting with GUI

Post by dan.potter »

You don't have to guess. When you write $controlname followed by a period studio will give you all the methods and properties available to the control. After a dozen forms or so you'll have them all memorized. :)
This topic is 7 years and 8 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked