Quantcast
Viewing all articles
Browse latest Browse all 546

PowerShell GUIs • Problems migrating from 5.1 to 7.4.1

A couple of weeks ago, I was low on ideas for new snippets and scripts. I then decided to look ahead and prepare for a new era.
The preparations went smooth and it looked like a walkover; but so far it hasn’t been.
I have collaborated with AI on many tricky things in Powershell, but here at last “he” was running out of suggestions and adviced me to a Forum like this one. So here I am.
The last thing I made my friend AI do, was making a 10 point plan for testing out my Win10 installation running Powershell ISE and it went fine. I also made “him” make a function that ran through my approx. 200 snippets and scripts, that tested for 7.4.1 acceptance, only 2 passed, that’s when he adviced me to join you.
I have collected all my things so they are menu driven, with System.Windows.Forms.ListBox as driver. Now hold on tight:
Below is my listbox and it works fine in 5.1; but doesn’t show in 7.4.1. I know you will all say, we can’t reproduce that; but if I’m the only one, how can I then get it fixed?

#load the appropriate assemblies
[void][Reflection.Assembly]::LoadWithPartialName("Sy

Code:

#load the appropriate assemblies
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms.DataVisualization")

#create chart
$Chart = New-object System.Windows.Forms.DataVisualization.Charting.Chart
$Chart.Width = 500
$Chart.Height = 400
$Chart.Left = 40
$Chart.Top = 30

#create a chartarea to draw on and add to chart
$ChartArea = New-Object System.Windows.Forms.DataVisualization.Charting.ChartArea.
$Chart.ChartAreas.Add($ChartArea)

#listbox form
$form = New-Object System.Windows.Forms.Form
$form.Text = 'HeatingChart 2020'
$form.Size = New-Object System.Drawing.Size(300,280)
$form.StartPosition = 'CenterScreen'

#legend
$legend = New-Object system.Windows.Forms.DataVisualization.Charting.Legend
$legend.name = "Legend1"
$Chart.Legends.Add($Legend)
$Legend.Docking = 'bottom'

$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,190)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = 'OK'
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$form.AcceptButton = $okButton
$form.Controls.Add($okButton)

$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,190)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = 'Cancel'
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)

$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = ' Choose a 3 year period'
$form.Controls.Add($label)

#listbox
$listBox = New-Object System.Windows.Forms.ListBox
$listBox.Location = New-Object System.Drawing.Point(10,40)
$listBox.Size = New-Object System.Drawing.Size(260,20)
$listBox.Height = 135

#[void]$listBox.Items.AddRange($Xyear)
$form.Controls.Add($listBox)
$form.Topmost = $true
$result = $form.ShowDialog()

Statistics: Posted by drewdavis — Mon Apr 15, 2024 1:49 am



Viewing all articles
Browse latest Browse all 546

Trending Articles