Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ITextSharp如何将矩形参数传递给方法以设置边框_C#_Itext - Fatal编程技术网

C# ITextSharp如何将矩形参数传递给方法以设置边框

C# ITextSharp如何将矩形参数传递给方法以设置边框,c#,itext,C#,Itext,下面是我在SO上找到的一个示例,用于将单元格添加到PdfPTable中,并将其外推到一个方法中,我创建了一个方法,用于设置除cell.Border的矩形值之外的所有参数。如何修复我的方法,以便传入所需的任何矩形值 矩形是从ITextSharp中的元素IELENT派生的对象 可能的矩形值为: 矩形。左边框,矩形。上边框,矩形。右边框,矩形。下边框,矩形。无边框 或可通过其数值访问: 下边框=2,左边框=4,无边框=0,右边框=8,上边框=1 示例:cell.Border=1 | 2 | 8;或ce

下面是我在SO上找到的一个示例,用于将单元格添加到PdfPTable中,并将其外推到一个方法中,我创建了一个方法,用于设置除cell.Border的矩形值之外的所有参数。如何修复我的方法,以便传入所需的任何矩形值

矩形是从ITextSharp中的元素IELENT派生的对象

可能的矩形值为:

矩形。左边框,矩形。上边框,矩形。右边框,矩形。下边框,矩形。无边框

或可通过其数值访问:

下边框=2,左边框=4,无边框=0,右边框=8,上边框=1

示例:cell.Border=1 | 2 | 8;或cell.Border=Rectangle.TOP_Border | Rectangle.RIGHT_Border

挂起我的是必须在值和单元格之间的“|”

方法如下:

 private static void addCell(PdfPTable table, string phrase, int colspan, int height, Font font)
 {
    PdfPCell cell = new PdfPCell(new Phrase(phrase, font));
    cell.Border = Rectangle.TOP_BORDER | Rectangle.BOTTOM_BORDER;  ** need to set param here ** 
    cell.BorderWidth = 1;
    cell.Colspan = colspan;
    cell.FixedHeight = height;
    table.AddCell(cell);
 }

我的问题的答案是将适当的值作为int传递到方法中。矩形值具有数值,调用将它们相加为一个数字,并传递给方法。这有一个特定的术语,但我现在想不起来

addCell(tableName, "MyPhrase", 1, 1, MyFont, Rectangle.BOTTOM_BORDER | Rectangle.RIGHT_BORDER;

private static void addCell(PdfPTable table, string phrase, int colspan, int height, Font font, int border)
{
   PdfPCell cell = new PdfPCell(new Phrase(phrase, font));
   cell.Border =  border;
   cell.BorderWidth = 1;
   cell.Colspan = colspan;
   cell.FixedHeight = height;
   table.AddCell(cell);
}
挂起我的是必须在值和单元格之间的“|”。边框将不接受字符串;-为什么or运算符应该接受字符串?你为什么期望它这样做?