Output is formatted differently after build

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 6 years and 4 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
CitrixITM
Posts: 124
Last visit: Wed Jul 27, 2022 2:19 pm

Output is formatted differently after build

Post by CitrixITM »

When I run my app from within PowerShell Studio, the output looks correct.
long.jpg
long.jpg (141.96 KiB) Viewed 4066 times
After I build it into an .exe and run it, the format doesn't look correct (it is missing the right most fields and looks like it is squished even though there is more space).
short.jpg
short.jpg (98.06 KiB) Viewed 4066 times
Here is the applicable code:
$VMInfo = Get-AzureRmVmPublicIP -ResourceGroupName $RGVM -VMName $VMip -VMStatus | Select -Property VMNAME, PublicIP
$textboxOutput.AppendText("$VMInfo")

Not sure why it is different after a build.

Brian
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Output is formatted differently after build

Post by jvierra »

You need to custom format the output. I recommend using a DataGridView as it will auto size better. You can also use Format-Table and set the column widths.
User avatar
CitrixITM
Posts: 124
Last visit: Wed Jul 27, 2022 2:19 pm

Re: Output is formatted differently after build

Post by CitrixITM »

Thanks. It looks like no mater how I attempt to format the output, it is still cutting off in the GUI around 80 characters. It is also doing this in the Gridview.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Output is formatted differently after build

Post by mxtrinidad »

Try the following command as I've seen it working with RichTextBox.

"... | Out-string -width 1000"

Hope this help!
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Output is formatted differently after build

Post by jvierra »

For textbox you need to set a compatible fixed font. Be sure to change the form AutoscaleMode to DPI.
The TextBox control does not truncate or expand columns. If you use Out-String the width will get interpreted. Use Format-Table. Also build for Windows Forms latest version.

This code works and displays correctly in all cases. (see attached PSF).

Code: Select all

    $textbox1.Lines = Get-Process | 
        select * -First 20 | 
        Format-Table -AutoSize | 
        Out-String -Width 250	
Attachments
Test-TextBoxFormats.psf
(25.11 KiB) Downloaded 143 times
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Output is formatted differently after build

Post by jvierra »

The default for Out-String is as follows:
-Width

Specifies the number of characters in each line of output. Any additional characters are truncated, not wrapped. If you omit this parameter, the width is determined by the characteristics of the host program. The default value for the Windows PowerShell console is 80 (characters).+

Type: Int32
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
Always check the help first:

help Out-File -Online
User avatar
CitrixITM
Posts: 124
Last visit: Wed Jul 27, 2022 2:19 pm

Re: Output is formatted differently after build

Post by CitrixITM »

Thanks, I did attempt to use out-string, but it had no effect. Below is my code. I'm surprised that it works fine in the Studio, but not fine once built. Is that normal?

$VMInfoFormated = $VMInfo | Format-Table -AutoSize | Out-String -Width 250
$textboxOutput.AppendText("$VMInfoFormated")
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Output is formatted differently after build

Post by jvierra »

Works for me when I build. Did you try my PSF example to seem how it behaves and how it can be easily resized.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Output is formatted differently after build

Post by jvierra »

mxtrinidad wrote: Tue Nov 14, 2017 9:03 am Try the following command as I've seen it working with RichTextBox.

"... | Out-string -width 1000"

Hope this help!
Using Format-Table -auto combined with Out-String helps to stabilize the result. Setting DPI mode also helps to maintain translation from PSS to hi-rez monitors. All require using a "fixed" font like "Lucida Console".
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Output is formatted differently after build

Post by jvierra »

CitrixITM wrote: Tue Nov 14, 2017 9:29 am Thanks, I did attempt to use out-string, but it had no effect. Below is my code. I'm surprised that it works fine in the Studio, but not fine once built. Is that normal?

$VMInfoFormated = $VMInfo | Format-Table -AutoSize | Out-String -Width 250
$textboxOutput.AppendText("$VMInfoFormated")
Do not use "AppendText". Use $textboxOutput.Lines as this will flow correctly.
This topic is 6 years and 4 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