Trying to add popup but bad size when using with PSAPPDeploytoolkit

Hello,

I added a popup to allow a user to read a message before continuing.
The popup works fine in a powershell, but when I integrate it into the Psappdeploytoolkit, the size is no longer correct.

I don’t understand why, even trying to change it, it doesn’t change anything …

Version 3.7.0 and 3.8.4 tested, same behavior.

Do you have an idea ?

you might have to modify the code in AppDeployToolkitMain.ps1 to either make the dialog bigger or shrink the size of the fonts.

The easiest way to get around this problem is to reword your messages or break it up into 2 popups.

I can’t add another popup for this.
Do you know what i should modify in main.ps1 ?

I don’t find the good parameter i need to modify.

I can’t guess which function you are using to do the popup either.
Help me to help you.

Here the function to show the popup :

#regionCustomPopup
Function CustomPopup 
{

               [CmdletBinding()]
               Param (

               )

               Begin {
                              ## Get the name of this function and write header
                              [string]${CmdletName} = $PSCmdlet.MyInvocation.MyCommand.Name
                              Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -CmdletBoundParameters $PSBoundParameters -Header
               }


    Process {

                             #----------------------------------------------
                             #region Import the Assemblies
                             #----------------------------------------------
                             [void][reflection.assembly]::LoadWithPartialName('System.Windows.Forms')
                             [void][reflection.assembly]::LoadWithPartialName('System.Data')
                             [void][reflection.assembly]::LoadWithPartialName('System.Drawing')
                             #endregion Import Assemblies
                
                             #----------------------------------------------
                             #region Generated Form Objects
                             #----------------------------------------------
                             [System.Windows.Forms.Application]::EnableVisualStyles()
                             $MainForm = New-Object 'System.Windows.Forms.Form'
                
                    $panelBanner = New-Object 'System.Windows.Forms.Panel'
                    $panelButton = New-Object 'System.Windows.Forms.Panel'
                
                    $labelUnsaved = New-Object 'System.Windows.Forms.Label'
                    $labelMain = New-Object 'System.Windows.Forms.Label'
                    $labelInstallNowMessage = New-Object 'System.Windows.Forms.Label'
        
                    $ButtonApplyNow = New-Object 'System.Windows.Forms.Button'
                             
                    $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
                
                    $NotifyIcon = New-Object 'System.Windows.Forms.NotifyIcon'
                    $ContextMenu = New-Object 'System.Windows.Forms.ContextMenu'
                    $ShowItem = New-Object 'System.Windows.Forms.MenuItem'
                    $MinimizeItem = New-Object 'System.Windows.Forms.MenuItem'
        
                    $MyDir = [System.IO.Path]::GetDirectoryName($myInvocation.ScriptName)
                             #endregion Generated Form Objects

                    
                #region Text
                        $TextButton = "Update Now"
                        $Text = "
Software to update now -  the new software will be updated in a few minutes.

Name of the software must be now updated in order to continue the to use it on your PC.

Please save your work and close all open files/documents before proceeding.

The update will start when you have clicked on the update now and your machine will be restarted after the update.
"

               
                        $TextSettingsMain = 'Microsoft Sans Serif, 11pt'
                        $TextSettingsUnsaved = 'Microsoft Sans Serif, 11pt, style=Bold'
                        $TextUnsavedLocation = '24, 230'
                #endregion


                             [scriptblock]$MainForm_Load={
                
                             }

                             [scriptblock]$ShowItem.add_Click({
                        $MainForm.WindowState = "Normal"
                    })
                
                    [scriptblock]$MinimizeItem.add_Click({
                        $MainForm.WindowState = "minimized"
                    })
                
                    [scriptblock]$NotifyIcon_MouseDoubleClick = {
                        $MainForm.WindowState = "Normal"
                    }
        
                             [scriptblock]$ButtonApplyNow_Click={
                        $MainForm.Hide()
                        $MainForm.Close()
                        Write-log -message "[Update Now] button clicked"
                        $resultPopUp = [System.Windows.MessageBox]::Show("Are you sure ?",'Update Software','YESNO','Warning','NO')
                        If($resultPopUp -eq "YES")
                        {
                            Write-log -message "User selected YES"
                            $MainForm.Close()
                        }
                        Else
                        {
                            Write-log -message "User selected NO"
                            main($command)
                        }

                                            
                             }
                
                             $panelButton_Paint=[System.Windows.Forms.PaintEventHandler]{
                                            
                             }

                                            # --End User Generated Script--
                             #----------------------------------------------
                             #region Generated Events
                             #----------------------------------------------
                             
                             [scriptblock]$Form_StateCorrection_Load=
                             {
                                            #Correct the initial state of the form to prevent the .Net maximized form issue
                                            $MainForm.WindowState = $InitialFormWindowState
                             }
                             
                             [scriptblock]$Form_StoreValues_Closing=
                             {
                                            #Store the control values
                             }
                
                             
                             [scriptblock]$Form_Cleanup_FormClosed=
                             {
                                            #Remove all event handlers from the controls
                                            try
                                            {
                                                          $ButtonApplyNow.remove_Click($ButtonApplyNow_Click)
                                                          $panelButton.remove_Paint($panelButton_Paint)
                                                          $MainForm.remove_Load($MainForm_Load)
                                                          $MainForm.remove_Load($Form_StateCorrection_Load)
                                                          $MainForm.remove_Closing($Form_StoreValues_Closing)
                                                           $MainForm.remove_FormClosed($Form_Cleanup_FormClosed)
                                            }
                                            catch [Exception]
                                            { }
                             }
                             #endregion Generated Events
                
                             #----------------------------------------------
                             #region Generated Form Code
                             #----------------------------------------------
                             $MainForm.SuspendLayout()
                             $panelButton.SuspendLayout()
                             $panelBanner.SuspendLayout()

                #region Main Form
                    #----------------------------------------------
                    # Main Form
                    #----------------------------------------------
                    [string]$invokingScript = (Get-Variable -Name 'MyInvocation').Value.ScriptName
                    [string]$scriptParentPath = Split-Path -Path $invokingScript -Parent
                    $Icon = New-Object System.Drawing.Icon("$scriptParentPath\AppDeployToolkit\AppDeployToolkitLogo.ico")
                             $MainForm.Controls.Add($panelButton)
                             $MainForm.Controls.Add($panelBanner)
                    $MainForm.Controls.Add($labelUnsaved)
                             $MainForm.Controls.Add($labelMain)
                    $MainForm.Controls.Add($labelInstallNowMessage)
                    $MainForm.Controls.Add($labelInformation)
                             #$MainForm.AutoScaleDimensions = '6, 13'
                             #$MainForm.AutoScaleMode = 'Font'
                             $MainForm.BackColor = '#FFFFFF'
                             $MainForm.ClientSize = '700, 450'
                    $MainForm.ControlBox = $False #Mettre False pour empecher de fermer le popup
                             $MainForm.Name = 'MainForm'
                    $MainForm.Icon = $Icon
                             $MainForm.ShowIcon = $False
                    $MainForm.FormBorderStyle = 'FixedDialog'
                             $MainForm.ShowInTaskbar = $False #Mettre False pour le déploiement
                             $MainForm.StartPosition = 'CenterScreen'
                             $MainForm.Text = 'Update Software - WARNING - You must close any files opened'
                             $MainForm.TopMost = $True
                             $MainForm.add_Load($MainForm_Load)
                    #$MainForm.AutoSize = $True
                    #endregion
                
        
                #region panel
                             #----------------------------------------------
                    # panelButton
                    #----------------------------------------------
                    $panelButton.Controls.Add($ListBox)
                             $panelButton.Controls.Add($ButtonApplyNow)
                             $panelButton.BackColor = '39,80,155'
                             $panelButton.Location = '0, 370'
                             $panelButton.Name = 'panelButton'
                             $panelButton.Size = '700, 80'
                             $panelButton.TabIndex = 10
                             $panelButton.add_Paint($panelButton_Paint)
                
                    #----------------------------------------------
                    # panelBanner
                    #----------------------------------------------
                    $Image = [System.Drawing.Image]::FromFile("$scriptParentPath\AppDeployToolkit\AppDeployToolkitBanner.png")
                    $panelBanner.BackgroundImage = $Image
                    $panelBanner.BackgroundImageLayout = "None"
                             $panelBanner.BackColor = '39, 80, 155'
                             $panelBanner.Location = '0, 0'
                             $panelBanner.Name = 'panelBanner'
                             $panelBanner.Size = '700, 80'
                             $panelBanner.TabIndex = 9
                #endregion
                
                #region label
                    #----------------------------------------------
                    # labelMain
                    #----------------------------------------------
                             $labelMain.Font = $TextSettingsMain
                             $labelMain.Location = '24, 90'
                             $labelMain.Name = 'labelMain'
                             $labelMain.Size = '666, 350'
                             $labelMain.TabIndex = 2
                             $labelMain.Text = $Text
        
                #region Notification
                    #----------------------------------------------
                    # NotifyIcon
                    #----------------------------------------------
                    $ShowItem.Text = "Show"
                    $MinimizeItem.Text = "Minimize"
                    $NotifyIcon.Icon = $Icon
                    $NotifyIcon.ContextMenu = $ContextMenu
                    $NotifyIcon.ContextMenu.MenuItems.Add($ShowItem)
                    $NotifyIcon.ContextMenu.MenuItems.Add($MinimizeItem)
                    $NotifyIcon.Visible = $True
                    $NotifyIcon.add_DoubleClick($NotifyIcon_MouseDoubleClick)
                #endregion
                
                #endregion Label
        
                #region Button
                
                             #----------------------------------------------
                    # ButtonApplyNow
                    #----------------------------------------------
                             $ButtonApplyNow.Font = 'Microsoft Sans Serif, 10pt, style=Bold'
                    $ButtonApplyNow.ForeColor = 'DarkRed'
                             $ButtonApplyNow.Location = '285, 20' #24,20 by default
                             $ButtonApplyNow.Name = 'ButtonApplyNow'
                             $ButtonApplyNow.Size = '125, 45'
                             $ButtonApplyNow.TabIndex = 6
                             $ButtonApplyNow.Text = $TextButton
                    $ButtonApplyNow.FlatStyle = "System"
                    $ButtonApplyNow.BackColor = '#FFFFFF'
                             #$ButtonApplyNow.UseVisualStyleBackColor = $True
                             $ButtonApplyNow.add_Click($ButtonApplyNow_Click)
        
                #endregion Button

                
                             #endregion Generated Form Code
                
                             #----------------------------------------------
                
                             #Save the initial state of the form
                             $InitialFormWindowState = $MainForm.WindowState
                             #Init the OnLoad event to correct the initial state of the form
                             $MainForm.add_Load($Form_StateCorrection_Load)
                             #Clean up the control events
                             $MainForm.add_FormClosed($Form_Cleanup_FormClosed)
                             #Store the control values when form is closing
                             $MainForm.add_Closing($Form_StoreValues_Closing)
                             #Show the Form
                             return $MainForm.ShowDialog()

    }

               End {
                              Write-FunctionHeaderOrFooter -CmdletName ${CmdletName} -Footer
               }

}
#endregion

