简体   繁体   中英

MigraDoc table with rounded corners

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");

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM