Progressbar visible set to false when sub form is loaded

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 8 years and 5 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
Hanzoy
Posts: 32
Last visit: Fri Feb 03, 2023 2:30 am

Progressbar visible set to false when sub form is loaded

Post by Hanzoy »

Hi,

I have created a project and would like to, when I press a button in the main form, it opens a sub form and when the sub form is loaded, the progressbar in the main form is set to false.
I have created this:
PowerShell Code
Double-click the code block to select all.
if (Call-NewCompanyOU_psf –eq "OK")
{
	$toolstripprogressbar1.Visible = $false
}
But that will only set it to false, when I close the sub form.
Anyone who knows how I can accomplish this? :)
User avatar
SAPIEN Support Forums
Posts: 945
Last visit: Thu Oct 22, 2015 1:10 pm

Progressbar visible set to false when sub form is loaded

Post by SAPIEN Support Forums »

This is an automated post. A real person will respond soon.

Thank you for posting, Hanzoy.

Here are some hints to help you get an accurate and complete answer to your question.

Ask in the best forum: If you asked in the wrong forum, just copy your question to the right forum.

Anticipate follow-up questions!

Did you remember to include the following?
  • 1. Product, version and build
    2. 32 or 64 bit product
    3. Operating system, e.g. Windows 7 64 bit.
    4. Attach a screenshot, if applicable
    5. Attach logs, crash reports, etc., in a ZIP file
If not, please take a moment to edit your original post or reply to this one.

*** Make sure you do not post any licensing information ***
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Progressbar visible set to false when sub form is loaded

Post by jvierra »

It is not really possible to understand what you are trying to ask.
User avatar
Hanzoy
Posts: 32
Last visit: Fri Feb 03, 2023 2:30 am

Re: Progressbar visible set to false when sub form is loaded

Post by Hanzoy »

jvierra wrote:It is not really possible to understand what you are trying to ask.
Sorry about that, I will try to make myself more clear :)

I have to forms.
A main form where I have a button. When I press that button, it makes the progressbar visible in the main form and opens a sub form.
What I would like is to set the progressbar.visible, in the main form, to false as soon as the sub form is loaded.
But with the following code, it is set to false when I close the sub form, and not when is it finished loading.

Here is the code for the button in the main form.
PowerShell Code
Double-click the code block to select all.
$button_NewCompanyOU_Click = {
	#TODO: Place custom script here
	
    $toolstripprogressbar1.Visible = $true
	$toolstripprogressbar1.Value = 1
	$toolstripprogressbar1.Maximum = 2

    if (Call-NewCompanyOU_psf –eq "OK")
    {
        $toolstripprogressbar1.PerformStep()
        $toolstripprogressbar1.Visible = $false
    }
}
Hope i make more sense now :)
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Progressbar visible set to false when sub form is loaded

Post by jvierra »

Forms are modal in PowerShell. You cannot execute code in the calling form until the called form is closed.

You can try to send the control as an argument and set it in the child.
User avatar
Hanzoy
Posts: 32
Last visit: Fri Feb 03, 2023 2:30 am

Re: Progressbar visible set to false when sub form is loaded

Post by Hanzoy »

jvierra wrote:Forms are modal in PowerShell. You cannot execute code in the calling form until the called form is closed.

You can try to send the control as an argument and set it in the child.
Ahh of course :)
Tried this, to test it and it works.
Button from main form:
PowerShell Code
Double-click the code block to select all.
$button_NewCompanyOU_Click = {
	#TODO: Place custom script here
	
    $toolstripprogressbar1.Visible = $true
	$toolstripprogressbar1.Value = 1
	$toolstripprogressbar1.Maximum = 2

    $script:Progressbarfalse = ($toolstripprogressbar1.Visible = $false)

    Call-NewCompanyOU_psf
}
form load in the child form:
PowerShell Code
Double-click the code block to select all.
$form_NewCompanyOU_Load={
	#TODO: Initialize Form Controls here

    $Progressbarfalse
}
User avatar
Hanzoy
Posts: 32
Last visit: Fri Feb 03, 2023 2:30 am

