Text not lining up in textbox

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Matt Bloomfield Matt Bloomfield 5 months, 2 weeks ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #37892
    Profile photo of Andy Smith
    Andy Smith
    Participant

    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 {
    
    $HostName=$InputBoxHW.text;
    
    $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
    $Performance.Controls.Add($outputProc)
    

    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 %

    Cheers

    #37896
    Profile photo of Matt Bloomfield
    Matt Bloomfield
    Participant

    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.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.