我有一个用 VB6 编写的应用程序。
此应用程序包含一个文件,其中包含包含
foreach
循环的片段。在此循环中,方法将控件添加到一个部分(部分是报告中的一个区域)。
我正在尝试实现以下功能:
当
theheader
添加到 headerSection
中时,tt
不会再次添加 theHeader
,但是此代码片段无法做到这一点。我哪里错了?
For Each thisColumn As Column In theColumns
If thisColumn.Type = Column.ColumnType.Description Then
AddDescriptionColumn(thisColumn, startColumnAt, headerTop)
End If
Private Sub AddDescriptionColumn(ByVal ColumnToAdd As Column, ByRef LeftPosition As Single, ByVal HeaderTop As Single)
'Get report sections
Dim headerSection As ActiveReports.Section = _theActiveReport.Sections(PageHeaderName)
'Add column header text
Dim theHeader As New ActiveReports.Label
theHeader.Name = "lblDescription"
theHeader.Text = ColumnToAdd.DisplayCaption
theHeader.Font = ColumnToAdd.HeaderFont
theHeader.Location = New PointF(LeftPosition, HeaderTop)
theHeader.Size = New SizeF(columnWidth, _columnHeaderHeight)
If TextHeight(ColumnToAdd.DisplayCaption, theHeader.Font, columnWidth) > _columnHeaderHeight Then
theHeader.VerticalAlignment = ActiveReports.VerticalTextAlignment.Top
Else
theHeader.VerticalAlignment = ActiveReports.VerticalTextAlignment.Bottom
End If
theHeader.BackColor = Color.Transparent
theHeader.MultiLine = True
theHeader.WordWrap = True
theHeader.Visible = True
headerSection.Controls.Add(theHeader)
我会尝试这样的事情:
Private Sub AddDescriptionColumn(...
Dim bolFound as boolean=False
'Get report sections
Dim headerSection As ActiveReports.Section = _theActiveReport.Sections(PageHeaderName)
' Iterate through the list of controls. Set bolFound if control name already exists.
For Each control As ARControl In headerSection.Controls
If control.Name="lblDescription" Then
bolFound=True
Exit For
End If
Next
If bolFound=True Then
'A control named lblDescription already exists in the headerSection
Else
'Add column header text
...
End If