C# FlowDocument中的数据表
我正在尝试使用要在打印机上打印的数据表创建flowdocument。我可以创建flowdocument和打印机之类的东西,但我不知道如何创建表 这是我的密码:C# FlowDocument中的数据表,c#,flowdocument,C#,Flowdocument,我正在尝试使用要在打印机上打印的数据表创建flowdocument。我可以创建flowdocument和打印机之类的东西,但我不知道如何创建表 这是我的密码: //Creating flow document Paragraph myParagraph = new Paragraph(); //Add content to the paragraph myParagraph.Inlines.Add(new Bold(new Run
//Creating flow document
Paragraph myParagraph = new Paragraph();
//Add content to the paragraph
myParagraph.Inlines.Add(new Bold(new Run("List of tasks (" + TasksToShow.Count + ")")));
//Create content of paragraph
DataTable myTable = new DataTable();
myTable.Columns.Add("Task ID", typeof(int));
myTable.Columns.Add("Task name", typeof(string));
foreach (Task task in TasksToShow)
{
myTable.Rows.Add(task.TaskID, task.TaskName);
}
//Adding content to the flow document
FlowDocument myFlowDocument = new FlowDocument();
myFlowDocument.Blocks.Add(myParagraph);
myFlowDocument.Blocks.Add(myTable); //This line fails :(
//Print the document
PrintDialog dialog = new PrintDialog();
if(dialog.ShowDialog() == true)
{
int margin = 5;
Size pageSize = new Size(dialog.PrintableAreaWidth - margin * 2, dialog.PrintableAreaHeight - margin * 2);
IDocumentPaginatorSource paginator = myFlowDocument;
paginator.DocumentPaginator.PageSize = pageSize;
dialog.PrintDocument(paginator.DocumentPaginator, "Flow print");
}
你可以这样做
// Create the parent FlowDocument...
flowDoc = new FlowDocument();
// Create the Table...
table1 = new Table();
// ...and add it to the FlowDocument Blocks collection.
flowDoc.Blocks.Add(table1);
// Set some global formatting properties for the table.
table1.CellSpacing = 10;
table1.Background = Brushes.White;
请再看一遍
之后,您可以根据需要更改此depnds…是您的链接真正帮助了我:D