I'm not much of a scripter, by any means. But, looking at your issue, I
think the problem lies more in the fact that you are using a varible width
font for your form. If you changed over to a fixed width font, like Courier
or Lucinda Console, that may help you with the formatting.

Daniel

On Tue, Sep 30, 2014 at 4:33 PM, Michael Leone <[email protected]> wrote:

> I am not a .Net programmer. But I came across a script online that I find
> useful, and now I am trying to modify it a bit. What the script does is put
> a listbox on a form; the listbox is populated with an entry I am trying to
> construct (by which I mean - I am concatenating 3 string variables
> together, and adding that as the list entry.
>
> Here's the problem: The onscreen formatting needs to be a fixed width, and
> what I am ending up with looks like this:
>
> [image: Inline image 1]
>
> See how it's wandering? I want a fixed font onscreen, and I can't seem to
> figure out how to get it to do that. I am padding the individual components
> to the widths I want, but it still shows onscreen like that.
>
> Here's the code snippets:
>
> $FormWidth = 300 # 300
> $FormHeight = 500 # 320
>
> $objForm = New-Object System.Windows.Forms.Form
> $objForm.Text = "Select user(s)"
> $objForm.Size = New-Object System.Drawing.Size($FormWidth,$FormHeight)
> $objForm.StartPosition = "CenterScreen"
> ## ----- Make the ListBox -----
> $objListBox = New-Object System.Windows.Forms.ListBox
> $objListBox.Name = "List of RDS Users"
> $ListBoxLocationWidth = $FormWidth * 0.03
> $ListBoxLocationHeight = $FormHeight * 0.09
> $objListBox.Location = New-Object
> System.Drawing.Size($ListBoxLocationWidth,$ListBoxLocationHeight)
> $ListBoxSizeWidth = $FormWidth * 0.93
> $ListBoxSizeHeight = $FormHeight * 0.05
> $objListBox.Size = New-Object
> System.Drawing.Size($ListBoxSizeWidth,$ListBoxSizeHeight)
> $objListBox.Height = $FormHeight * 0.41
> $objListBox.ScrollAlwaysVisible = $true
> $objListBox.Font = "Courier Regular"
> $objListBox.SelectionMode = "MultiExtended"
>
> Function FillListBox
> {
> $LoggedOnUsers = Get-RDUserSession -ConnectionBroker "$connectionBroker"
> -CollectionName "$SessionHostCollection" | Sort-Object -Property UserName
> ForEach ($user in $LoggedOnUsers)
> {
>   $RDS_User = "{0,-10}" -f $user.UserName.PadRight(10)
>   SWITCH ($user.SessionState)
>   {
>     "STATE_CONNECTED" { $RDS_Status = "ACTIVE      "}
>     "STATE_DISCONNECTED" { $RDS_Status = "DISCONNECTED"}
>    }
>  $RDS_Server = [string] $user.ServerName
>  $TheListEntry = $RDS_User + "| " + $RDS_Status + "; " +
>  $RDS_Server.SubString(0,10)
>  [void] $objListBox.Items.Add($TheListEntry)
> }
>
> I'm sure it's simple, but it's eluding my fried brain today.
> Clues, anyone?
>



-- 
Daniel Rodriguez
[email protected]

Reply via email to