Is “Courier Regular” an actual font installed on your machine? Maybe use a FontDialog control to select from a list of installed fonts? http://msdn.microsoft.com/en-us/library/system.windows.forms.control.font(v=vs.110).aspx?cs-save-lang=1&cs-lang=vb#code-snippet-1
From: [email protected] [mailto:[email protected]] On Behalf Of Michael Leone Sent: Wednesday, 1 October 2014 6:33 AM To: [email protected] Cc: [email protected] Subject: [NTSysADM] Formatting a ListBox 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: [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?

