Text not lining up in textbox

This topic contains 1 reply, has 2 voices, and was last updated by  Matt Bloomfield 2 years, 3 months ago.

  • Author
  • #37892

    Andy Smith

    I've been trying for over 3 hrs now just to get the output from the below lined up on the left of a text box

    function processes {
    $topprocs = Get-Counter -ComputerName $HostName '\Process(*)\% Processor Time' -ErrorAction SilentlyContinue | Select-Object -ExpandProperty countersamples | %{New-Object PSObject -Property @{ComputerName=$_.Path.Split('\')[2];Process=$_.instancename;CPUPct=("{0,4:N0}%" -f $_.Cookedvalue);CookedValue=$_.CookedValue}} | ?{$_.CookedValue -gt 0}| Sort-Object @{E='ComputerName'; A=$true },@{E='CookedValue'; D=$true },@{E='Process'; A=$true }
    $procs = $topprocs | ft @{E={"{0,25}" -f $_.Process};L="ProcessName"},CPUPct -HideTableHeaders -AutoSize
    $outputProc.text = write $procs | Out-String
    $outputProc = New-Object System.Windows.Forms.TextBox
    $outputProc.Location = New-Object System.Drawing.Size(70,80)
    $outputProc.Size = New-Object System.Drawing.Size(250,150)
    $outputProc.MultiLine = $True

    Sorry was going to paste a pic but can't

    Anyway the txt is in the middle of the box with a space at the top

    All i want it the process and %


  • #37896

    Matt Bloomfield

    Default should be to align left. Have you tried forcing it with

    $outputProc.TextAlign = 'Left'

    The other thing check is that your input to the textbox does not have any spaces or formatting that's causing the problem. Try using the trim() method on the input to remove any white space.

You must be logged in to reply to this topic.