#To launch the popup
CustomPopup

The custom popup does not look different with or without PSADT.
Try on another PC.

You are, however, using variables with the same name as PSADT: $InitialFormWindowState, $NotifyIcon, $panelButton to name a few. Maybe PSADT changes one or more of your variables.
OR PSADT sets global setting that breaks your popup. A debugger with a breakpoint set before your function end would give you the ability to see what your variables are set to before your function terminates.

Sorry I cannot help you more.

Why you don’t use the toolkit Show-DialogBox function?
Or you can even use Show-InstallationWelcome with a -CustomText parameter which can be added in the AppDeployToolkitConfig.xml file?

1 Like

I tried to rename the variables, but it’s the same behavior.
I tried the psapp with the popup on different VM and 2 computers but it the same result each time.

I tried the show-dialogbox function but i need more customisation, that’s why i recreate one.
To add banner, and specific button (also red specific text for certain cases)

Try to reduce the size of your function to the smallest possible that still causes your problem.
This might help you to locate your issue.

Also try to run with and without PS editors. (disclaimer - I still use PowerGUI)

I tried, but it’s always the same results.
If i execute only the form directly from Powershell_ISE, i have the good size.
But if i run either the deploy-application.ps1 or the deploy-application.exe from powershell.exe or cmd.exe, i haven’t the good size at the start.
When the popup appears, i have a window, but if i click on “update now” button, the windows size’s change and become the size attended.
But if the user says “No”, he will revert to the old popup, so i want to fix it.