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.
User avatar
CitrixITM
Posts: 123
Joined: Tue Mar 01, 2016 8:28 am

Output is formatted differently after build

Post by CitrixITM » Mon Nov 13, 2017 9:33 pm

When I run my app from within PowerShell Studio, the output looks correct.
long.jpg
long.jpg (141.96 KiB) Viewed 315 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 315 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

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output is formatted differently after build

Post by jvierra » Mon Nov 13, 2017 9:42 pm

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: 123
Joined: Tue Mar 01, 2016 8:28 am

Re: Output is formatted differently after build

Post by CitrixITM » Tue Nov 14, 2017 9:45 am

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
Site Admin
Posts: 45
Joined: Sun Mar 03, 2013 12:42 pm

Re: Output is formatted differently after build

Post by mxtrinidad » Tue Nov 14, 2017 10:03 am

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

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

Hope this help!

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output is formatted differently after build

Post by jvierra » Tue Nov 14, 2017 10:17 am

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 3 times

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output is formatted differently after build

Post by jvierra » Tue Nov 14, 2017 10:19 am

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: 123
Joined: Tue Mar 01, 2016 8:28 am

Re: Output is formatted differently after build

Post by CitrixITM » Tue Nov 14, 2017 10: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")

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output is formatted differently after build

Post by jvierra » Tue Nov 14, 2017 10:32 am

Works for me when I build. Did you try my PSF example to seem how it behaves and how it can be easily resized.

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output is formatted differently after build

Post by jvierra » Tue Nov 14, 2017 10:35 am

mxtrinidad wrote:
Tue Nov 14, 2017 10: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".

User avatar
jvierra
Posts: 11550
Joined: Tue May 22, 2007 9:57 am
Contact:

Re: Output is formatted differently after build

Post by jvierra » Tue Nov 14, 2017 10:36 am

CitrixITM wrote:
Tue Nov 14, 2017 10: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.

Post Reply