打印按钮异常问题

时间:2013-02-18 15:39:36

标签: c# wpf

我有一个c#程序,该程序调用一项服务,该服务将从Medicare获得患者的保险状态。 (由其他人写的服务)。我正在获取数据并按我的意愿显示它。有人告诉我要添加一个打印选项,但是在运行时这个消息有一个例外:

“PrintTicket提供程序无法将DEVMODE转换为PrintTicket。Win32错误:参数不正确。”

以下是打印部分的代码:也许您可以看到导致此错误的错误。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
using System.Reflection;
using System.Diagnostics;
using System.Threading;
using System.Windows.Xps;
using System.Printing;

namespace EligibilityCheck
{

    public partial class MainWindow
    {
        VM vm = null;
        public MainWindow()
        {
            InitializeComponent();
            vm = new VM();
            this.DataContext = vm;
        }

        private void DXWindow_Loaded(object sender, RoutedEventArgs e)
        {

        }

        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            Print();
        }

        private void Print()
        {
            PrintDialog PrintDialog = new PrintDialog();
            Nullable<Boolean> printClicked = PrintDialog.ShowDialog();

            if (printClicked == true)
            {
                VisualBrush VisualBrush = new VisualBrush(txtResult);
                VisualBrush.Stretch = Stretch.Uniform;
                VisualBrush.ViewboxUnits = BrushMappingMode.Absolute;
                VisualBrush.Viewbox = new Rect(5, 5, 700, 700);

                Rectangle rect = new Rectangle();
                rect.Fill = VisualBrush;
                rect.Arrange(new Rect(new Point(50, 50), new Point(900, 900) /*pageAreaSize*/));

                PrintDialog.PrintVisual(rect, Title);
            }

        }



    }
}

0 个答案:

没有答案