MigraDoc table with rounded corners

一笑奈何 提交于 2020-01-15 03:40:10

问题


How can I set rounded corners for a table? I'm using c# and MigraDoc.

MigraDoc.DocumentObjectModel.Tables.Table myTable = section.AddTable();
myTable.Borders.Visible = true;
MigraDoc.DocumentObjectModel.Tables.Column myColumn = myTable.AddColumn();
MigraDoc.DocumentObjectModel.Tables.Row myRow = myTable.AddRow();
myRow[0].AddParagraph("Some text");

回答1:


PdfSharp can do it. Not sure about MigraDoc.

http://www.nudoq.org/#!/Packages/PDFsharp-MigraDoc-GDI/PdfSharp/XGraphicsPath/M/AddRoundedRectangle

http://www.nudoq.org/#!/Packages/PDFsharp-MigraDoc-GDI/PdfSharp/XGraphics/M/DrawRoundedRectangle




回答2:


MigraDoc table cells have a RoundedCorner property.
I do not have time now to create a fully functional sample, but AIUI you must add dummy rows at the top and at the bottom as well as dummy columns at the left and at the right to make room for the rounded corners. You have to set cell shading to see the effect of the rounded corners. And most likely those rounded corners will work with PDF only, not with RTF.

Code snippet that shows how to use the properties:

public static void SetRoundedCorners(Table table)
{
    int rowCount = table.Rows.Count;
    int colCount = table.Columns.Count;

    if (rowCount < 2 || colCount < 2)
        return;

    table.Rows[0].Cells[0].RoundedCorner = RoundedCorner.TopLeft;
    table.Rows[0].Cells[colCount - 1].RoundedCorner =  RoundedCorner.TopRight;
    table.Rows[rowCount - 1].Cells[colCount - 1].RoundedCorner =  RoundedCorner.BottomRight;
    table.Rows[rowCount - 1].Cells[0].RoundedCorner =  RoundedCorner.BottomLeft;
}


来源:https://stackoverflow.com/questions/24578421/migradoc-table-with-rounded-corners

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!