我有一个问题,我想在报告预览页面中向最终用户展示一种带有彩色背景的表格,当他/她决定品尝它时,因为我已经在纸张上打印了那个背景,然后才想删除背景和把它发送到打印机。某些背景已经打印在纸上了,我只是填写了一些空格(例如名称等) 如果我想删除第一个用户的背景,只是看到一些文本在纸上展开而且不是那么用户友好, 你有什么建议吗? 非常感谢 这是我用来显示打印预览的代码
DevExpress.XtraReports.UI.XtraReport report;
report = new Parvane_report();
report.Parameters[0].Value = "";
report.Parameters[1].Value = parvane.Registration_date;
report.Parameters[2].Value = parvane.Senf_number;
report.Parameters[3].Value = parvane.Contex;
report.Parameters[4].Value = parvane.Title;
report.Parameters[5].Value = "";
report.Parameters[6].Value = parvane.Name;
report.Parameters[7].Value = parvane.Family;
report.Parameters[8].Value = parvane.Sodor;
report.Parameters[9].Value = parvane.Tavalod;
report.Parameters[10].Value = parvane.Shenasname;
report.Parameters[11].Value =parvane.CodMeli;
report.Parameters[12].Value =parvane.Ostan;
report.Parameters[13].Value =parvane.Shahrestan;
report.Parameters[14].Value =parvane.Shahr;
report.Parameters[15].Value =parvane.Bakhsh;
report.Parameters[16].Value =parvane.Dehestan;
report.Parameters[17].Value =parvane.Rosta;
report.Parameters[18].Value =parvane.CodPosti;
report.Parameters[19].Value =parvane.Adress;
report.Parameters[20].Value =parvane.Codshaghel;
using (ReportPrintTool printTool = new ReportPrintTool(report))
{
// Invoke the Ribbon Print Preview form modally,
// and load the report document into it.
printTool.ShowRibbonPreviewDialog();
// Invoke the Ribbon Print Preview form
// with the specified look and feel setting.
// printTool.ShowRibbonPreview(UserLookAndFeel.Default);
}
但正如我所说,我想向最终用户展示背景预览,并在使用点击打印按钮时删除背景, 如果你知道我的problam的任何其他解决方案,请帮助我.. 我忘了说我正在使用C#
答案 0 :(得分:1)
使用XtraReport.Watermark
属性设置报告的背景。在打印之前,您需要将ReportPrintTool.PrintingSystem.Watermark.ImageTransparency
属性ReportPrintTool.PrintingSystem.Watermark.TextTransparency
属性设置为255并在打印后恢复该值。为此,您需要使用here所述的ICommandHandler
接口,处理PrintingSystemCommand.Print
命令和PrintingSystemCommand.PrintDirect
命令,并隐藏用户的PrintingSystemCommand.Watermark
命令。
这是一个例子:
public class PrintWithoutWatermarkCommandHandler : ICommandHandler
{
private readonly ReportPrintTool _reportPrintTool;
private bool _isExecuted;
public PrintWithoutWatermarkCommandHandler(ReportPrintTool reportPrintTool)
{
_reportPrintTool = reportPrintTool;
//Hide watermark command from users.
_reportPrintTool.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.Watermark, CommandVisibility.None);
}
public virtual void HandleCommand(PrintingSystemCommand command, object[] args, IPrintControl control, ref bool handled)
{
if (_isExecuted || !CanHandleCommand(command, control)) return;
var printingSystem = _reportPrintTool.PrintingSystem;
var watermark = printingSystem.Watermark;
var imageTransparency = watermark.ImageTransparency;
var textTransparency = watermark.TextTransparency;
//Hide watermark.
watermark.ImageTransparency = 255;
watermark.TextTransparency = 255;
if (command == PrintingSystemCommand.Print)
_reportPrintTool.PrintDialog();
else
try
{
_isExecuted = true;
printingSystem.ExecCommand(command);
}
finally
{
_isExecuted = false;
}
//Restore watermark.
watermark.ImageTransparency = imageTransparency;
watermark.TextTransparency = textTransparency;
handled = true;
}
public virtual bool CanHandleCommand(PrintingSystemCommand command, IPrintControl control)
{
return command == PrintingSystemCommand.Print || command == PrintingSystemCommand.PrintDirect;
}
}
现在您可以在代码中使用此命令处理程序:
report = new Parvane_report();
//Your code
//Add watermark here if you have not added it before.
using (ReportPrintTool printTool = new ReportPrintTool(report))
{
printTool.PrintingSystem.AddCommandHandler(new PrintWithoutWatermarkCommandHandler(printTool));
printTool.ShowRibbonPreviewDialog();
}
答案 1 :(得分:0)
这对我很有帮助。谢谢!打印文件后,我也遇到了水印消失的问题。在我的情况下,通过将XTRAREPORT的“ShowPrintMarginsWarning”设置为False来修复此问题。我得到了一个边距警告对话框,并以某种方式干扰了水印。
如果有人想要上面的C#代码的VB.NET代码,那么它就在下面。
Option Infer On
Imports DevExpress.XtraReports.UI
Public Class PrintWithoutWatermarkCommandHandler
Implements ICommandHandler
Private ReadOnly _reportPrintTool As ReportPrintTool
Private _isExecuted As Boolean
Public Sub New(ByVal reportPrintTool As ReportPrintTool)
_reportPrintTool = reportPrintTool
'Hide watermark command from users.
_reportPrintTool.PrintingSystem.SetCommandVisibility(PrintingSystemCommand.Watermark, CommandVisibility.None)
End Sub
Public Function ICommandHandler_CanHandleCommand(ByVal command As PrintingSystemCommand, ByVal printControl As IPrintControl) As Boolean Implements ICommandHandler.CanHandleCommand
Return command = PrintingSystemCommand.Print OrElse command = PrintingSystemCommand.PrintDirect
End Function
Public Sub ICommandHandler_HandleCommand(ByVal command As PrintingSystemCommand, ByVal args As Object(), ByVal printControl As IPrintControl,
ByRef handled As Boolean) Implements ICommandHandler.HandleCommand
If _isExecuted OrElse Not ICommandHandler_CanHandleCommand(command, printControl) Then
Return
End If
Dim printingSystem = _reportPrintTool.PrintingSystem
Dim watermark = printingSystem.Watermark
Dim imageTransparency = watermark.ImageTransparency
Dim textTransparency = watermark.TextTransparency
'Hide watermark.
watermark.ImageTransparency = 255
watermark.TextTransparency = 255
If command = PrintingSystemCommand.Print Then
_reportPrintTool.PrintDialog()
Else
Try
_isExecuted = True
printingSystem.ExecCommand(command)
Finally
_isExecuted = False
End Try
End If
'Restore watermark.
watermark.ImageTransparency = imageTransparency
watermark.TextTransparency = textTransparency
handled = True
End Sub
结束班