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

上一篇:15个实用的CSS在线实例教程


下一篇:Spark SQL 小文件问题处理