0

点击打印预览:

private void PrintPreview_Click(object sender, EventArgs e)
{
    // Adding treeList Component and it's look and feel.
    PreviewPrintableComponent(treeList, treeList.LookAndFeel);
}

负责打印预览的代码:

void PreviewPrintableComponent(IPrintable component, UserLookAndFeel lookAndFeel)
{
    // Create a link that will print a control. 
    PrintableComponentLink link = new PrintableComponentLink()
    {
        PrintingSystemBase = new PrintingSystemBase(),
        Component = component,
        Landscape = true,
        PaperKind = PaperKind.A5,
        Margins = new Margins(20, 20, 20, 20)
    };

    // I believe somewhere here I need to do something about formatting in 
    // 'component' and 'lookAndFeel'. 


    // creating preview doc
    link.CreateDocument();

    // showing preview
    link.ShowRibbonPreview(lookAndFeel);
}

格式化我的 TreeList 的代码。此代码在编译时运行,因为它是在设计时生成的事件:

private void TreeList_NodeCellStyle(object sender, GetCustomNodeCellStyleEventArgs e)
{
    // "Number" is name of column in which color formatting is applied
    if (e.Column.FieldName == "Number")
    {
        // Changing color to red for negative value.
        if (Convert.ToInt32(e.Node.GetValue(e.Column.AbsoluteIndex)) < 0)
        {
            e.Appearance.ForeColor = Color.Red;
        }
    }
}

表单中的我的 TreeList打印预览时的我的 TreeList

4

1 回答 1

1

尝试将TreeListOptionsPrint.UsePrintStyles 属性设置为false以使用您在 NodeCellStyle 事件中指定的外观。

于 2020-04-09T13:38:23.967 回答