TablePanelLayout border remnant

This topic contains 1 reply, has 2 voices, and was last updated by Profile photo of Don Jones Don Jones 5 months, 1 week ago.

  • Author
    Posts
  • #59614
    Profile photo of Tom
    Tom
    Participant

    I am having an issue in powershell 2.0 where I put a border around a scrollable TablePanelLayout. When scrolling there is a border remnant – how do I get this remnant or program such that there is no border remnant when scrolling? Here is the code:

    [CmdletBinding()]
    
    Param()
    
    Set-StrictMode -Version 2
    
    Write-Verbose "Create the main form"
    $form = New-Object Windows.Forms.Form
    $form.Size = New-Object Drawing.Size @(900, 400)
    
    $form.SuspendLayout()
    
    $dataSize = 70
    $dataHeight = 20
    $volumeSize = 280
    
    Function Create-Data-Panel ($width, $height, $correction) {
    
        Write-Verbose "Create the panel that holds the data"
        $dataPanel = New-Object Windows.Forms.TableLayoutPanel
        $dataPanel.Size = New-Object Drawing.Size @($width,$height)
        $dataPanel.Dock = "Fill"
        $dataPanel.AutoScroll = $true
        $dataPanel.BackColor = "Transparent"
        $dataPanel.CellBorderStyle = "None"
        $dataPanel.RowCount = 0
        $dataPanel.ColumnCount = 7  
    
        $dataPanel.add_paint({$whitePen = new-object System.Drawing.Pen([system.drawing.color]::blue, 2)
        $_.graphics.drawrectangle($whitePen,$this.clientrectangle)
        })  
    
        $correctedWidth = $volumeSize - $correction
        for ($j=0; $j -lt 100; $j++){
        for ($i=0; $i -lt 7; $i++) {
            $label = New-Object System.Windows.Forms.Label
            $label.TextAlign = "MiddleCenter"
            $label.Text = "0"
            $label.Font = "Verdana, 9pt"
            $label.Size = "$dataSize,$dataHeight"
            $label.BackColor = "Transparent"
            if ($i -eq 0) {
                $label.Size = "$correctedWidth,$dataHeight"
                $label.Text = "$j 12345678901234567890123456789012"
            }
            $dataPanel.Controls.Add($label,$i,$j)
        }
        }
    
        return $dataPanel
    }
    
    $hght = $form.size.height * 3/4
    $statsPanel = Create-Data-Panel 760 60 4
    $form.Controls.Add($statsPanel)
    $form.Add_Shown( { $form.Activate() } )    
    $form.ResumeLayout()
    $form.StartPosition = "CenterScreen"    
    $form.ShowDialog()
    

    It appears that this remnant only occurs if you use the scroll slider or the scroll arrows but not if you click on the scroll bar itself to scroll.

  • #59994
    Profile photo of Don Jones
    Don Jones
    Keymaster

    That's really not PowerShell per se; you're using WinForms, and those kinda work like they work. It might be wroth your while to ask on someplace like StackOverflow, where there's a larger population of developers using WinForms who might have some useful advice. Sorry!

You must be logged in to reply to this topic.