我有一个继承了我正在添加组框的面板的类。此组框现在包含几个文本框。我希望通过使用组框的AutoSize属性和组框的Padding属性,使文本框在组框内水平和垂直居中。这是我的尝试:
Imports System.Drawing
Public Class pnlItemMstr_A_OSI
Inherits Panel
Public Sub New(ByRef ItemMstr_DS As DataSet, ByVal padding As Integer)
MyBase.New()
Dim drItemMstr As DataRow = ItemMstr_DS.Tables(0)(0)
Dim txtHeight As Integer = 26
' article numbers
Dim grpArtNum As New GroupBox
Dim txtARTC_NUM_DOM_C As New TextBox
Dim txtARTC_NUM_CAN_C As New TextBox
With txtARTC_NUM_DOM_C
.Text = drItemMstr("ARTC_NUM_DOM_C").ToString
.Size = New Size(200, txtHeight)
.Location = New Point(0, 0)
End With
With txtARTC_NUM_CAN_C
.Text = drItemMstr("ARTC_NUM_CAN_C").ToString
.Size = New Size(200, txtHeight)
.Location = New Point(0, txtHeight)
End With
With grpArtNum
grpArtNum.Text = "Article Number"
grpArtNum.Padding = New Padding(padding)
grpArtNum.Controls.Add(txtARTC_NUM_DOM_C)
grpArtNum.Controls.Add(txtARTC_NUM_CAN_C)
End With
Me.Controls.Add(grpArtNum)
End Sub
End Class
我最终得到的是丑陋而不是我期望发生的事情,请注意组框文本是如何被切断的:
看起来填充没有正确应用,但我确信我只是做错了。
答案 0 :(得分:1)
Padding属性主要用于Dock Styled子控件,因此请尝试将Dock填充面板添加到GroupBox中以包含这些TextBox:
With grpArtNum
grpArtNum.Text = "Article Number"
grpArtNum.Padding = New Padding(padding)
Dim innerPanel As New Panel With {.Dock = DockStyle.Fill}
innerPanel.Controls.Add(txtARTC_NUM_DOM_C)
innerPanel.Controls.Add(txtARTC_NUM_CAN_C)
grpArtNum.Controls.Add(innerPanel)
End With