在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从我的测试中,以下是对顶部和底部填充的观察:

  • 1行需要1磅填充
  • 2行需要4磅
  • 3及以上为增量为6.

Csharp相关问答推荐

使用变量子根名称在C#中重新初始化SON文件

如何在C#中将对象[*,*]直接转换为字符串[*,*]?

使用Audit.EntityFramework,我如何将外键的值设置为相关实体上的属性?

C#XmlSerializer-输出控制新行的多个XML片段

HttpConext.Request.Path和HttpConext.GetEndpoint()之间的差异

Blazor WebApp:原始异常:AADSTS700025:客户端是公共的,因此既不应显示客户端,也不应显示客户端

如何忽略API JSON响应中的空字符串?

使用CollectionView时在.NET Maui中显示数据时出现问题

在集成测试中可以在模拟InMemory数据库中设定数据种子

WPF动态设置弹出窗口水平偏移

如何在特定环境中运行dotnet测试?

如何使用EPPlus C#在单个单元格中可视化显示多行文字

如何使用类似于[SELECT*FROM&Q;&Q;WHERE&Q;]SQL查询的System.Data.Entity创建查询?

使用Blazor WebAssembly提高初始页面加载时间的性能

具有嵌套属性的IGGroup

Linq SELECT的多条指令

如何使用.NET 8.0中新的CompositeFormat类?

如何将 colored颜色 转换为KnownColor名称?

我应该使用IMhemyCache来存储承载令牌,还是应该为Azure函数中的401个错误实施Polly重试策略?

部署Aspnet Blazor服务器时出现未处理的Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]异常