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.
This topic is 5 years and 8 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
clum09
Posts: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Close splash form and password dot character

Post by clum09 »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Close splash form and password dot character

Post by jvierra »

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: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: Close splash form and password dot character

Post by clum09 »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Close splash form and password dot character

Post by jvierra »

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.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Close splash form and password dot character

Post by jvierra »

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
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Close splash form and password dot character

Post by davidc »

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: 150
Last visit: Sun Jan 21, 2024 5:07 pm

Re: Close splash form and password dot character

Post by clum09 »

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
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Close splash form and password dot character

Post by davidc »

Thank you for the update.
David
SAPIEN Technologies, Inc.
This topic is 5 years and 8 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