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.Drawing.Printing; using Gma.QrCodeNet.Encoding; namespace SiaSun.LMS.WPFClient.UC { /// /// ucBarCodePlanarControl.xaml 的交互逻辑 /// public partial class ucBarCodePlanarControl : UserControl { int intModuleSize = 4; string strHeader = "标题"; string strData=null; /// /// 显示标题 /// public string U_Header { get { return strHeader; } set { strHeader = value; this.txtHeader.Text = value; } } /// /// BarCode Data /// public string U_Data { get { return strData; } set { strData = value; this.qrImageControl.Text = strData; } } /// /// 构造函数 /// public ucBarCodePlanarControl() { InitializeComponent(); } /// /// 保存条码 /// public void U_SaveBarCode() { try { System.Windows.Forms.SaveFileDialog sdlg = new System.Windows.Forms.SaveFileDialog(); if (sdlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { QrEncoder qrEncoder = new QrEncoder(ErrorCorrectionLevel.H); QrCode qrCode = new QrCode(); qrEncoder.TryEncode(this.strData, out qrCode); Gma.QrCodeNet.Encoding.Windows.Controls.Renderer renderer = new Gma.QrCodeNet.Encoding.Windows.Controls.Renderer(intModuleSize, System.Drawing.Brushes.Black, System.Drawing.Brushes.White); renderer.CreateImageFile(qrCode.Matrix, sdlg.FileName, System.Drawing.Imaging.ImageFormat.Png); } } catch (Exception ex) { MainApp._MessageDialog.ShowException(ex); } } /// /// 打印条码 /// public void U_PrintBarCode(PrintDialog pt,List DataList) { foreach (string strData in DataList) { this.qrImageControl.Text = strData; pt.PrintVisual(this.qrImageControl, "打印二维码"); } } } }