私の問題は単純です。私はTableLayoutPanel
を持っていて、その中にさまざまな行があり、それぞれにコントロールが入っています。コンテンツが表示されていないときに自動サイズのTableLayoutPanel行が折りたたまれないようにする
Visible
プロパティがFalse
に設定されている場合を除いて、内容に基づいてTableLayoutPanel
のサイズを自動的に変更します。
このような状況が発生した場合、その行が空白のままにしておきたいと思います。
現在、コントロールのVisible
プロパティがFalse
に設定されている場合、その行は折りたたまれています。デバッガをチェックすると、Height
がまだ24
であり、0
ではないことがわかります。
私はさまざまな設定を使用して遊んできましたが、問題のグーグルでは、私がやろうとしていることとは正反対の方法を尋ねる人々がいるようです。簡単な例について
完全なコードは以下の通りです:
Form1.vbを
Option Strict On
Option Explicit On
Option Infer Off
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
For i As Integer = 0 To 2
Dim c As New CheckBox()
c.Text = "Checkbox" & i+1
If i = 0
AddHandler c.CheckedChanged, Sub(sender2 As Object, e2 As EventArgs)
If TryCast(sender2, CheckBox).Checked
TryCast(TableLayoutPanel1.Controls(1), CheckBox).Visible = False
Else
TryCast(TableLayoutPanel1.Controls(1), CheckBox).Visible = True
End If
End Sub
End If
TableLayoutPanel1.Controls.Add(c)
Next
End Sub
End Class
Form1.Designer.vb
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
Inherits System.Windows.Forms.Form
'Form overrides dispose to clean up the component list.
<System.Diagnostics.DebuggerNonUserCode()> _
Protected Overrides Sub Dispose(ByVal disposing As Boolean)
Try
If disposing AndAlso components IsNot Nothing Then
components.Dispose()
End If
Finally
MyBase.Dispose(disposing)
End Try
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()
Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
Me.SuspendLayout
'
'TableLayoutPanel1
'
Me.TableLayoutPanel1.AutoSize = true
Me.TableLayoutPanel1.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink
Me.TableLayoutPanel1.ColumnCount = 1
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle())
Me.TableLayoutPanel1.Location = New System.Drawing.Point(13, 13)
Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
Me.TableLayoutPanel1.RowCount = 3
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle())
Me.TableLayoutPanel1.Size = New System.Drawing.Size(0, 0)
Me.TableLayoutPanel1.TabIndex = 0
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(6!, 13!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(284, 261)
Me.Controls.Add(Me.TableLayoutPanel1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(false)
Me.PerformLayout
End Sub
Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
End Class
異常要求。 TLPのMinimumSizeプロパティは、あなたが探しているものが本当に*疑わしいと思うので、あまり縮められません。そうでない場合は、AutoSizeとAbsoluteの間でRowStyle.SizeTypeプロパティを反転するコードを追加する必要があります。 –