zoukankan      html  css  js  c++  java
  • TX Textcontrol 使用总结四——打印

    使用内置的打印对话框
    在Text Control中只需一行代码就可以实现打印操作,通过调研 TextControl.Print 方法将打开一个打印对话框,用户可以设置打印机和其他打印参数。
    ==>
    textControl1.Print("My Print Job");


    用户自定义打印对话框
    缺省状态下的打印对话框会显示一些打印操作最常用的一些设置选项。如果 需要配置这些选项是否可用,比如:AllowPrintToFile选项、ShowHelp选项或者ShowNetrowk选项,可以通过 TextControl.Print()来实现。以下代码将会把AllowPrintToFile和AllowSomePages设置不可用
    ==>
    /// <summary>
    /// 实现打印功能
    /// </summary>
    /// <param name="txcontrol">TextControl txcontrol</param>
    public void PrintTxContent(TextControl txcontrol)
    {
    PrintDialog printDialog = new PrintDialog();
    PrintDocument doc = new PrintDocument();
    printDialog.Document = doc;
    printDialog.AllowSomePages = false;
    printDialog.AllowPrintToFile = false;
    printDialog.PrinterSettings.FromPage = 1;
    printDialog.PrinterSettings.ToPage = txcontrol.Pages;
    if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
    {
    txcontrol.Print(doc);
    }
    }


    直接打印
    打印操作时可以不给用户提供打印参数设置界面,而将打印参数设置给PrintDocument对象,然后传递给TextControl.Print方法
    ==>
    PrintDocument myPrintDocument = new PrintDocument();
    myPrintDocument.PrinterSettings.FromPage = 1;
    myPrintDocument.PrinterSettings.ToPage = txContent.Pages;
    txContent.Print(myPrintDocument);

     ==》

    /// <summary>
    /// 实现打印功能
    /// </summary>
    /// <param name="txcontrol">TextControl txcontrol</param>
    public bool PrintTxContent(TextControl txcontrol)
    {
    try
    {
    PrintDocument myPrintDocument = new PrintDocument();
    myPrintDocument.PrinterSettings.FromPage = 1;
    myPrintDocument.PrinterSettings.ToPage = txcontrol.Pages;
    txcontrol.Print(myPrintDocument);
    }
    catch
    {
    return false;
    }
    return true;
    }

    /// <summary>
    /// 实现打印功能
    /// </summary>
    /// <param name="txcontrol">TextControl txcontrol</param>
    public bool PrintPreViewTxContent(TextControl txcontrol)
    {
    try
    {
    PrintDocument myPrintDocument = new PrintDocument();
    myPrintDocument.PrinterSettings.FromPage = 1;
    myPrintDocument.PrinterSettings.ToPage = txcontrol.Pages;
    txcontrol.PrintPreview(myPrintDocument);
    }
    catch
    {
    return false;
    }
    return true;
    }

    博客内容主要用于日常学习记录,内容比较随意,如有问题,还需谅解!!!
  • 相关阅读:
    SOJ 2785_Binary Partitions
    Codeforces Round #328 (Div. 2)
    C++ fill 和memset
    SOJ 2749_The Fewest Coins
    Codeforces Round #327 (Div. 2)
    TYVJ P1013 找啊找啊找GF Label:动态规划
    TYVJ 1014 乘法游戏
    TYVJ 1011 NOIP 2008&&NOIP 2000 传纸条&&方格取数 Label:多线程dp
    错误集合
    TYVJ P1038/P1039 忠诚 标签:线段树
  • 原文地址:https://www.cnblogs.com/YYkun/p/5662454.html
Copyright © 2011-2022 走看看