Close splash form and password dot character

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.
Locked
User avatar
clum09
Posts: 149
Joined: Thu Apr 24, 2008 9:11 am

Close splash form and password dot character

Post by clum09 » Thu Jul 05, 2018 2:40 pm

Hello,

I have a form application that I developed with PowerShell Studio 2016 v5.2.118 back in 2016.

The application has a child form that was used as a splash screen during application load. Everything worked fine at that time.

Now I want to convert the form application to use the new PowerShell Studio 5.5.153 with hope to use the new features to make the form display the form controls correctly with the high dpi resolution. The converted form loads the splash screen, but it fails to close this splash form.

What I used in the old form was I added the splash form code to the main form, and I added the code below to open the child form.

$mainForm_Load={
#TODO: Initialize Form Controls here
Call-Splash_Form_psf | Out-Null;
}

Within my splash form, I had the following code the close the splash form after 2 seconds.

$FormEvent_Load={
#TODO: Initialize Form Controls here
}

# Script block to wait 2 seconds and close the Splash form.
$Close_Form = {
sleep 2
& $Form_Cleanup_FormClosed;
$form1.Close();
}

Like I said, during that time the splash form closed correctly after 2 seconds, but with new converted code by the new PowerShell Studio, the splash form no longer closes.

Another problem I run into with the new converted code is I have the password character that is just a dot symbols like ● to represent the type password during typing the password. When I have this code by the main form only, it works fine, but when I have the splash form running before the main form, the following error occurs and the password character fails to display during typing.

ERROR: Exception setting "PasswordChar": "Cannot convert value "●" to type "System.Char". Error: "String must be exactly one character long.""

but this behavior does not happen with the old code, and the password character ● still displays correctly.

I would like to know how I can correct the code so that splash form can close as it used to do, and how I can have the password character ● display correctly with the code from the new version of PowerShell Studio.

Thank you in advance.

User avatar
jvierra
Posts: 13687
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Close splash form and password dot character

Post by jvierra » Thu Jul 05, 2018 3:01 pm

There is nothing about the code posted that would cause your issues.

What is this: "& $Form_Cleanup_FormClosed;"
"FormClosed" is called automatically after the form has been closed. You are calling it before the form closes. This will likely cause issues.

User avatar
clum09
Posts: 149
Joined: Thu Apr 24, 2008 9:11 am

Re: Close splash form and password dot character

Post by clum09 » Thu Jul 05, 2018 3:40 pm

Hi jvierra,

Thank you for the response.

You miss-understand my description. There is a region called Generated Events below the User Generated Script region within the splash form that the $Close_Form event calls to clean up the form code before the $form1.Close() code closes the form, but the splash form will never close regardless of $form1.Close() is called. The & in front of the $Form_Cleanup_FormClosed event causes the event to execute. The code sleep 2 tells the code to wait 2 seconds before next line executes. See below.

#----------------------------------------------
# User Generated Script
#----------------------------------------------

# To load this Splash form, add the line below to the $mainForm_Load
# script block to the # User Genrerated Script section of the main form.
# Leave the $FormEvent_Load script block below as it is in this section.
# $mainForm_Load = {
#TODO: Initialize Form Controls here
# Call-Splash_Form_psf | Out-Null;
# }

$FormEvent_Load = {
#TODO: Initialize Form Controls here
}

# Script block to wait 2 seconds and close the Splash form.
$Close_Form = {
sleep 2;
& $Form_Cleanup_FormClosed;
$form1.Close();
}

# --End User Generated Script--
#----------------------------------------------
#region Generated Events
#----------------------------------------------

$Form_StateCorrection_Load =
{
#Correct the initial state of the form to prevent the .Net maximized form issue
$form1.WindowState = $InitialFormWindowState
& $Close_Form;
}

$Form_Cleanup_FormClosed =
{
#Remove all event handlers from the controls
try
{
$form1.remove_Load($FormEvent_Load)
$form1.remove_Load($Form_StateCorrection_Load)
$form1.remove_FormClosed($Form_Cleanup_FormClosed)
}
catch [Exception]
{ }
}
#endregion Generated Events

My problem is the splash form never closes. The bottom line is how to tell the splash form to close after 2 seconds after the script has eceuted.

User avatar
jvierra
Posts: 13687
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Close splash form and password dot character

Post by jvierra » Thu Jul 05, 2018 3:49 pm

I am aware of that. That event is called automatically as it is an event. The "Close" event is called as an event when the form is being closed. It appears that you will be executing it twice.

Also changing the version of Net that you are using will change the timing in some cases which may discover subtle design issues that were not seen under a different version of Net.

User avatar
jvierra
Posts: 13687
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Close splash form and password dot character

Post by jvierra » Thu Jul 05, 2018 5:09 pm

Here is the form closed event code. Notice that it removes itself from the events.

Code: Select all

$Form_Cleanup_FormClosed=
	{
		#Remove all event handlers from the controls
		try
		{
			$buttonStopToaster.remove_Click($buttonStopToaster_Click)
			$buttonSendMessage.remove_Click($buttonSendMessage_Click)
			$buttonStartNotifier.remove_Click($buttonStartNotifier_Click)
			$formTestToasterNotificat.remove_Load($formTestToasterNotificat_Load)
			$formTestToasterNotificat.remove_MouseDown($formTestToasterNotificat_MouseDown)
			$formTestToasterNotificat.remove_Load($Form_StateCorrection_Load)
			$formTestToasterNotificat.remove_FormClosed($Form_Cleanup_FormClosed)
		}
		catch { Out-Null <# Prevent PSScriptAnalyzer warning #> }
	}

It also removes all events from the form. This may cause issues when the code is called after the event is removed. The event is designed to be the last event called AFTER the form "Close" event and no during the "Close" event.

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Close splash form and password dot character

Post by davidc » Fri Jul 06, 2018 7:07 am

As for the PasswordChar, please zip and upload the original psf file and we can take a look at it:

https://www.sapien.com/support/upload
David
SAPIEN Technologies, Inc.

User avatar
clum09
Posts: 149
Joined: Thu Apr 24, 2008 9:11 am

Re: Close splash form and password dot character

Post by clum09 » Tue Jul 10, 2018 8:25 am

Hi Davidc,

I just found out that the textbox of Windows Form has a property known as UseSystemPasswordChar. Once I set this property to $True, the issue with the password character went away.

For the splash form closing issue, I just moved to the form closing routine to the $Form_StateCorrection_Load script block, and it works fine now.

Thank you all for the help.

User avatar
davidc
Posts: 5913
Joined: Thu Aug 18, 2011 4:56 am

Re: Close splash form and password dot character

Post by davidc » Tue Jul 10, 2018 8:57 am

Thank you for the update.
David
SAPIEN Technologies, Inc.

Locked