我创建了一个自定义类 (DataGroupBoxControl),它基本上是一个 GroupBox,里面有一个或多个面板。每个面板并排放置两个标签,如下图所示。 在此处输入图像描述
该对象允许将 DataTable 传递给它,这决定了创建和显示多少行面板。我希望用户能够单击其中一个面板标签并执行“某事”。
这是创建标签的类中的过程。
Public Class DataGroupBoxControl
Inherits GroupBox
Public DataLabels As New List(Of DataLabelControl)
Public Sub BindData(ByVal ds As DataTable)
Dim colItem As Integer = 0
For Each col As DataColumn In ds.Columns
DataLabels.Add(New DataLabelControl)
For Each row As DataRow In ds.Rows
DataLabels(colItem).TitleLabel.Text = col.ColumnName & " " & _Separator
DataLabels(colItem).TitleLabel.Name = col.ColumnName
If IsNumeric(row.Item(colItem)) Then
If row.Item(colItem).ToString.IndexOf(".") <> -1 Then
DataLabels(colItem).ValueLabel.Text = Decimal.Parse(row.Item(colItem)).ToString("c")
Else
DataLabels(colItem).ValueLabel.Text = row.Item(colItem)
End If
End If
DataLabels(colItem).ValueLabel.Name = row.Item(colItem)
DataLabels(colItem).Top = (colItem * DataLabels(colItem).Height) + 20
DataLabels(colItem).Left = 5
Me.Controls.Add(DataLabels(colItem))
Me.Height = Me.Height + DataLabels(colItem).Height
DataLabels(colItem).Show()
Next
colItem += 1
Next
End Sub
在哪里以及如何创建标签点击事件处理程序?然后使用以下对象从我的主窗体访问该事件:
Public AccountsGroupBox As New DataGroupBoxControl