在RDLC文件中,有没有办法将图像与Tablix单元格高度的中心对齐?不知何故,它只能有一个固定的位置.我能找到的唯一解决方案是填充,但我似乎找不到一种在运行时获取单元格尺寸的方法.
我需要这样做的原因是因为行上的其他单元格可能会改变行的高度,而且由于它主要是文本框,所以图像看起来不对齐.
在RDLC文件中,有没有办法将图像与Tablix单元格高度的中心对齐?不知何故,它只能有一个固定的位置.我能找到的唯一解决方案是填充,但我似乎找不到一种在运行时获取单元格尺寸的方法.
我需要这样做的原因是因为行上的其他单元格可能会改变行的高度,而且由于它主要是文本框,所以图像看起来不对齐.
我找到了某种解决方案.它需要知道将影响行的高度的字段的值.You also need a monospaced font.个 基本上,我为图像的填充设置了一个表达式.从那里我调用一个报告函数:
Function GetLineAmount(ByVal str As String, ByVal lineLength As Integer) As Integer
Dim amount As Integer = 1
If str.Length > lineLength Then
Dim positionToFind As Integer = lineLength
If str(positionToFind) <> " " Then
' Find the last position of a space character
Do While positionToFind >= 0 AndAlso str(positionToFind) <> " "
positionToFind -= 1
Loop
' Find the last position before that which is not a space (group of spaces)
Do While positionToFind >= 0 AndAlso str(positionToFind) = " "
positionToFind -= 1
Loop
positionToFind += 1
End If
If positionToFind = 0 Then
positionToFind = lineLength
End If
Dim rest As String = str.Substring(positionToFind)
'PDF somehow "deletes" the first space in a line of text, so 2 space will leave one ... leaving this if to adapt to the pdf.
If rest.Length > 0 AndAlso rest(0) = " " Then
rest = rest.Substring(1)
End If
If rest <> String.Empty Then
amount += GetLineAmount(rest, lineLength)
End If
End If
Return amount
End Function
这将返回一个字段将占用的行数.您必须知道一行需要多少个字符(which is why you need a monospaced font)
然后,从图像填充表达式中,代码将为:
= iif(Code.GetLineAmount(Fields!Description.Value,24) = 1
, "1pt"
, (4 + (6 * (Code.GetLineAmount(Fields!Description.Value,24) -2) )) & "pt"
)
所以在该部分中,我发送字段Description,它是在某个时间接受更多行的那个,然后是24,可以适合这些行的字符的数目.
100从我的测试中,以下是对顶部和底部填充的观察: