如何引入具有背景色的圆形细胞? [英] How to introduce rounded cells with a background color?
问题描述
在此问题中,我已经看到如何为表格单元格设置圆角边框
I have seen how to set rounded borders for a table cell in this question
但是有可能使单元格没有边界,而是彩色和圆形的背景吗?
But is it possible to make cell that will have no borders, but colored and rounded background?
推荐答案
要实现此目的,您需要 calendar.pdf :
To achieve that, you need cell events. I've provided different examples in my book. See for instance calendar.pdf:
用于创建白细胞的Java代码如下:
The Java code to create the white cells looks like this:
class CellBackground implements PdfPCellEvent {
public void cellLayout(PdfPCell cell, Rectangle rect,
PdfContentByte[] canvas) {
PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
cb.roundRectangle(
rect.getLeft() + 1.5f, rect.getBottom() + 1.5f, rect.getWidth() - 3,
rect.getHeight() - 3, 4);
cb.setCMYKColorFill(0x00, 0x00, 0x00, 0x00);
cb.fill();
}
}
对于此代码的C#版本,请转到在哪里可以找到C#示例?,然后单击与示例的Java版本的章节相对应的章节.
For the C# version of this code, go to Where do I find the C# examples? and click on the chapter that corresponds with the chapter of the Java version of the example.
例如, PdfCalendar.cs :
class CellBackground : IPdfPCellEvent {
public void CellLayout(
PdfPCell cell, Rectangle rect, PdfContentByte[] canvas
) {
PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
cb.RoundRectangle(
rect.Left + 1.5f,
rect.Bottom + 1.5f,
rect.Width - 3,
rect.Height - 3, 4
);
cb.SetCMYKColorFill(0x00, 0x00, 0x00, 0x00);
cb.Fill();
}
}
您可以像这样使用此事件:
You can use this event like this:
CellBackground cellBackground = new CellBackground();
cell.CellEvent = cellBackground;
现在,将在单元格呈现到页面的那一刻执行CellLayout()
方法.
Now the CellLayout()
method will be executed the moment the cell is rendered to a page.
这篇关于如何引入具有背景色的圆形细胞?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!