Show-SplashScreen Problem, No Image

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
User avatar
mbrinkhoff
Posts: 11
Meble kuchenne na zamówienie - na wymiar - Wrocław
Joined: Thu Nov 09, 2017 6:32 am

Show-SplashScreen Problem, No Image

Post by mbrinkhoff »

Product: PowerShell Studio 2020 (64 Bit)
Build: v5.7.172
OS: Windows 10 Enterprise (64 Bit)
Build: v10.0.17763.0

I am trying to use the Show-SplashScreen cmdlet for the first time (as described here https://www.sapien.com/blog/2019/04/16/ ... ns-batman/) and I am having an issue with the screen only showing a white box instead of the PNG image. It looks like it's finding the image file because the box that is displayed is the size of the image. I do get the text that I have set at the top of the box.

This is the code I am using. The image file is in the same folder as the project and when I compiled it to an exe I copied it to that folder also.

Code: Select all

$imagePath = Join-Path -Path (Get-ScriptDirectory) -ChildPath 'SplashImage.png'
$splashForm = Show-SplashScreen -ImageLocation $imagePath -Title "ServerTool $global:version" -PassThru
Another person seems to have had this issue last year but I couldn't find a post by them.
Doug Neely says:
April 17, 2019 at 7:51 pm
I have been trying this out, but am having issues with it actually loading the image. I have tried different sizes, png and jpg, and I see it definitely getting the dimensions of the image, but don’t actually see it. Sometimes, it will load later in the process (when I am updating the title), other times, it won’t. Any ideas on this?

User avatar
brittneyr
Site Admin
Posts: 361
Joined: Thu Jun 01, 2017 7:20 am

Re: Show-SplashScreen Problem, No Image

Post by brittneyr »

I'm having problems reproducing this. Can you please answer the following questions:
-Does the splash screen work before you compile it into an exe?
-Can you get it to work with any other image?
-Did you use the 'Empty Form with Splash Screen' template?
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
mbrinkhoff
Posts: 11
Joined: Thu Nov 09, 2017 6:32 am

Re: Show-SplashScreen Problem, No Image

Post by mbrinkhoff »

It works about 1 out of 20 times running it from the "run" button in the IDE toolbar.

I have tried 2 other PNG images and it behaves the same. I do think it is getting the image file successfully because the size of the white box changes when I change the png file.

I did not use the 'Empty Form with Spash Screen' template. I am using the Show-SplashScreen snippet as was detailed in the "Holy Splash Screens Batman!" article I linked to.

As an aside if I use the -Modal parameter it works every time but that does not allow me to close the splash screen when the form is done loading.

User avatar
brittneyr
Site Admin
Posts: 361
Joined: Thu Jun 01, 2017 7:20 am

Re: Show-SplashScreen Problem, No Image

Post by brittneyr »

Can you please upload your form and image here:
https://www.sapien.com/support/upload
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
brittneyr
Site Admin
Posts: 361
Joined: Thu Jun 01, 2017 7:20 am

Re: Show-SplashScreen Problem, No Image

Post by brittneyr »

From looking at what you uploaded, I do not see the code snippets for 'Show-SplashScreen' or 'Get-ScriptDirectory'. Does your script have any errors when you attempt to run it? Is this script apart of a project?

I also have no issue when I use your image in my test scripts. The following is an example of part of a script using a splash screen:
  1. $form1_Load={
  2.  
  3.     #TODO: Initialize Form Controls here
  4.  
  5.     $imagePath = Join-Path -Path (Get-ScriptDirectory) -ChildPath 'SplashImage.png'
  6.  
  7.     $form = Show-SplashScreen -ImageLocation $imagePath -Title "Test" -Timeout 10
  8.  
  9. }
  10.  
  11. function Get-ScriptDirectory
  12.  
  13. {
  14.  
  15. <#
  16.  
  17.     .SYNOPSIS
  18.  
  19.         Get-ScriptDirectory returns the proper location of the script.
  20.  
  21.     .OUTPUTS
  22.  
  23.         System.String
  24.  
  25.     .NOTES
  26.  
  27.         Returns the correct path within a packaged executable.
  28.  
  29. #>
  30.  
  31.     [OutputType([string])]
  32.  
  33.     param ()
  34.  
  35.     if ($null -ne $hostinvocation)
  36.  
  37.     {
  38.  
  39.         Split-Path $hostinvocation.MyCommand.path
  40.  
  41.     }
  42.  
  43.     else
  44.  
  45.     {
  46.  
  47.         Split-Path $script:MyInvocation.MyCommand.Path
  48.  
  49.     }
  50.  
  51. }
  52.  
  53.  
  54.  
  55. function Show-SplashScreen
  56.  
  57. {
  58.  
  59.     <#
  60.  
  61.     .SYNOPSIS
  62.  
  63.         Displays a splash screen using the specified image.
  64.  
  65.     .PARAMETER Image
  66.  
  67.         Mandatory Image object that is displayed in the splash screen.
  68.  
  69.     .PARAMETER Title
  70.  
  71.         (Optional) Sets a title for the splash screen window.
  72.  
  73.     .PARAMETER Timeout
  74.  
  75.         The amount of seconds before the splash screen is closed.
  76.  
  77.         Set to 0 to leave the splash screen open indefinitely.
  78.  
  79.         Default: 2
  80.  
  81.     .PARAMETER ImageLocation
  82.  
  83.         The file path or url to the image.
  84.  
  85.     .PARAMETER PassThru
  86.  
  87.         Returns the splash screen form control. Use to manually close the form.
  88.  
  89.     .PARAMETER Modal
  90.  
  91.         The splash screen will hold up the pipeline until it closes.
  92.  
  93.     .EXAMPLE
  94.  
  95.         PS C:\> Show-SplashScreen -Image $Image -Title 'Loading...' -Timeout 3
  96.  
  97.     .EXAMPLE
  98.  
  99.         PS C:\> Show-SplashScreen -ImageLocation 'C:\Image\MyImage.png' -Title 'Loading...' -Timeout 3
  100.  
  101.     .EXAMPLE
  102.  
  103.         PS C:\> $splashScreen = Show-SplashScreen -Image $Image -Title 'Loading...' -PassThru
  104.  
  105.                 #close the splash screen
  106.  
  107.                 $splashScreen.Close()
  108.  
  109.     .OUTPUTS
  110.  
  111.         System.Windows.Forms.Form
  112.  
  113.     .NOTES
  114.  
  115.         Created by SAPIEN Technologies, Inc.
  116.  
  117.         The size of the splash screen is dependent on the image.
  118.  
  119.         The required assemblies to use this function outside of a WinForms script:
  120.  
  121.         Add-Type -AssemblyName System.Windows.Forms
  122.  
  123.         Add-Type -AssemblyName System.Drawing
  124.  
  125. #>
  126.  
  127.     [OutputType([System.Windows.Forms.Form])]
  128.  
  129.     param
  130.  
  131.     (
  132.  
  133.         [Parameter(ParameterSetName = 'Image',
  134.  
  135.                    Mandatory = $true,
  136.  
  137.                    Position = 1)]
  138.  
  139.         [ValidateNotNull()]
  140.  
  141.         [System.Drawing.Image]$Image,
  142.  
  143.         [Parameter(Mandatory = $false)]
  144.  
  145.         [string]$Title,
  146.  
  147.         [int]$Timeout = 2,
  148.  
  149.         [Parameter(ParameterSetName = 'ImageLocation',
  150.  
  151.                    Mandatory = $true,
  152.  
  153.                    Position = 1)]
  154.  
  155.         [ValidateNotNullOrEmpty()]
  156.  
  157.         [string]$ImageLocation,
  158.  
  159.         [switch]$PassThru,
  160.  
  161.         [switch]$Modal
  162.  
  163.     )
  164.  
  165.    
  166.  
  167.     #Create a splash screen form to display the image.
  168.  
  169.     $splashForm = New-Object System.Windows.Forms.Form
  170.  
  171.    
  172.  
  173.     #Create a picture box for the image
  174.  
  175.     $pict = New-Object System.Windows.Forms.PictureBox
  176.  
  177.    
  178.  
  179.     if ($Image)
  180.  
  181.     {
  182.  
  183.         $pict.Image = $Image;
  184.  
  185.     }
  186.  
  187.     else
  188.  
  189.     {
  190.  
  191.         $pict.Load($ImageLocation)
  192.  
  193.     }
  194.  
  195.    
  196.  
  197.     $pict.AutoSize = $true
  198.  
  199.     $pict.Dock = 'Fill'
  200.  
  201.     $splashForm.Controls.Add($pict)
  202.  
  203.    
  204.  
  205.     #Display a title if defined.
  206.  
  207.     if ($Title)
  208.  
  209.     {
  210.  
  211.         $splashForm.Text = $Title
  212.  
  213.         $splashForm.FormBorderStyle = 'FixedDialog'
  214.  
  215.     }
  216.  
  217.     else
  218.  
  219.     {
  220.  
  221.         $splashForm.FormBorderStyle = 'None'
  222.  
  223.     }
  224.  
  225.    
  226.  
  227.     #Set a timer
  228.  
  229.     if ($Timeout -gt 0)
  230.  
  231.     {
  232.  
  233.         $timer = New-Object System.Windows.Forms.Timer
  234.  
  235.         $timer.Interval = $Timeout * 1000
  236.  
  237.         $timer.Tag = $splashForm
  238.  
  239.         $timer.add_Tick({
  240.  
  241.                 $this.Tag.Close();
  242.  
  243.                 $this.Stop()
  244.  
  245.             })
  246.  
  247.         $timer.Start()
  248.  
  249.     }
  250.  
  251.    
  252.  
  253.     #Show the form
  254.  
  255.     $splashForm.AutoSize = $true
  256.  
  257.     $splashForm.AutoSizeMode = 'GrowAndShrink'
  258.  
  259.     $splashForm.ControlBox = $false
  260.  
  261.     $splashForm.StartPosition = 'CenterScreen'
  262.  
  263.     $splashForm.TopMost = $true
  264.  
  265.    
  266.  
  267.     if ($Modal) { $splashForm.ShowDialog() }
  268.  
  269.     else { $splashForm.Show() }
  270.  
  271.    
  272.  
  273.     if ($PassThru)
  274.  
  275.     {
  276.  
  277.         return $splashForm
  278.  
  279.     }
  280.  
  281. }
SplashScreenTest.png
SplashScreenTest.png (44.25 KiB) Viewed 1647 times
Brittney Ryn
SAPIEN Technologies, Inc.

User avatar
mbrinkhoff
Posts: 11
Joined: Thu Nov 09, 2017 6:32 am

Re: Show-SplashScreen Problem, No Image

Post by mbrinkhoff »

Yes, it is part of a project and those functions are included in globals.ps1.

Code: Select all

function Show-SplashScreen
{
	<#
	.SYNOPSIS
		Displays a splash screen using the specified image.
	
	.PARAMETER Image
		Mandatory Image object that is displayed in the splash screen.
	
	.PARAMETER Title
		(Optional) Sets a title for the splash screen window. 
	
	.PARAMETER Timeout
		The amount of seconds before the splash screen is closed.
		Set to 0 to leave the splash screen open indefinitely.
		Default: 2
	
	.PARAMETER ImageLocation
		The file path or url to the image.

	.PARAMETER PassThru
		Returns the splash screen form control. Use to manually close the form.
	
	.PARAMETER Modal
		The splash screen will hold up the pipeline until it closes.

	.EXAMPLE
		PS C:\> Show-SplashScreen -Image $Image -Title 'Loading...' -Timeout 3

	.EXAMPLE
		PS C:\> Show-SplashScreen -ImageLocation 'C:\Image\MyImage.png' -Title 'Loading...' -Timeout 3

	.EXAMPLE
		PS C:\> $splashScreen = Show-SplashScreen -Image $Image -Title 'Loading...' -PassThru
				#close the splash screen
				$splashScreen.Close()
	.OUTPUTS
		System.Windows.Forms.Form
	
	.NOTES
		Created by SAPIEN Technologies, Inc.

		The size of the splash screen is dependent on the image.
		The required assemblies to use this function outside of a WinForms script:
		Add-Type -AssemblyName System.Windows.Forms
		Add-Type -AssemblyName System.Drawing
#>
	[OutputType([System.Windows.Forms.Form])]
	param
	(
		[Parameter(ParameterSetName = 'Image',
				   Mandatory = $true,
				   Position = 1)]
		[ValidateNotNull()]
		[System.Drawing.Image]$Image,
		[Parameter(Mandatory = $false)]
		[string]$Title,
		[int]$Timeout = 2,
		[Parameter(ParameterSetName = 'ImageLocation',
				   Mandatory = $true,
				   Position = 1)]
		[ValidateNotNullOrEmpty()]
		[string]$ImageLocation,
		[switch]$PassThru,
		[switch]$Modal
	)
	
	#Create a splash screen form to display the image.
	$splashForm = New-Object System.Windows.Forms.Form
	
	#Create a picture box for the image
	$pict = New-Object System.Windows.Forms.PictureBox
	
	if ($Image)
	{
		$pict.Image = $Image;
	}
	else
	{
		$pict.Load($ImageLocation)
	}
	
	$pict.AutoSize = $true
	$pict.Dock = 'Fill'
	$splashForm.Controls.Add($pict)
	
	#Display a title if defined.
	if ($Title)
	{
		$splashForm.Text = $Title
		$splashForm.FormBorderStyle = 'FixedDialog'
	}
	else
	{
		$splashForm.FormBorderStyle = 'None'
	}
	
	#Set a timer
	if ($Timeout -gt 0)
	{
		$timer = New-Object System.Windows.Forms.Timer
		$timer.Interval = $Timeout * 1000
		$timer.Tag = $splashForm
		$timer.add_Tick({
				$this.Tag.Close();
				$this.Stop()
			})
		$timer.Start()
	}
	
	#Show the form
	$splashForm.AutoSize = $true
	$splashForm.AutoSizeMode = 'GrowAndShrink'
	$splashForm.ControlBox = $false
	$splashForm.StartPosition = 'CenterScreen'
	$splashForm.TopMost = $true
	
	if ($Modal) { $splashForm.ShowDialog() }
	else { $splashForm.Show() }
	
	if ($PassThru)
	{
		return $splashForm
	}
}
#Sample function that provides the location of the script
function Get-ScriptDirectory {
<#
	.SYNOPSIS
		Get-ScriptDirectory returns the proper location of the script.

	.OUTPUTS
		System.String
	
	.NOTES
		Returns the correct path within a packaged executable.
#>
	[OutputType([string])]
	param ()
	if ($null -ne $hostinvocation)
	{
		Split-Path $hostinvocation.MyCommand.path
	}
	else
	{
		Split-Path $script:MyInvocation.MyCommand.Path
	}
}

User avatar
brittneyr
Site Admin
Posts: 361
Joined: Thu Jun 01, 2017 7:20 am

Re: Show-SplashScreen Problem, No Image

Post by brittneyr »

I have had no issues in any of my tests of this. Does this work if you create a new form, separate from your existing project, from the template or snippet?
Brittney Ryn
SAPIEN Technologies, Inc.