Re: Progressbar visible set to false when sub form is loaded

Post by Hanzoy »

Hanzoy wrote:
jvierra wrote:Forms are modal in PowerShell. You cannot execute code in the calling form until the called form is closed.

You can try to send the control as an argument and set it in the child.
Ahh of course :)
Tried this, to test it and it works.
Button from main form:
PowerShell Code
Double-click the code block to select all.
$button_NewCompanyOU_Click = {
	#TODO: Place custom script here
	
    $toolstripprogressbar1.Visible = $true
	$toolstripprogressbar1.Value = 1
	$toolstripprogressbar1.Maximum = 2

    $script:Progressbarfalse = ($toolstripprogressbar1.Visible = $false)

    Call-NewCompanyOU_psf
}
form load in the child form:
PowerShell Code
Double-click the code block to select all.
$form_NewCompanyOU_Load={
	#TODO: Initialize Form Controls here

    $Progressbarfalse
}
Was a bit to fast, it will actually set it to false before it calls the sub form and not save it as a variable.
Will take a look at the argument stuff and see if I can get it to work :)
User avatar
Hanzoy
Posts: 32
Last visit: Fri Feb 03, 2023 2:30 am

Re: Progressbar visible set to false when sub form is loaded

Post by Hanzoy »

Tried this, but still doesn't work.

In Main form:
PowerShell Code
Double-click the code block to select all.
$button_ActiveDirectory_Click = {
	Call-ActiveDirectory_psf -Progressbar ($toolstripprogressbar1.Visible = $false)
}
In Child form:
PowerShell Code
Double-click the code block to select all.
param (
    [string]$Progressbar = $10_ProgressbarVisibleFalse
)
 
$form_ActiveDirectory_Load={
    #TODO: Initialize Form Controls here
     
    # Sets the progressbar.visible in main form to false
    $10_ProgressbarVisibleFalse
}
It's still executing the command as soon as you press the button, not when the Child form has finished loading.
Anyone who knows how to solve this?
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar visible set to false when sub form is loaded

Post by dan.potter »

Hanzoy wrote:Tried this, but still doesn't work.

In Main form:
PowerShell Code
Double-click the code block to select all.
$button_ActiveDirectory_Click = {
	Call-ActiveDirectory_psf -Progressbar ($toolstripprogressbar1.Visible = $false)
}
In Child form:
PowerShell Code
Double-click the code block to select all.
param (
    [string]$Progressbar = $10_ProgressbarVisibleFalse
)
 
$form_ActiveDirectory_Load={
    #TODO: Initialize Form Controls here
     
    # Sets the progressbar.visible in main form to false
    $10_ProgressbarVisibleFalse
}
It's still executing the command as soon as you press the button, not when the Child form has finished loading.
Anyone who knows how to solve this?

I don't know if this is just because my test forms don't take that long to load but I can't see a delay if I do this.
PowerShell Code
Double-click the code block to select all.
$MainForm_Load={
#TODO: Initialize Form Controls here
	
	$script:pb = $progressbar1
	
}



$button1_Click = {
	
	Call-sub_psf
	
}
subform
PowerShell Code
Double-click the code block to select all.
$form1_Load={
	
	$pb.visible = $false
	
}
User avatar
dan.potter
Posts: 709
Last visit: Wed Nov 14, 2018 11:39 am

Re: Progressbar visible set to false when sub form is loaded

Post by dan.potter »

Just for kicks I put a progress bar on both forms(the sub set to invisible.
PowerShell Code
Double-click the code block to select all.
$MainForm_Load={
#TODO: Initialize Form Controls here
	
	$script:pb = $progressbar1
	
}


$button1_Click = {
	
	Call-sub_psf
	
}

PowerShell Code
Double-click the code block to select all.
$form1_Load={
	
	
	
}


$textbox1_Enter = {
	
	$pb.visible = $false
	$progressbar1.Visible = $true
}
This topic is 8 years and 5 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