ironmansoftware / powershell-pro-tools

Scripting, automation, and development tools for professionals working with PowerShell.
MIT License
46 stars 1 forks source link

Form Designer can sometimes mangle the designer code 🧟‍♂️ #3

Open DataTraveler1 opened 1 year ago

DataTraveler1 commented 1 year ago

Describe the bug

Form Designer can sometimes mangle the designer code on a WinForms project

Expected behavior

Clicking 'Save' on an unchanged WinForm project within Form Designer should not change any of the code

Actual behavior

Clicking 'Save' on an unchanged WinForm project within Form Designer may change some of the code

Version

Form Designer 2024.7.2

Steps to Reproduce

  1. Assemble the two required files issue2648.ps1 and issue2648-designer.ps1 into a WinForms project using the code further below
  2. Make a back-up copy of the project.
  3. Execute the project in PSScriptPad to ensure it works as expected (see screenshot further below 📸)
  4. Ensure that the project files and their backup copy have not changed and are still identical.
  5. Open the project in PSScriptPad again and without making any changes click Save 💾
  6. Compare the designer.ps1 file between the project you just opened versus its backup

List of changes observed after clicking Save

Line Number Change
Line 38 Deleted
Line 74 Modified
Line 82 Deleted
below figure shows the changes that occurred on line 74 & 82 image

Code To Reproduce (Issue2648.ps1)

$MainForm_Load = {
}
$ClickLinkLabel1 = {
    $LinkLabel1.add_Click({[system.Diagnostics.Process]::start('https://ironmansoftware.com')})
}

$ClickButton1 = {
    $MainForm.Close()
}
Add-Type -AssemblyName System.Windows.Forms
. (Join-Path $PSScriptRoot 'issue2648.designer.ps1')

$MainForm.ShowDialog()

Code To Reproduce (Issue2648-designer.ps1)

$MainForm = New-Object -TypeName System.Windows.Forms.Form
[System.Windows.Forms.Label]$Label2 = $null
[System.Windows.Forms.Button]$Button1 = $null
[System.Windows.Forms.GroupBox]$GroupBox1 = $null
[System.Windows.Forms.LinkLabel]$LinkLabel1 = $null
function InitializeComponent
{
$Label2 = (New-Object -TypeName System.Windows.Forms.Label)
$Button1 = (New-Object -TypeName System.Windows.Forms.Button)
$GroupBox1 = (New-Object -TypeName System.Windows.Forms.GroupBox)
$LinkLabel1 = (New-Object -TypeName System.Windows.Forms.LinkLabel)
$GroupBox1.SuspendLayout()
$MainForm.SuspendLayout()
#
#Label2
#
$Label2.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Segoe UI',[System.Single]12,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0)))
$Label2.ForeColor = [System.Drawing.Color]::FromArgb(([System.Int32]([System.Byte][System.Byte]102)),([System.Int32]([System.Byte][System.Byte]45)),([System.Int32]([System.Byte][System.Byte]142)))

$Label2.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]10,[System.Int32]35))
$Label2.Name = [System.String]'Label2'
$Label2.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]264,[System.Int32]61))
$Label2.TabIndex = [System.Int32]1
$Label2.Text = [System.String]'A suite of tools for scripters building solutions with PowerShell.'
#
#Button1
#
$Button1.AutoSize = $true
$Button1.BackColor = [System.Drawing.SystemColors]::Control
$Button1.FlatAppearance.BorderSize = [System.Int32]0
$Button1.FlatStyle = [System.Windows.Forms.FlatStyle]::Flat
$Button1.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Segoe UI',[System.Single]9.75,[System.Drawing.FontStyle]::Bold,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0)))
$Button1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]237,[System.Int32]98))
$Button1.Name = [System.String]'Button1'
$Button1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]29,[System.Int32]29))
$Button1.TabIndex = [System.Int32]2
$Button1.Text = [System.String]'X'
$Button1.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
$Button1.UseVisualStyleBackColor = $false
$Button1.add_Click($ClickButton1)
#
#GroupBox1
#
$GroupBox1.BackColor = [System.Drawing.Color]::White
$GroupBox1.Controls.Add($LinkLabel1)
$GroupBox1.Controls.Add($Label2)
$GroupBox1.Controls.Add($Button1)
$GroupBox1.ForeColor = [System.Drawing.Color]::FromArgb(([System.Int32]([System.Byte][System.Byte]102)),([System.Int32]([System.Byte][System.Byte]45)),([System.Int32]([System.Byte][System.Byte]142)))

$GroupBox1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]12,[System.Int32]-2))
$GroupBox1.Name = [System.String]'GroupBox1'
$GroupBox1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]279,[System.Int32]141))
$GroupBox1.TabIndex = [System.Int32]3
$GroupBox1.TabStop = $false
$GroupBox1.Text = [System.String]'PowerShell Pro Tools'
#
#LinkLabel1
#
$LinkLabel1.BackColor = [System.Drawing.SystemColors]::Control
$LinkLabel1.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Segoe UI',[System.Single]9.75,[System.Drawing.FontStyle]::Regular,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0)))
$LinkLabel1.LinkArea = (New-Object -TypeName System.Windows.Forms.LinkArea -ArgumentList @([System.Int32]160,[System.Int32]29))
$LinkLabel1.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @([System.Int32]13,[System.Int32]98))
$LinkLabel1.Name = [System.String]'LinkLabel1'
$LinkLabel1.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]160,[System.Int32]29))
$LinkLabel1.TabIndex = [System.Int32]3
$LinkLabel1.Text = [System.String]'visit ironmansoftware.com'
$LinkLabel1.TextAlign = [System.Drawing.ContentAlignment]::MiddleCenter
$LinkLabel1.UseCompatibleTextRendering = $true
$LinkLabel1.add_Click($ClickLinkLabel1)
#
#MainForm
#
$MainForm.BackColor = [System.Drawing.Color]::White
$MainForm.ClientSize = (New-Object -TypeName System.Drawing.Size -ArgumentList @([System.Int32]303,[System.Int32]150))
$MainForm.ControlBox = $false
$MainForm.Controls.Add($GroupBox1)
$MainForm.Font = (New-Object -TypeName System.Drawing.Font -ArgumentList @([System.String]'Segoe UI',[System.Single]15.75,[System.Drawing.FontStyle]::Bold,[System.Drawing.GraphicsUnit]::Point,([System.Byte][System.Byte]0)))
$MainForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$MainForm.MaximizeBox = $false
$MainForm.MinimizeBox = $false
$MainForm.ShowIcon = $false
$MainForm.Name = [System.String]'MainForm'
$MainForm.Text = [System.String]'Issue ironmansoftware/powershell-pro-tools#3'
$MainForm.add_Load($MainForm_Load)
$GroupBox1.ResumeLayout($false)
$GroupBox1.PerformLayout()
$MainForm.ResumeLayout($false)
Add-Member -InputObject $MainForm -Name Label2 -Value $Label2 -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name Button1 -Value $Button1 -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name GroupBox1 -Value $GroupBox1 -MemberType NoteProperty
Add-Member -InputObject $MainForm -Name LinkLabel1 -Value $LinkLabel1 -MemberType NoteProperty
}
. InitializeComponent

Screenshot

image

DataTraveler1 commented 1 year ago

The Before/After labels on the screenshot showing the differences are accidentally reversed.

adamdriscoll commented 1 year ago

I want to mention that I cannot reproduce this in Visual Studio even though they use the same code to parse and generate the code. It must be something with the form editor in PSScriptPad.