Tabbed form help

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 6 years and 1 month 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
User avatar
ctrlaltdel
Posts: 12
Last visit: Mon Mar 18, 2024 4:23 pm

Tabbed form help

Post by ctrlaltdel »

I have created a Tab Control Form however I can not figure out how to make it display my poweshell code.
  1. $computerSystem = Get-CimInstance CIM_ComputerSystem
  2. $computerBIOS = Get-CimInstance WIN32_BIOS
  3. $computerOS = Get-CimInstance CIM_OperatingSystem
  4. $computerCPU = Get-CimInstance CIM_Processor
  5. $computerHDD = Get-CimInstance Win32_LogicalDisk -Filter "DeviceID = 'C:'"
  6. $computerWSAT = Get-CimInstance Win32_WinSat
  7. $computerReliability = Get-CimInstance Win32_ReliabilityStabilityMetrics | Select-Object -First 1
  8. $PhysicalRAM = (Get-WMIObject -class Win32_PhysicalMemory -ComputerName localhost | Measure-Object -Property capacity -Sum | % { [Math]::Round(($_.sum / 1GB), 2) })
  9. $ComputerIP = (` Get-NetIPConfiguration | ` Where-Object { ` $_.IPv4DefaultGateway -ne $null ` -and ` $_.NetAdapter.Status -ne "Disconnected" }).IPv4Address.IPAddress
What I have tried to do in the designer is put a Label boxes and then do
  1. $label1.Text = "HI! I'm $($computerSystem.name)"
  2. $label2.Text = "$($computerSystem.manufacturer)"
  3. $label3.Text = "$($computerSystem.model)"
  4. $label4.Text = "$($computerBIOS.serialnumber)"
  5. $label5.Text = "$($computerCPU.name)"
  6. $label6.Text = "$($PhysicalRAM) GB"
  7. $label7.Text = "$($ComputerIP)"
But when I save and run all I see on the form is "Label" it doesn't display the information I am trying to pipe to it.


Here is the entirety of my code so far. Please note that the LinkLabel works as intended OK. Just not sure how / where to insert this other code so the tab will display it.
  1. $formHelpDesk_Load={
  2.     UpdateNavButtons
  3. }
  4.  
  5. function UpdateNavButtons
  6. {
  7.     $buttonNext.Enabled = $tabcontrol1.SelectedIndex -lt $tabcontrol1.TabCount - 1 
  8.     $buttonPrev.Enabled = $tabcontrol1.SelectedIndex -gt 0
  9. }
  10.  
  11. $buttonPrev_Click={
  12.     if($tabcontrol1.SelectedIndex -gt 0)
  13.     {
  14.         $tabcontrol1.SelectedIndex--
  15.     }
  16.     UpdateNavButtons
  17. }
  18.  
  19. $buttonNext_Click={
  20.     if($tabcontrol1.SelectedIndex -lt $tabcontrol1.TabCount - 1)
  21.     {
  22.         $tabcontrol1.SelectedIndex++
  23.     }
  24.     UpdateNavButtons
  25. }
  26.  
  27. $picturebox1_Click={
  28.     #TODO: Place custom script here
  29.    
  30. }
  31.  
  32. $tabpage1_Click={
  33.     #TODO: Place custom script here
  34.    
  35. }
  36.  
  37.  
  38. $linklabelClickHereToOpenASupp_LinkClicked=[System.Windows.Forms.LinkLabelLinkClickedEventHandler]{
  39.     #Event Argument: $_ = [System.Windows.Forms.LinkLabelLinkClickedEventArgs]
  40.     #TODO: Place custom script here
  41.    
  42.     $outlook = New-Object -comObject Outlook.Application
  43.    
  44.     #Create the new email
  45.     $mail = $outlook.CreateItem(0)
  46.    
  47.     $mail.To = "myemail@mydomain.com"
  48.    
  49.     #Optional, set the subject
  50.     $mail.Subject = "$env:USERNAME on $env:COMPUTERNAME is requesting help"
  51.    
  52.     #Optional, set the body
  53.     $mail.Body = "##########PLEASE TYPE YOUR SUPPORT MESSAGE BELOW##########
  54.  
  55. ##########DO NOT MODIFY BELOW THIS LINE##########"
  56.    
  57.    
  58.    
  59.     #Get the new email object
  60.     $inspector = $mail.GetInspector
  61.    
  62.     #Bring the message window to the front
  63.     $inspector.Activate()
  64. }
  65.  
  66.  
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tabbed form help

Post by jvierra »

When posting large amounts of code please post the code as a file attachment. Copying the code from tis code box (which beaks the code's text) is difficult and we don't have your forms settings.

Just attach the PSF file.

Also note that all changes to controls must be done inside of an event and the variables must by "in scope".
User avatar
ctrlaltdel
Posts: 12
Last visit: Mon Mar 18, 2024 4:23 pm

Re: Tabbed form help

Post by ctrlaltdel »

Sorry about that, noted for the future as I can't edit the original and I didn't want to start a new thread.

OK PSF attached as well as tab1 and tab2 which is the code I want to insert. This is really easy to do when just creating a multi form project, I can not figure out how to create an event for a tabbed project.
Attachments
tab2.txt
(1.05 KiB) Downloaded 98 times
tab1.txt
(382 Bytes) Downloaded 100 times
AAMHELPTFS.psf
(18.8 KiB) Downloaded 103 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tabbed form help

Post by jvierra »

I cannot understand what you mean by inserting code. The code snippets cannot just be inserted. They have to go in an event somewhere. What event causes this code to be executed? You refer to two buttons named "$buttonPrev_Click" Those buttons do not exist in your form. Your code refers to "$label1" which does not exist.
User avatar
ctrlaltdel
Posts: 12
Last visit: Mon Mar 18, 2024 4:23 pm

Re: Tabbed form help

Post by ctrlaltdel »

"They have to go in an event somewhere"

Right that is what I am trying to get help with. How do I create an event for a tab?

How do I create an event for a tab section and input code into it? In this case, I want it to gather information about the computer from WMI and display it in labels.

the buttons code is there because when you create the form by default it puts buttons which I removed from the graphical.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tabbed form help

Post by jvierra »

Just select the tab page and add the event just like any other control. Click in the center of the page to elect and not on the tab.
User avatar
ctrlaltdel
Posts: 12
Last visit: Mon Mar 18, 2024 4:23 pm

Re: Tabbed form help

Post by ctrlaltdel »

Clicked in the center of the tab and it created a block. On the script page I put my code. Then On the design page I put a label1 tool

All it displays is "Label1" and not the code I am trying to get it to display
Attachments
TF.psf
(53.39 KiB) Downloaded 123 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Tabbed form help

Post by jvierra »

I didn't say double click. Just click in the middle of the tab page you want to add an event to and use the properties pages (events tab) to add any event that you want.

What I can tell is that you have not learned how to use the designer. Open the manual from the help bar (left side) and read the parts o n the designer bits and how to use it.
This topic is 6 years and 1 month 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