how to show main form if the form_load is not complted

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 5 years and 11 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
ocsscott6969
Posts: 48
Last visit: Tue Dec 05, 2023 10:04 am

how to show main form if the form_load is not complted

Post by ocsscott6969 »

Ok sounds strange but I am passing a command line to my gui utility to continue processing if a reboot happens during use.

so I have code like below in the form load
$p1 is the command line

if ($p1.Length -gt 6)
{
$global:p1CfgFile = Split-Path -leaf $P1
$Script:outputFile = $p1CfgFile
add-Content -Path "c:\softdist\appinstaller2\$outputfile-$Date.log" -Value "Continuing Installs via Run Key of CFG File --> $P1CfgFile " -Force
$Status = "Continuing"
#$form_main.Show this didn't help
$buttonStartsInstalls.Enabled = $true
$buttonStartsInstalls.PerformClick()
}

so I want to show my form but run the code from that click event. how can I force the form to show I thought fom.show would do the trick

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

Re: how to show main form if the form_load is not complted

Post by jvierra »

$form.Show() cannot be used in PowerShell. You can only use "ShowDialog()"

What you are trying to do cannot be done. You cannot split a command over many lines like you are doing.

If you are trying to restart a form after a reboot then it is more sensible to set a flag in the registry and check it each time the form is opened.
User avatar
ocsscott6969
Posts: 48
Last visit: Tue Dec 05, 2023 10:04 am

Re: how to show main form if the form_load is not complted

Post by ocsscott6969 »

I am not sure what you mean when you say I cant split a command over many lines can you be specific which lines do you mean?

and for the other part I can use showdialog to show my main form inside the form load event?

its so hard to explain these things in email vs talking not sure I am explaining what I am trying to do correctly.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: how to show main form if the form_load is not complted

Post by jvierra »

In PowerShell with PS Studio all forms are displayed using ShowDialog. This is coded for you automatically. If the main form starts a child form the main form cannot be made current until the child is closed.

I cannot understand what you are trying to do or what your issue is. If the system reboots there will be no forms. The form will have to be restarted. Adding code cannot protect you from a reboot.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: how to show main form if the form_load is not complted

Post by jvierra »

The following command is on multiple lines and will have an extra line break added to the file.

add-Content -Path "c:\softdist\appinstaller2\$outputfile-$Date.log" -Value "Continuing Installs via Run Key of CFG File --> $P1CfgFile " -Force

To avoid this we can:


$msg = "Continuing Installs via Run Key of CFG File --> $P1CfgFile "
$msg | Add-Content c:\softdist\appinstaller2\$outputfile-$Date.log"


As I noted above, a form cannot be continued. A workflow can be continued if it is designed correctly.
User avatar
ocsscott6969
Posts: 48
Last visit: Tue Dec 05, 2023 10:04 am

Re: how to show main form if the form_load is not complted

Post by ocsscott6969 »

That long line is just how it copy/pasted it is one line in the code editor.

The showdialog worked like a charm

thanks
This topic is 5 years and 11 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