【问题标题】:iTextsharp and DataGrid color conflictiTextsharp 和 DataGrid 颜色冲突
【发布时间】:2016-10-29 06:11:07
【问题描述】:

我的代码上的一个 DataGrid 使用类似的代码进行个性化

With MyDataGrid
    .RowsDefaultCellStyle.BackColor = Color.White
    .AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray
End With

工作正常。

使用 Nuget,我使用 Install-Package iTextSharp 安装了 iTextsharp,然后我添加了这些行

Imports iTextSharp.text.pdf
Imports iTextSharp.text
Imports iTextSharp.text.BaseColor

代码有效,PDF 已创建

但如果我添加行

Imports iTextSharp.text.Font

一行出现冲突

With MyDataGrid
    .RowsDefaultCellStyle.BackColor = Color.White
    .AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray
End With

Visual Studio 说

属性 iTextSharp.text.Font.Color 作为 BaseColor 获取/设置此字体的颜色 对非共享成员的引用需要对象引用

我认为 Visual Studio 将 Datagrid 的 Color.White 属性与 iTextsharp 的文本之一混淆了。

但即使使用这段代码(在 With MyDataGrid 之外)

MyDataGrid.RowsDefaultCellStyle.BackColor = Color.White
MyDataGrid.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray

冲突持续

如何避免这种冲突?

【问题讨论】:

    标签: vb.net itext


    【解决方案1】:

    您可以通过显式使用 System.Drawing 颜色强制它使用您想要的系统颜色,因此它不会尝试从您的其他 itextsharp 引用中获取颜色前缀:

        With MyDataGrid
            .RowsDefaultCellStyle.BackColor = System.Drawing.Color.White
            .AlternatingRowsDefaultCellStyle.BackColor = System.Drawing.Color.LightGray
        End With
    

    【讨论】:

    • 简单的解决方案!谢谢。
    猜你喜欢
    • 2021-09-27
    • 1970-01-01
    • 1970-01-01
    • 2011-06-23
    • 2023-03-19
    • 1970-01-01
    • 2014-04-27
    • 2014-11-28
    • 2023-04-08
    相关资源
    最近更新 更多