multiple form project

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 6 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
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

multiple form project

Post by mqh77777 »

Product, version and build: 5.2.128
32 or 64 bit version of product: 64
Operating system: Windows 7 32 and 64 bit
32 or 64 bit OS: 32 and 64 bit
PowerShell Version: 4

I have a single form project that uses the $statusbar1.text. When we run the .EXE we can see a message at the bottom of the screen. But when I created a multiple form project I've noticed that this command no longer works. I've tried $statusbar1.text and $statusbar.text and neither works. How do you make this work on both the parent and child forms?
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: multiple form project

Post by DevinL »

[TOPIC MOVED TO POWERSHELL GUIS FORUM BY MODERATOR]
DevinL
SAPIEN Technologies, Inc.
DevinL
Posts: 1098
Last visit: Tue Jun 06, 2017 9:15 am

Re: multiple form project

Post by DevinL »

I moved both of your threads over as they were more overall PowerShell GUI questions as opposed to specific issues with PowerShell Studio.

One thing that would be of great help is if you could provide the code that you currently have for your multiple forms so we have a better understanding of what's going on.

You can use the code selection box at the top of where you type out a reply to format your code in a more readable format as well:
Code_Selection_Box.png
Code_Selection_Box.png (5.48 KiB) Viewed 3848 times
DevinL
SAPIEN Technologies, Inc.
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: multiple form project

Post by mqh77777 »

Hi, I have two forms and over 600 lines of code. So I created a new multiple form project with one task to show what I mean. the $statusbar1.text is never seen.

# main form

$MainForm_Load={
#TODO: Initialize Form Controls here

}

$buttonCallChildForm_Click={
#TODO: Place custom script here
if((Call-ChildForm_psf) -eq 'OK')
{

}
}

#########################################################

Child Form


$formChildForm_Load={
#TODO: Initialize Form Controls here

}


$button1_Click={
#TODO: Place custom script here
$pc = Read-Host "Enter remote computer name"
$statusbar1.text = 'The query of of a remote machines WMI can take time, please wait.'
get-wmiobject -class Win32_QuickFixEngineering -ComputerName $pc | Out-GridView -wait -Title "MGH"
$statusbar1.text = 'All done!'
}

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

Re: multiple form project

Post by dan.potter »

consider your scope when you passing data from the child to the main form.

mainform:

Call-ChildForm_psf

$statusbar1.text = $sbtext


Child form.

The ok button dialogresult property on your child should be set to ok.

$button1_Click={

$script:sbtext = 'updating the statusbar'

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

Re: multiple form project

Post by dan.potter »

  1. ##main
  2.  
  3. $MainForm_Load={
  4. #TODO: Initialize Form Controls here
  5.  
  6. }
  7.  
  8. $buttonCallChildForm_Click={
  9.     #TODO: Place custom script here
  10.     if((Call-ChildForm_psf) -eq 'OK')
  11.     {
  12.         $statusbar1.Text = $sbtext
  13.     }
  14. }
  15.  
  16.  
  17.  
  18. ##child
  19.  
  20. $formChildForm_Load={
  21.     #TODO: Initialize Form Controls here
  22.    
  23. }
  24.  
  25.  
  26. $buttonOK_Click={
  27.     $script:sbtext = 'updating the statusbar'
  28. }
User avatar
mqh77777
Posts: 252
Last visit: Mon Feb 26, 2024 10:07 am
Has voted: 1 time

Re: multiple form project

Post by mqh77777 »

If I understood you right I did the following.

$buttonCallChildForm_Click={
#TODO: Place custom script here
$statusbar1.text = $sbtext
if((Call-ChildForm_psf) -eq 'OK') {}
}

then on the child item

$button1_Click={
#TODO: Place custom script here
$computer = read-host "Enter computer name"
Get-WmiObject win32_computersystem -comp $computer | Select-Object USername, Caption, Model | Out-GridView -Title "Logged on user"
$script:sbtext = 'updating the statusbar'
}

I never saw a status bar. And my main objective is to have 1 parent form and at least 2 child forms. All 3 forums will have 6-10 buttons. Each button will use the Statusbar command.

Main Form - Called Computer Tasks. This form will have 11 buttons, each one doing a different task against computers.
Child form 1 - Called User Tasks. This form will have 6 buttons on it each one doing a different task against users.
Chile form 2 - Called Server Tasks. This form will have several buttons on it each one doing a different task against File Server machines.

I have all of this working right now but its on 1 Form. That 1 form is now far far too crowded and takes up the whole screen when run, and our desktop support team does not like it, so I am trying to create a multiple form utility that is cleaner.

so all of my posts in this form today in the long run are about the same thing.

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: multiple form project

Post by jvierra »

You cannot update the status bar on another form. You will need to specify the parent form"

$parent.Controls['statusbar1'].Text = 'your message'

It you are trying to update the current forms statusbar then you may need to use "DoEvents"
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: multiple form project

Post by dan.potter »

The get-wmiobject command goes in your mainform under the call-childform. Think of it like this, when you call the child form your main script is paused until the childform is closed. It picks right up on the next line of the mainform after the child form button is clicked.

All forms are functions and compiled into one big script.
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: multiple form project

Post by dan.potter »

This topic is 7 years and 6 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