Hide Horizontal Scroll bar

This topic contains 3 replies, has 3 voices, and was last updated by  Tom 10 months, 1 week ago.

  • Author
  • #59616


    I have a tablelayoutpanel (named tl) that I have the following settings:

    $tl.AutoScroll = $false
    $tl.VerticalScroll.Enabled = $true
    $tl.VerticalScroll.Visible = $true
    $tl.HorizontalScroll.Enabled = $false
    $tl.HorizontalScroll.Visible = $false

    This works initially – so if I populate the table then show the form dialog there is only a vertical scrollbar. Once I add something to the table after showing the form the vertical scrollbar disappears. If I change the AutoScroll to $true the initial panel is also correct (only the vertical scroll shows) but once I add to the table the scrollbars are reset – showing both the vertical and horizontal bars. It is as if the VerticalScroll settings and the HorizontalScroll settings are not persisted. How can I hide the horizontal scroll bar?

  • #59995

    Don Jones

    That's really all controlled from within the WinForm control itself, unfortunately. I'm not sure you could influence that behavior more than you already have.

  • #60037

    Dan Potter

    Post all of your code, I can only guess without it. Are you dynamically adding controls to the panel?

    Add an event for control added possibly.


    $tl.HorizontalScroll.Visible = $false

    • #60468

      Set-StrictMode -Version 2
      [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") | Out-Null
      [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null
      Write-Verbose "Create the main form"
      $form = New-Object Windows.Forms.Form
      $form.Size = New-Object Drawing.Size @(900, 600)
      $dataSize = 70
      $dataHeight = 20
      $volumeSize = 280
      $dp = New-Object Windows.Forms.TableLayoutPanel
      $addButton = New-Object Windows.Forms.Button
      $addButton.Text = "Add"
      $addButton.name = "outputButton"
      $addButton.Location = New-Object System.Drawing.Point(0,500)
      $correctedWidth = 0
      Function Add-Row ($txt) {
      	write-verbose "add row"
      	$zeroBasedRow = $dp.RowCount - 1
      	write-verbose $zeroBasedRow
          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"
      			if ($txt -eq $null){
      				$label.Text = "12345678901234567890123456789012"
      			} else {
      				$label.Text = $txt
      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.AutoScroll = $true
      	#$dataPanel.VerticalScroll.Enabled = $true
      	#$dataPanel.VerticalScroll.Visible = $true
      	#$dataPanel.HorizontalScroll.Enabled = $false
      	#$dataPanel.HorizontalScroll.Visible = $false
      	$dataPanel.BackColor = "Transparent"
      	$dataPanel.CellBorderStyle = "None"
      	$dataPanel.RowCount = 0
      	$dataPanel.ColumnCount = 7	
      	$script:correctedWidth = $volumeSize - $correction
      	return $dataPanel
      $hght = $form.size.height * 3/4
      $dp = Create-Data-Panel 760 300 4
      for ($j=0; $j -lt 50; $j++){     # LINE OF INTEREST!!!!!!
      	$txt = "$j 12345678901234567890123456789012"
      	Add-Row $txt
      $form.Add_Shown( { $form.Activate() } )    
      $form.StartPosition = "CenterScreen"	

      Notice that AutoScroll is on. If you run this script as is the TableLayoutPanel will only show the vertical scroll bar; push the "Add" button as many times as you want and you will see the table has new entries at the end and the scroll bar remains only showing the vertical scroll bar. The problem is that the TableLayoutPanel I am working with does not have ANY initial data on it so essentially the "LINE OF INTEREST!!!!!!" becomes a 0 for the $j bounding value. Change that value to zero so the line reads "for ($j=0; $j -lt 0; $j++){ # LINE OF INTEREST!!!!!!" and then run the script (notice the table is empty. Press the "Add" button (notice no scroll bars show up until they are needed which is not a problem). Fill the table so that the vertical scroll bar is needed and you will see that BOTH the vertical and horizontal scroll bars appear – I ONLY want the vertical scroll bar not the horizontal – so my question is how to hide the horizontal scroll bar? Thanks!

You must be logged in to reply to this topic.