我有2个面板彼此相邻排列,如屏幕截图所示。每个小组由3-4个控件组成。
我想要实现的是 - 当表单大小发生变化时,面板的大小应该自动调整,保持两个面板之间的常量间隙。
到目前为止,我已经尝试了两个面板的各种锚组合,但无法获得所需的结果。 我有点被困在这里。 (我在Visual Basic 2013中工作)
答案 0 :(得分:1)
Dock
样式设置为Fill
。percent
50%
。absolute
20
。Dock
样式设置为Fill
。另外,我建议您阅读以下关于如何改进TLP渲染的SO帖子:
样本表格:
Public Class Form1
Public Sub New()
Me.InitializeComponent()
End Sub
Private Sub InitializeComponent()
Me.TableLayoutPanel1 = New System.Windows.Forms.TableLayoutPanel()
Me.Panel1 = New System.Windows.Forms.Panel()
Me.Panel2 = New System.Windows.Forms.Panel()
Me.TableLayoutPanel1.SuspendLayout()
Me.SuspendLayout()
'
'TableLayoutPanel1
'
Me.TableLayoutPanel1.ColumnCount = 3
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Absolute, 20.0!))
Me.TableLayoutPanel1.ColumnStyles.Add(New System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
Me.TableLayoutPanel1.Controls.Add(Me.Panel1, 0, 0)
Me.TableLayoutPanel1.Controls.Add(Me.Panel2, 2, 0)
Me.TableLayoutPanel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.TableLayoutPanel1.Location = New System.Drawing.Point(0, 0)
Me.TableLayoutPanel1.Name = "TableLayoutPanel1"
Me.TableLayoutPanel1.RowCount = 1
Me.TableLayoutPanel1.RowStyles.Add(New System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 100.0!))
Me.TableLayoutPanel1.Size = New System.Drawing.Size(682, 260)
Me.TableLayoutPanel1.TabIndex = 1
'
'Panel1
'
Me.Panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Panel1.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel1.Location = New System.Drawing.Point(3, 3)
Me.Panel1.Name = "Panel1"
Me.Panel1.Size = New System.Drawing.Size(325, 254)
Me.Panel1.TabIndex = 0
'
'Panel2
'
Me.Panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
Me.Panel2.Dock = System.Windows.Forms.DockStyle.Fill
Me.Panel2.Location = New System.Drawing.Point(354, 3)
Me.Panel2.Name = "Panel2"
Me.Panel2.Size = New System.Drawing.Size(325, 254)
Me.Panel2.TabIndex = 1
'
'Form1
'
Me.AutoScaleDimensions = New System.Drawing.SizeF(8.0!, 16.0!)
Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
Me.ClientSize = New System.Drawing.Size(682, 260)
Me.Controls.Add(Me.TableLayoutPanel1)
Me.Name = "Form1"
Me.Text = "Form1"
Me.TableLayoutPanel1.ResumeLayout(False)
Me.ResumeLayout(False)
End Sub
Friend WithEvents TableLayoutPanel1 As System.Windows.Forms.TableLayoutPanel
Friend WithEvents Panel1 As System.Windows.Forms.Panel
Friend WithEvents Panel2 As System.Windows.Forms.Panel
End Class
答案 1 :(得分:-1)
只需将左侧面板的底座设置为左右一对!