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.
minimen456
Posts: 5
Last visit: Sat Apr 17, 2021 3:25 am
Has voted: 1 time
Post
by minimen456 » Tue Apr 06, 2021 3:04 pm
Hello,
I'd like to print results into a textbox in reverse order. I'm clicking a button and the newer datestamp must be on top. I've tried like this with no success. Is there a proper way?
Code: Select all
$txtResult.Lines += "$(get-date -Format "hh:mm:ss")"
$tmp = $txtResult.Lines
[array]::Reverse($tmp)
$txtResult.Lines = $tmp
Attachments
get-windowsversion_.psf
(38.67 KiB) Downloaded 8 times
Capture1.PNG (8.6 KiB) Viewed 312 times
jvierra
Posts: 14762
Last visit: Mon Apr 19, 2021 4:16 pm
Answers: 9
Has voted: 3 times
Been upvoted: 7 times
Post
by jvierra » Tue Apr 06, 2021 3:40 pm
There is no reverse order for an array. You can create a new array in reverse then assign it to the "Lines" property.
To insert lines in a list use a ListBox as inserts can be done at the top.
You can also do this.
$listbox.Text = $newline + $listbox.Text
minimen456
Posts: 5
Last visit: Sat Apr 17, 2021 3:25 am
Has voted: 1 time
Post
by minimen456 » Wed Apr 07, 2021 12:45 am
Does nothing, Listbox doesn't display anything:
I seems You've meant:
Code: Select all
$texbox1.Text = "$(get-date -Format "hh:mm:ss")" + [Environment]::NewLine + $textbox1.Text
Thanks, the solution works.
Also it seems I can't copy results to a clipboard from Listbox when the GUI is running.
jvierra
Posts: 14762
Last visit: Mon Apr 19, 2021 4:16 pm
Answers: 9
Has voted: 3 times
Been upvoted: 7 times
Post
by jvierra » Wed Apr 07, 2021 2:00 am
Sorry - typo. SHould be
$textbox.Text = $newline + $textbox.Text
For ListBox just insert the line at index 0.
$listbox.Items.Insert(0,$line)