Example #1
5
 /// <summary>
 /// 打印信息的初始化
 /// </summary>
 /// <param datagrid="DataGridView">打印数据</param>
 /// <param PageS="int">纸张大小</param>
 /// <param lendscape="bool">是否横向打印</param>
 public PrintClass(DataGridView datagrid, int PageS, bool lendscape)
 {
     this.datagrid = datagrid;//获取打印数据
     this.PageSheet = PageS;//纸张大小
     printdocument = new PrintDocument();//实例化PrintDocument类
     pagesetupdialog = new PageSetupDialog();//实例化PageSetupDialog类
     pagesetupdialog.Document = printdocument;//获取当前页的设置
     printpreviewdialog = new PrintPreviewDialog();//实例化PrintPreviewDialog类
     printpreviewdialog.Document = printdocument;//获取预览文档的信息
     printpreviewdialog.FormBorderStyle = FormBorderStyle.Fixed3D;//设置窗体的边框样式
     //横向打印的设置
     if (PageSheet >= 0)
     {
         if (lendscape == true)
         {
             printdocument.DefaultPageSettings.Landscape = lendscape;//横向打印
         }
         else
         {
             printdocument.DefaultPageSettings.Landscape = lendscape;//纵向打印
         }
     }
     pagesetupdialog.Document = printdocument;
     printdocument.PrintPage += new PrintPageEventHandler(this.printdocument_printpage);//事件的重载
 }
Example #2
1
        public void NetworkPrint(LocalReport report, String inPrinterName)
        {
            try
            {
                string printerName = inPrinterName;

                Export(report);
                m_currentPageIndex = 0;

                PrintDocument printDoc = new PrintDocument();
                printDoc.PrinterSettings.PrinterName = printerName;

                if (!printDoc.PrinterSettings.IsValid)
                {
                    string msg = String.Format("Can't find printer \"{0}\".", printerName);
                    //MessageBox.Show(msg, "Print Error");
                    return;
                }
                printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
                printDoc.Print();
            }
            catch (Exception ee)
            {

            }
        }
        private static void method2(string filename, string printer)
        {
            Spire.Doc.Document doc = new Spire.Doc.Document();

            doc.LoadFromFile(filename);

            System.Drawing.Printing.PrintDocument printDoc = doc.PrintDocument;

            //get the page size
            SizeF sf = doc.Sections[0].PageSetup.PageSize;
            float wd = sf.Width;
            float ht = sf.Height;
            float a  = (S.PageSize.A4.Height - wd) / 2;
            float b  = (S.PageSize.A4.Width - ht) / 2;


            //set printing margins
            printDoc.OriginAtMargins = true;
            //printDoc.DefaultPageSettings.Margins = new System.Drawing.Printing.Margins((int)(a), (int)(a), (int)(b), (int)(b));
            printDoc.PrinterSettings.PrinterName   = printer;
            printDoc.PrinterSettings.Duplex        = Duplex.Horizontal;
            printDoc.DefaultPageSettings.PaperSize = new PaperSize("postcard", 600, 400);
            printDoc.PrintController = new StandardPrintController();
            printDoc.Print();
        }
        private static void method1(string filename, string printer)
        {
            Spire.Doc.Document doc = new Spire.Doc.Document();

            //Load word document
            doc.LoadFromFile(filename);

            //Printing with Custom paper
            SizeF sf = doc.Sections[0].PageSetup.PageSize;

            float wd = sf.Width;
            float ht = sf.Height;

            System.Drawing.Printing.PrintDocument printDoc = doc.PrintDocument;
            printDoc.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("custom", (int)wd / 72 * 100, (int)ht / 72 * 100);

            doc.PrintDocument.PrinterSettings.PrinterName = printer;

            if (doc.PrintDocument.PrinterSettings.CanDuplex)
            {
                //Setting Horizontal printing ;
                doc.PrintDocument.PrinterSettings.Duplex = Duplex.Horizontal;
            }

            System.Drawing.Printing.PrintController printController = new System.Drawing.Printing.StandardPrintController();
            printDoc.PrintController = printController;
            printDoc.Print();
        }
Example #5
0
 public VoucherPrintCore(Template template, TemplatePrintModelVoucher templatePrintModel)
 {
     try
     {
         this.template     = template;
         this.voucherModel = templatePrintModel;
         printDialog1      = new System.Windows.Forms.PrintDialog();
         printDocument1    = new System.Drawing.Printing.PrintDocument();
         printDocument1.PrinterSettings.PrinterName   = template.PrintSetting.PrintModule;
         printDocument1.DefaultPageSettings.PaperSize = new PaperSize("comaond", (int)(template.Background.ImageWidth / 2.54), (int)(template.Background.ImageHeight / 2.54));
         x = GetX(printDocument1.DefaultPageSettings.HardMarginX);
         y = GetY(printDocument1.DefaultPageSettings.HardMarginY);
         printDocument1.DefaultPageSettings.Margins.Left = 0;
         printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(printDocument1_PrintPage);
         if (templatePrintModel.SerialNumber != "")
         {
             startNum = templatePrintModel.SerialNumber.Substring(0, 16);
             endNum   = templatePrintModel.SerialNumber.Substring(17);
             PageNum  = Convert.ToInt32(endNum.Substring(10)) - Convert.ToInt32(startNum.Substring(10)) + 1;
         }
         //printDialog1.AllowSomePages = true;
         printDocument1.PrinterSettings.Collate = true;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Example #6
0
        /// <summary>
        /// 打印变量的基础定义.
        /// </summary>
        private void Init()
        {
            // 初始化 打印文档.
            printDocument1 = new PrintDocument();
            // 定义 打印文档的事件.
            printDocument1.BeginPrint += new System.Drawing.Printing.PrintEventHandler(this.BeginPrint);
            printDocument1.EndPrint   += new System.Drawing.Printing.PrintEventHandler(this.EndPrint);
            printDocument1.PrintPage  += new System.Drawing.Printing.PrintPageEventHandler(this.PrintPage);

            // 定义打印文档的附加信息.
            printDocument1.DocumentName = "打印测试";


            // 初始化 页面设置对话框.
            pageSetupDialog1          = new PageSetupDialog();
            pageSetupDialog1.Document = printDocument1;

            // 初始化 打印预览对话框.
            printPreviewDialog1          = new PrintPreviewDialog();
            printPreviewDialog1.Document = printDocument1;

            // 初始化 打印对话框.
            printDialog1          = new PrintDialog();
            printDialog1.Document = printDocument1;
        }
Example #7
0
        public daXuatExcel()
        {
            this.printDocument1 = new System.Drawing.Printing.PrintDocument();

            this.printDocument1.PrintPage  += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
            this.printDocument1.BeginPrint += new System.Drawing.Printing.PrintEventHandler(this.printDocument1_BeginPrint);
        }
Example #8
0
        private void PrintPreview()
        {
            try
            {
                m_PrintDocument             = new System.Drawing.Printing.PrintDocument();
                m_PrintDocument.BeginPrint += m_PrintDocument_BeginPrint;
                m_PrintDocument.PrintPage  += PrintDocument_PrintPage;
                m_PrintDocument.PrinterSettings.MaximumPage   = CurrentDocument.Count;
                m_PrintDocument.PrinterSettings.MinimumPage   = 1;
                m_PrintDocument.PrinterSettings.FromPage      = 1;
                m_PrintDocument.PrinterSettings.ToPage        = CurrentDocument.Count;
                m_PrintDocument.DefaultPageSettings.Landscape = CurrentPage.IsLandscape;

                m_PrintPageIndex = 0;                 // in case the user prints
                var dlgPreview = new PrintPreviewDialog
                {
                    Document = m_PrintDocument,
                    //AutoScrollMargin = new Size(0, 0),
                    //AutoScrollMinSize = new Size(0, 0),
                    ClientSize = new Size(400, 300),
                    //Enabled = true,
                    //UseAntiAlias = true
                };

                PrintMeasures = false;
                dlgPreview.ShowDialog();
            }
            finally
            {
                m_PrintDocument.Dispose();
                m_PrintDocument             = null;
                m_PrintDocument.BeginPrint += m_PrintDocument_BeginPrint;
                m_PrintDocument.PrintPage  += PrintDocument_PrintPage;
            }
        }
    protected void Page_Load(object sender, EventArgs e)
    {
        databaseaccesslayer dataobj = new databaseaccesslayer();

        if (!IsPostBack)
        {
            try
            {
                string    sql1 = @"select * from Application_Setting where User_Id=" + Session["Id"] + " and Appl_Id=56 and IsVaild=1";
                DataTable dt1  = dataobj.Selectdatatable(sql1);
                if (dt1.Rows.Count == 1)
                {
                    string sql  = @"select * from CustomerAndSupplier where Supplier=1";
                    string path = "Reports/ReportSupplier.rpt";
                    string sqls = sql;
                    System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
                    ReportDocument reportdocument = new ReportDocument();
                    reportdocument.Load(Server.MapPath(path));
                    reportdocument.DataSourceConnections[0].SetConnection(".", "ERPsystem", true);
                    reportdocument.SetDataSource(dataobj.Selectdatatable(sqls));
                    reportdocument.SetParameterValue("@Type", true);
                    CrystalReportViewer1.ReportSource = reportdocument;
                }
                else
                {
                    Response.Redirect("MainPage.aspx");
                }
            }
            catch (Exception)
            {
                Response.Redirect("MainPage.aspx");
            }
        }
    }
Example #10
0
        protected override void PrintPreview(ToolStripButton sender)
        {
            LoadPrintSetting();

            this.reoGridControl1.CurrentWorksheet.ResetAllPageBreaks();

            this.reoGridControl1.CurrentWorksheet.PrintableRange = new unvell.ReoGrid.RangePosition(0, 0, this.reoGridControl1.CurrentWorksheet.RowCount, this.reoGridControl1.CurrentWorksheet.ColumnCount);

            using (var session = this.reoGridControl1.CurrentWorksheet.CreatePrintSession())
            {
                using (System.Drawing.Printing.PrintDocument doc = session.PrintDocument)
                {
                    PageSettings ps = Miles.Coro.Common.Print.PrintConfigManager.GetPageSettings(this.GetType().FullName);
                    doc.DefaultPageSettings         = ps;
                    doc.PrinterSettings.PrinterName = ps.PrinterSettings.PrinterName;
                    //打印预览
                    using (PrintPreviewDialog ppd = new PrintPreviewDialog())
                    {
                        ppd.StartPosition = FormStartPosition.CenterScreen;
                        ppd.WindowState   = FormWindowState.Maximized;
                        ppd.SetBounds(0, 0, 1024, 768);
                        ppd.Document = doc;
                        ppd.PrintPreviewControl.Zoom = 1.5d;
                        ppd.ShowDialog();
                    }
                }
            }
        }
Example #11
0
        public void printDataTable(DataTable dt, PrintInfo p)
        {
            this.printDt = dt;
            this.pInfo   = p;
            PrintDocument   pd  = new System.Drawing.Printing.PrintDocument();
            PrinterSettings pss = new System.Drawing.Printing.PrinterSettings();

            pss.DefaultPageSettings.Landscape = pInfo.landscape;
            pd.PrinterSettings = pss;

            pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);

            PrintDialog ppd = new PrintDialog();

            ppd.Document = pd;
            if (printDt == null)
            {
                MessageBox.Show("出错", "没有可以打印的数据", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (ppd.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    pd.Print();
                }
                catch (Exception ex)
                {
                    MessageBox.Show("出错", ex.Message, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Example #12
0
        public static void showInvoiceDialog(IWin32Window target, long tranId)
        {
            try
            {
                printTranID = tranId;
                System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
                int neededWidth = 600, height = 800;
                pDoc.DefaultPageSettings.Margins          = new Margins(0, 0, 0, 0);
                pDoc.DefaultPageSettings.PaperSize        = new PaperSize("Custom", neededWidth, height);
                pDoc.DefaultPageSettings.PaperSize.Height = height;
                pDoc.DefaultPageSettings.PaperSize.Width  = neededWidth;

                pDoc.PrintPage += PDoc_PrintPage;

                //PrintDialog printDialog = new PrintDialog();
                //printDialog.Document = pDoc;

                PrintPreviewDialog ppDialog = new PrintPreviewDialog();
                ppDialog.FindForm().WindowState = FormWindowState.Maximized;
                ppDialog.Document = pDoc;

                if (ppDialog.ShowDialog(target) == DialogResult.OK)
                {
                    pDoc.Print();
                }

                //new forms.frmInvoice(tranId).ShowDialog(target);
            }
            catch (Exception ex)
            {
                MessageBox.Show(target, "Sorry, error occured please try again after setting default printer in your Printers Setttings." + Environment.NewLine + "Error message : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #13
0
        private void fmPrintMap_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (m_bShowPrintDialog)
            {
                System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
                pd.PrinterSettings.PrinterName = cboPrinters.SelectedItem.ToString();

                System.Drawing.Printing.PaperSize pkSize = new System.Drawing.Printing.PaperSize();

                //bool bPaperSizeAllowed = false;
                //string sPaperSizes = "";

                //for (int i = 0; i < pd.PrinterSettings.PaperSizes.Count; i++)
                //{
                //    //System.Windows.Forms.MessageBox.Show(pd.PrinterSettings.PaperSizes[i].PaperName.ToString());
                //    if (pd.PrinterSettings.PaperSizes[i].PaperName.Contains(this.cboMapSize.SelectedItem.ToString()))
                //    {
                //        bPaperSizeAllowed = true;
                //        //break;

                //    }
                //}

                if (System.Windows.Forms.MessageBox.Show("Would you like to print this map now?", "Medford Print Map", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    object missing = Type.Missing;
                    //if (bPaperSizeAllowed)
                    showPrintDialog(cboPrinters.SelectedItem.ToString()); //this.App.ShowDialog((int)esriMxDlgIDs.esriMxDlgPrintSetup, ref missing);    //
                    //else
                    //    this.App.ShowDialog((int)esriMxDlgIDs.esriMxDlgPageSetup,ref missing);    //showPageSettingDialog(cboPrinters.SelectedItem.ToString());
                }
                //System.Windows.Forms.MessageBox.Show(sPaperSizes);
            }
        }
        private void btnPrint_Click(object sender, EventArgs e)
        {
            pullSchematics();
            pageCount = 0;
            System.Drawing.Printing.PrintDocument doc = new System.Drawing.Printing.PrintDocument();
            doc.PrintPage     += new System.Drawing.Printing.PrintPageEventHandler(CaptureScreen);
            prtDialog.Document = doc;
            DialogResult result = prtDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    doc.DefaultPageSettings.Landscape = false;
                    doc.Print();
                }
                catch (Exception E)
                {
                    MessageBox.Show(E.Message);
                }
            }
            tbMethodInfo.SelectedIndex = 0;
            pnlInitControls.Visible    = true;

            DialogResult dr = MessageBox.Show("New comm-code?", "Printing Complete", MessageBoxButtons.YesNo);

            if (dr == DialogResult.Yes)
            {
                btnClear_Click(this, EventArgs.Empty);
                txtCode.Focus();
            }
        }
Example #15
0
 ///<summary></summary>
 public void PrintReport()
 {
     pd2            = new PrintDocument();
     pd2.PrintPage += new PrintPageEventHandler(this.pd2_PrintPage);
     pd2.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
     pd2.OriginAtMargins             = true;
     if (!PrefB.GetBool("RxOrientVert"))
     {
         pd2.DefaultPageSettings.Landscape = true;
     }
                 #if DEBUG
     pView.printPreviewControl2.Document = pd2;
     pView.ShowDialog();
                 #else
     if (!Printers.SetPrinter(pd2, PrintSituation.Rx))
     {
         return;
     }
     try{
         pd2.Print();
     }
     catch {
         MessageBox.Show(Lan.g(this, "Printer not available"));
     }
                 #endif
 }
    private void toolStripButtonPageSetup_Click(object sender, EventArgs e)
    {
        PageSetupDialog pageSetupDialog = new PageSetupDialog();

        pageSetupDialog.AllowOrientation = false;
        pageSetupDialog.EnableMetric     = true;

        pageSetupDialog.PageSettings = printPreviewControl.Document.DefaultPageSettings;

        pageSetupDialog.Document = printPreviewControl.Document;

        if (pageSetupDialog.ShowDialog() == DialogResult.OK)
        {
            System.Drawing.Printing.PrintDocument printDocument = printPreviewControl.Document;

            printPreviewControl.Dispose();
            printPreviewControl = null;

            printPreviewControl = new PrintPreviewControl();
            Controls.Add(printPreviewControl);

            printPreviewControl.Dock         = System.Windows.Forms.DockStyle.Fill;
            printPreviewControl.Location     = new System.Drawing.Point(0, 25);
            printPreviewControl.UseAntiAlias = true;
            printPreviewControl.BringToFront();

            printPreviewControl.Document = printDocument;
        }
        ;
    }
Example #17
0
        /**/
        ///// <summary>
        ///// 判断表单是否在指定的打印机所支持的纸张列表中,表单就是我们平常所说的纸张
        ///// </summary>
        ///// <param name="PrinterName">打印机名称</param>
        ///// <param name="PaperName">纸张名称</param>
        ///// <returns>是:在;否:不在</returns>
        public static bool FormInPrinter(string PrinterName, string PaperName)
        {
            bool bolRet = false;

            System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();

            pd.PrinterSettings.PrinterName = PrinterName;

            foreach (System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes)
            {
                if (ps.PaperName == PaperName)
                {
                    bolRet = true;
                    break;
                }
            }

            pd.Dispose();

            return(bolRet);
        }

        #endregion 判断表单是否在指定的打印机所支持的纸张列表中
        #region 判断指定纸张的宽度和高度和与打印内容指定的宽度和高度是否匹配
        /**/
        /// <summary>
        /// 判断指定纸张的宽度和高度和与打印内容指定的宽度和高度是否匹配
        /// </summary>
        /// <param name="PrinterName">打印机名称</param>
        /// <param name="FormName">表单名称</param>
        /// <param name="Width">宽度</param>
        /// <param name="Height">高度</param>
        /// <returns></returns>
        public static bool FormSameSize(string PrinterName, string FormName, decimal Width, decimal Height)
        {
            bool bolRet = false;

            System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();

            pd.PrinterSettings.PrinterName = PrinterName;

            foreach (System.Drawing.Printing.PaperSize ps in pd.PrinterSettings.PaperSizes)
            {
                if (ps.PaperName == FormName)
                {
                    decimal decWidth  = FromInchToCM(System.Convert.ToDecimal(ps.Width));
                    decimal decHeight = FromInchToCM(System.Convert.ToDecimal(ps.Height));
                    //只要整数位相同即认为是同一纸张,毕竟inch到cm的转换并不能整除
                    if (Math.Round(decWidth, 0) == Math.Round(Width, 0) && Math.Round(decHeight, 0) == Math.Round(Height, 0))
                    {
                        bolRet = true;
                    }
                    break;
                }
            }

            pd.Dispose();

            return(bolRet);
        }
Example #18
0
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            if (drpName.SelectedIndex > 0)
            {
                div.Visible = true;
                string sql = @"ReportTranTreasure " + drpName.SelectedItem.Value + ",'" + DateTime.Parse(txtDateFrom.Text) + "','" + DateTime.Parse(txtDateTo.Text) + "'";
                System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
                ReportDocument reportdocument = new ReportDocument();
                reportdocument.Load(Server.MapPath("Reports/ReportTranTreasure.rpt"));

                reportdocument.DataSourceConnections[0].SetConnection(".", "ERPsystem", true);
                reportdocument.SetDataSource(dataobj.Selectdatatable(sql));
                reportdocument.SetParameterValue("@userId", drpName.SelectedItem.Value);
                reportdocument.SetParameterValue("@datefrom", DateTime.Parse(txtDateFrom.Text));
                reportdocument.SetParameterValue("@dateto", DateTime.Parse(txtDateTo.Text));
                CrystalReportViewer1.ReportSource = reportdocument;
                //reportdocument.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
                //reportdocument.PrintToPrinter(1, true, 1, 100);
            }
        }
        catch (Exception ex)
        {
            dataobj.Alert(ex.Message, this);
        }
    }
Example #19
0
        public override void OnStartPrint(PrintDocument document, PrintEventArgs e) {
            Debug.Assert(dc == null && graphics == null, "PrintController methods called in the wrong order?");

            // For security purposes, don't assume our public methods methods are called in any particular order
            CheckSecurity();

            base.OnStartPrint(document, e);

            
            try {
                
                if (!document.PrinterSettings.IsValid)
                throw new InvalidPrinterException(document.PrinterSettings);

                IntSecurity.AllPrintingAndUnmanagedCode.Assert();
                
                // We need a DC as a reference; we don't actually draw on it.
                // We make sure to reuse the same one to improve performance.
                dc = document.PrinterSettings.CreateInformationContext(modeHandle);
            }
            finally {
                CodeAccessPermission.RevertAssert();
            }
            
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="AllLetters">HTML text (could be several pages)</param>
        /// <param name="APathForImagesBase">Could be null if I'm not printing images!</param>
        public void PreviewOrPrint(String AllLetters, String APathForImagesBase)
        {
            System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
            bool printerInstalled = printDocument.PrinterSettings.IsValid;

            if (!printerInstalled)
            {
                MessageBox.Show(Catalog.GetString("There is no printer, so printing is not possible"));
                return;
            }

            FGfxPrinter = new TGfxPrinter(printDocument, TGfxPrinter.ePrinterBehaviour.eFormLetter);
            try
            {
                TPrinterHtml htmlPrinter = new TPrinterHtml(AllLetters,
                    APathForImagesBase,
                    FGfxPrinter);
                FGfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea);
                this.ppvLetters.InvalidatePreview();
                this.ppvLetters.Document = FGfxPrinter.Document;
                this.ppvLetters.Zoom = 1;
                FGfxPrinter.Document.EndPrint += new PrintEventHandler(this.EndPrint);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// Handles the Click event of the Print button
        /// </summary>
        /// <param name="sender">Object that fired the event</param>
        /// <param name="e">.NET supplied event parameters</param>
        private void btnPrint_Click(object sender, EventArgs e)
        {
            System.Drawing.Printing.PrintDocument docToPrint = new System.Drawing.Printing.PrintDocument();
            docToPrint.PrintPage += new PrintPageEventHandler(docToPrint_PrintPage);
            PrintDialog dialog = new PrintDialog();

            dialog.AllowSelection = true;
            dialog.Document       = docToPrint;
            DialogResult result = dialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                try
                {
                    docToPrint.Print();
                }
                catch (Win32Exception ex)
                {
                    MsgBox.Show(ex.Message, SharedStrings.MAKE_VIEW);
                }

                catch (Exception ex)
                {
                    MsgBox.ShowException(ex);
                }
            }
        }
Example #22
0
 public Frm_PreSave(string customerNo)
 {
     InitializeComponent();
     this.CustomerNo = customerNo;
     Print = new Print();
     printDocument = new PrintDocument();
 }
Example #23
0
 public void printTicket()
 {
     PrintDocument pd = new PrintDocument();
     pd.PrintController = new StandardPrintController();
     pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
     pd.Print();
 }
Example #24
0
 private void bPay_Click(object sender, EventArgs e)
 {
     DB.Instance.Insert("order", new Parameter("customer_id", cid), new Parameter("dt", DateTime.Now), new Parameter("status", OrderStatus.New));
     uint oid = 0;
     using (MySqlDataReader reader = DB.Instance.SelectReader("select max(id) from order"))
     {
         if(reader != null && reader.Read()){
             oid = reader.GetUInt32(0);
         }
     }
     foreach (var item in Role.Instance.ShopCart)
     {
         DB.Instance.Insert("order_inventory", new Parameter("order_id", oid), new Parameter("inventory_id", item.ID), new Parameter("amount", item.Qty));
     }
     var dr = MessageBox.Show("Order Placed. Would you like to pay now?", "Payment", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
     if (dr == DialogResult.Yes)
     {
         new Payment().ShowDialog();
     }
     else if(dr == DialogResult.No)
     {
         var ppd = new PrintPreviewDialog();
         PrintDocument pd = new PrintDocument();
         ppd.Document = pd;
         pd.PrintPage += Pd_PrintPage;
         ppd.ShowDialog();
     }
 }
Example #25
0
        public override void OnStartPrint(PrintDocument document, PrintEventArgs e) {
            Debug.Assert(dc == null && graphics == null, "PrintController methods called in the wrong order?");

            // For security purposes, don't assume our public methods methods are called in any particular order
            CheckSecurity(document);

            base.OnStartPrint(document, e);
            // the win32 methods below SuppressUnmanagedCodeAttributes so assertin on UnmanagedCodePermission is redundant
            if (!document.PrinterSettings.IsValid)
                throw new InvalidPrinterException(document.PrinterSettings);

            dc = document.PrinterSettings.CreateDeviceContext(modeHandle);
            SafeNativeMethods.DOCINFO info = new SafeNativeMethods.DOCINFO();
            info.lpszDocName = document.DocumentName;
            if (document.PrinterSettings.PrintToFile)
                info.lpszOutput = document.PrinterSettings.OutputPort; //This will be "FILE:"
            else
                info.lpszOutput = null;
            info.lpszDatatype = null;
            info.fwType = 0;

            int result = SafeNativeMethods.StartDoc(new HandleRef(this.dc, dc.Hdc), info);
            if (result <= 0) {
                int error = Marshal.GetLastWin32Error();
                if (error == SafeNativeMethods.ERROR_CANCELLED) {
                    e.Cancel = true;
                }
                else {
                    throw new Win32Exception(error);
                }
            }
        }
Example #26
0
        private void axWindowsMediaPlayer1_PlayStateChange(object sender, _WMPOCXEvents_PlayStateChangeEvent e)
        {
            //QUANDO VIDEO FOR PARADO
            if (  axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsPaused )
            {
                //O VIDEO FOI PARADO, PARA CONTINUAR PRECISA CLICAR EM OK
                if ( MessageBox.Show("Video Parado. Clique aqui para continuar!", "",
                    MessageBoxButtons.OK , MessageBoxIcon.Information) == DialogResult.OK )
                {
                    axWindowsMediaPlayer1.Ctlcontrols.play();
                }
            }

            //QUANDO O VIDEO ACABAR
            if (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
            {
                //IMPRIME
                PrintDocument document = new PrintDocument();
                document.PrintPage += new PrintPageEventHandler(impressaoConf);
                document.Print();

                this.Hide();

            }
        }
        public static void Imprimir(Entidades.Álbum.Álbum álbum, ItensImpressão itens)
        {
            using (PrintDocument documento = new PrintDocument())
            {
                documento.DocumentName = "Álbum " + álbum.Nome;

                using (PrintDialog dlg = new PrintDialog())
                {
                    dlg.AllowCurrentPage = false;
                    dlg.AllowSelection = false;
                    dlg.AllowSomePages = true;
                    dlg.UseEXDialog = true;
                    dlg.Document = documento;

                    if (dlg.ShowDialog() == DialogResult.OK)
                    {
                        ControleImpressão ctrl = new ControleImpressão(álbum, itens);

                        ctrl.página = new Página(
                                documento.PrinterSettings.DefaultPageSettings.PrintableArea.Width / 100f,
                                documento.PrinterSettings.DefaultPageSettings.PrintableArea.Height / 100f,
                                4, 5);
            
                        ctrl.daPágina = dlg.PrinterSettings.FromPage;
                        ctrl.atéPágina = dlg.PrinterSettings.ToPage != 0 ?
                            dlg.PrinterSettings.ToPage : int.MaxValue;

                        documento.PrintPage += new PrintPageEventHandler(ctrl.ImprimirPágina);
                        documento.Print();
                    }
                }
            }
        }
Example #28
0
 private void button1_Click(object sender, EventArgs e)
 {
     PrintDocument pd = new PrintDocument();
         pd.PrintPage += PrintPage;
         pd.Print();
         this.Close();
 }
Example #29
0
        public void print1(string printerName, string filePath)
        {
            // string dataDir = RunExamples.GetDataDir_AsposePdfFacades_Printing();
            // Create PdfViewer object
            PdfViewer viewer = new PdfViewer();

            // Open input PDF file
            viewer.BindPdf(filePath);
            // Set attributes for printing
            viewer.AutoResize      = true;    // Print the file with adjusted size
            viewer.AutoRotate      = true;    // Print the file with adjusted rotation
            viewer.PrintPageDialog = false;   // Do not produce the page number dialog when printing
            // Create objects for printer and page settings and PrintDocument
            System.Drawing.Printing.PrinterSettings ps     = new System.Drawing.Printing.PrinterSettings();
            System.Drawing.Printing.PageSettings    pgs    = new System.Drawing.Printing.PageSettings();
            System.Drawing.Printing.PrintDocument   prtdoc = new System.Drawing.Printing.PrintDocument();
            // Set printer name
            ps.PrinterName = prtdoc.PrinterSettings.PrinterName;
            // Set PageSize (if required)
            pgs.PaperSize = new System.Drawing.Printing.PaperSize("Custom", 280, 826);
            // Set PageMargins (if required)
            pgs.Margins = new System.Drawing.Printing.Margins(0, 0, 0, 0);
            // ExStart:PrintDialog
            //System.Windows.Forms.PrintDialog printDialog = new System.Windows.Forms.PrintDialog();
            //if (printDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            //{
            // Document printing code goes here
            // Print document using printer and page settings
            viewer.PrintDocumentWithSettings(pgs, ps);
            //}
            // ExEnd:PrintDialog
            // Close the PDF file after priting
            viewer.Close();
        }
        public static void PrintImage(string argstrImageFile, string argstrPrinterSelected)
        {
            if (System.IO.File.Exists(argstrImageFile))
            {
                string strPrinterSelected = GetDefaultPrinter();
                if (strPrinterSelected == "")
                {
                    string strTemp = ConfigRoutines.GetSetting("DefaultPrinter");
                    strDefaultPrinter = strTemp == "" ? strDefaultPrinter : ConfigRoutines.GetSetting("DefaultPrinter");
                    strPrinterSelected = argstrPrinterSelected == "" ? strDefaultPrinter : argstrPrinterSelected;
                }
                PrintDocument objPrintDocument = new PrintDocument();
                objPrintDocument.PrintPage += new PrintPageEventHandler(objPrintDocument_PrintPage);
                objBitmap = new Bitmap(argstrImageFile);

                // print the file
                try
                {
                    objPrintDocument.PrinterSettings.PrinterName = strPrinterSelected;
                    //if (!bolPrintAsIs)
                    //{
                    //    Margins objMargins = new Margins(150, 20, 20, 20);
                    //    objPrintDocument.DefaultPageSettings.Margins = objMargins;
                    //}
                    objPrintDocument.Print();
                }
                catch (Exception ex)
                {
                    CommonRoutines.Log(ex.Message);
                }
            }
        }
        public PrintOptionsDialog(PlanExportSettings pto, PrintDocument doc)
        {
            InitializeComponent();

            int index;
            string curPrinter = doc.PrinterSettings.PrinterName;

            m_pto = pto;

            foreach (String printer in PrinterSettings.InstalledPrinters)
            {
                index = comboPrinters.Items.Add(printer);

                doc.PrinterSettings.PrinterName = printer;
                if (doc.PrinterSettings.IsDefaultPrinter)
                    comboPrinters.SelectedIndex = index;
            }

            // If this dialog is cancelled, we dont want the name of the printer to have changed
            doc.PrinterSettings.PrinterName = curPrinter;

            EntryFinishDate = pto.EntryFinishDate;
            EntryNumber = pto.EntryNumber;
            EntryStartDate = pto.EntryStartDate;
            EntryTrainingTimes = pto.EntryTrainingTimes;
            EntryNotes = pto.EntryNotes;
            FooterCount = pto.FooterCount;
            FooterDate = pto.FooterDate;
            FooterTotalTime = pto.FooterTotalTime;
            IncludeHeader = pto.IncludeHeader;
        }
Example #32
0
    public bool Print(string Text, string FontFamilyName, float FontSize, string printerName)
    {
        try
        {
            PrinterName = printerName;
            if (!GetPrinterStatus(printerName))
            {
                throw new ArgumentException("Printer " + printerName + " is currently offline.", "original");
            }

            printingText     = Text;
            printingText     = printingText.Replace(Environment.NewLine, "<n>");
            printFontDefault = new System.Drawing.Font(FontFamilyName, FontSize);

            System.Drawing.Printing.PrintDocument pd = new System.Drawing.Printing.PrintDocument();
            pd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(pd_PrintPage);
            if (PrinterName != "")
            {
                pd.PrinterSettings.PrinterName = PrinterName;
            }

            pd.Print();
            pd.Dispose();
        }
        catch
        {
            Debug.LogWarning("Cannot Print!");
            return(false);
        }

        return(true);
    }
Example #33
0
        public void PrintTokens(List<TokenPrint> tokens, Form parentDialog, string PrinterName, bool showPrintPreview)
        {
            _tokensToPrint = tokens;
            _pageCounter = 0;
            //bool showPrintPreview = true;
            PrintDocument pd = new PrintDocument();
            PrintDocument pd1 = new PrintDocument();

            pd.DefaultPageSettings.PaperSize = paperSize;
            pd.PrintPage += printDoc_PrintPage;
            pd.PrinterSettings.PrinterName = PrinterName;

            //ToDo: can remove preview in the actual production.
            if (showPrintPreview)
            {
                var ppDlg = new PrintPreviewDialog();
                ppDlg.SetBounds(30, 30, 1024, 500);
                ppDlg.PrintPreviewControl.AutoZoom = true;
                ppDlg.PrintPreviewControl.Zoom = 0.75;
                ppDlg.Document = pd;
                var dr = ppDlg.ShowDialog(parentDialog);
            }
            else
            {
                pd.Print();
            }
        }
Example #34
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         try
         {
             string    sql1 = @"select * from Application_Setting where User_Id=" + Session["Id"] + " and Appl_Id=54 and IsVaild=1";
             DataTable dt1  = dataobj.Selectdatatable(sql1);
             if (dt1.Rows.Count == 1)
             {
                 string sql = @"TreasureReport";
                 System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
                 ReportDocument reportdocument = new ReportDocument();
                 reportdocument.Load(Server.MapPath("Reports/ReportTreasure.rpt"));
                 reportdocument.DataSourceConnections[0].SetConnection(".", "ERPsystem", true);
                 reportdocument.SetDataSource(dataobj.Selectdatatable(sql));
                 CrystalReportViewer1.ReportSource = reportdocument;
                 //reportdocument.PrintOptions.PrinterName = printDocument.PrinterSettings.PrinterName;
                 //reportdocument.PrintToPrinter(1, true, 1, 100);
                 //Response.Redirect("MainReportTreasure.aspx");
             }
             else
             {
                 Response.Redirect("MainPage.aspx");
             }
         }
         catch (Exception)
         {
             Response.Redirect("MainPage.aspx");
         }
     }
 }
Example #35
0
		private void butPrint_Click(object sender,EventArgs e) {
			PrintDocument pd2=new PrintDocument();
			pd2.PrintPage+=new PrintPageEventHandler(this.pd2_PrintPage);
			pd2.OriginAtMargins=true;
			pd2.DefaultPageSettings.Margins=new Margins(0,0,0,0);
			pd2.Print();
		}
Example #36
0
        public override void Execute()
        {
            printDocument = new PrintDocument();

              printDocument.OriginAtMargins = true;
              printDocument.BeginPrint += new PrintEventHandler(printDocument_BeginPrint);
              printDocument.PrintPage += new PrintPageEventHandler(printDocument_PrintPage);

              Dictionary<String, Object> paperSettings = Printing.getPaperSettings(grtArguments);
              printDocument.DefaultPageSettings.Landscape = (string)paperSettings["orientation"] == "landscape";

              // Sizes must be given in inch * 100 (sigh).
              int paperWidth = (int)Math.Round((double)paperSettings["width"] / 0.254);
              int paperHeight = (int)Math.Round((double)paperSettings["height"] / 0.254);
              PaperSize paperSize = new PaperSize("Doesn't matter", paperWidth, paperHeight);
              printDocument.DefaultPageSettings.PaperSize = paperSize;

              if ((bool)paperSettings["marginsSet"])
            printDocument.DefaultPageSettings.Margins =
              new Margins((int)paperSettings["marginLeft"], (int)paperSettings["marginRight"],
            (int)paperSettings["marginTop"], (int)paperSettings["marginBottom"]);

              printDialog = new System.Windows.Forms.PrintDialog();
              printDialog.Document = printDocument;
              printDialog.AllowPrintToFile = true;

              pageNumber = 0;
              pageCount = -1;

              if (printDialog.ShowDialog() == DialogResult.OK)
              {
            printDocument.Print();
              }
        }
Example #37
0
 private void InitializeComponent()
 {
     this.printDocument1 = new System.Drawing.Printing.PrintDocument();
     //
     //Main DataSet Initialization
     //
     this.printPreviewDialog1 = new PrintPreviewDialog();
     this.maindataset = new SupremeTransport.maindataset();
     //
     //Table Adapter Initialization
     //
     this.mainbillTableAdapter = new SupremeTransport.maindatasetTableAdapters.mainbillTableAdapter();
     this.billTableAdapter = new SupremeTransport.maindatasetTableAdapters.billTableAdapter();
     // 
     // printDocument1
     // 
     this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument1_PrintPage);
     // 
     // printPreviewDialog1
     // 
     this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
     this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
     this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
     this.printPreviewDialog1.Enabled = true;
     this.printPreviewDialog1.Name = "printPreviewDialog1";
     this.printPreviewDialog1.Visible = false;
 }
Example #38
0
 public override void OnEndPage(
     PrintDocument document,
     PrintPageEventArgs e
     )
 {
     this.OriginController.OnEndPage(document, e);
 }
Example #39
0
 public static void PrintOrder()
 {
     var doc = new PrintDocument();
     doc.PrinterSettings.PrinterName = System.Configuration.ConfigurationManager.AppSettings["PrinterName"];
     doc.PrintPage += new PrintPageEventHandler(PrintPage);
     doc.Print();
 }
Example #40
0
        private void print()
        {
            try
            {
                PrintDocument pdPrint = new PrintDocument();

                pdPrint.PrinterSettings.PrinterName = PRINTER_NAME;
                pdPrint.PrintPage += new PrintPageEventHandler(pdPrint_PrintPage);
                pdPrint.PrinterSettings.PrinterName = PRINTER_NAME;

                // Open a printer status monitor for the selected printer.

                if (pdPrint.PrinterSettings.IsValid)
                {
                    pdPrint.DocumentName = "Print";

                    // Start printing.
                    pdPrint.Print();
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <include file='doc\PrintControllerWithStatusDialog.uex' path='docs/doc[@for="PrintControllerWithStatusDialog.OnStartPrint"]/*' />
        /// <internalonly/>
        /// <devdoc>
        ///    <para>
        ///       Implements StartPrint by delegating to the underlying controller.
        ///    </para>
        /// </devdoc>
        public override void OnStartPrint(PrintDocument document, PrintEventArgs e) {
            base.OnStartPrint(document, e);

            this.document = document;
            pageNumber = 1;

            if (SystemInformation.UserInteractive) {
                backgroundThread = new BackgroundThread(this); // starts running & shows dialog automatically
            }

            // OnStartPrint does the security check... lots of 
            // extra setup to make sure that we tear down
            // correctly...
            //
            try {
                underlyingController.OnStartPrint(document, e);
            }
            catch {
                if (backgroundThread != null) {
                    backgroundThread.Stop();
                }
                throw;
            }
            finally {
                if (backgroundThread != null && backgroundThread.canceled) {
                    e.Cancel = true;
                }
            }
        }
Example #42
0
        private void firstDate_ValueChanged(object sender, EventArgs e)
        {
            NewVipAvtoSet.ProtocolsRow[] rows = _set.GetProtocolsBetweenDates(firstDate.Value, secondDate.Value);

            _document = new PrintJournalDocument(rows, firstDate.Value, secondDate.Value, _set);
            printPreviewControl1.Document = _document;
        }
Example #43
0
        public bool printImage(string[] imagePaths)
        {
            // Get desired image width
            int desiredImageWidth;
            if (imagePaths.Count() == 1)
            {
                desiredImageWidth = (A4_WIDTH - (gap + 2 * A4_BORDER_WIDTH));
            }
            else
            {
               desiredImageWidth = (A4_WIDTH - ((gap + 2 * A4_BORDER_WIDTH) / 2));
            }

            try
            {
                List<Image> images = new List<Image>();
                foreach (string imagePath in imagePaths)
                {
                    Image image = Image.FromFile(imagePath);
                    image = this.Scale(image, maxImageWidth, A4_HEIGHT);
                    images.Add(image);
                }

                PrintDocument pd = new PrintDocument();
                pd.PrintPage += (sender, e) => printDoc_PrintPage(images, sender, e);
                pd.Print();
            }
            catch (System.Drawing.Printing.InvalidPrinterException)
            {
                return false;
            }

            return true;
        }
Example #44
0
        public void Print()
        {
            try {
                _current = 0;

                PrintDocument document = new PrintDocument();
                document.PrinterSettings = _config.PrinterSettings;
                document.PrinterSettings.Collate = true;
                document.PrinterSettings.Copies = (short)_session.NumberOfCopies;
                //document.DefaultPageSettings.Margins = new Margins(100, 100, 100, 100);
                document.DefaultPageSettings.Margins = new Margins(25, 25, 25, 25);
                document.QueryPageSettings += OnQueryPageSettings;
                document.PrintPage += OnPrintPage;

                if (!String.IsNullOrEmpty(_config.PaperSource)) {
                    foreach (PaperSource source in document.PrinterSettings.PaperSources) {
                        if (source.SourceName == _config.PaperSource)
                            document.DefaultPageSettings.PaperSource = source;
                    }
                }

                if (_config.PreviewOnly) {
                    if (Application.OpenForms.Count > 0)
                        Application.OpenForms[0].BeginInvoke(new WaitCallback(PreviewProc), document);
                } else {
                    document.Print();
                }
            } catch (Exception ex) {
            #if DEBUG
                Dicom.Debug.Log.Error("DICOM Print Error: " + ex.ToString());
            #else
                Dicom.Debug.Log.Error("DICOM Print Error: " + ex.Message);
            #endif
            }
        }
Example #45
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            string    sql1 = @"select * from Application_Setting where User_Id=" + Session["Id"] + " and Appl_Id=53 and IsVaild=1";
            DataTable dt1  = dataobj.Selectdatatable(sql1);
            if (dt1.Rows.Count == 1)
            {
                string sql  = @"UserBackPruches " + Session["UserReportId"] + ",'" + DateTime.Parse(Session["DateFrom"].ToString()) + "','" + DateTime.Parse(Session["DateTo"].ToString()) + "'";
                string path = "Reports/ReportUserBackPruches.rpt";
                System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument();
                ReportDocument reportdocument = new ReportDocument();
                reportdocument.Load(Server.MapPath(path));

                reportdocument.DataSourceConnections[0].SetConnection(".", "ERPsystem", true);
                reportdocument.SetDataSource(dataobj.Selectdatatable(sql));
                reportdocument.SetParameterValue("@userId", Session["UserReportId"]);
                reportdocument.SetParameterValue("@datefrom", DateTime.Parse(Session["DateFrom"].ToString()));
                reportdocument.SetParameterValue("@dateto", DateTime.Parse(Session["DateTo"].ToString()));
                CrystalReportViewer1.ReportSource = reportdocument;
            }
            else
            {
                Response.Redirect("MainPage.aspx");
            }
        }
        catch { Response.Redirect("MainPage.aspx"); }
    }
        private void PrintClicked(object sender, System.EventArgs e)
        {
            if (Viewer == null)
            {
                return;
            }

            PrintDocument pd = new PrintDocument();
            pd.DocumentName = Viewer.SourceFile.LocalPath;
            pd.PrinterSettings.FromPage = 1;
            pd.PrinterSettings.ToPage = Viewer.PageCount;
            pd.PrinterSettings.MaximumPage = Viewer.PageCount;
            pd.PrinterSettings.MinimumPage = 1;
            pd.DefaultPageSettings.Landscape = Viewer.PageWidth > Viewer.PageHeight ? true : false;
            using (PrintDialog dlg = new PrintDialog())
            {
                dlg.Document = pd;
                dlg.AllowSelection = true;
                dlg.AllowSomePages = true;
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    Viewer.Print(pd);
                }
            }

        }
        PrintDocument pd;//新建打印

        #region[事件]
        /// <summary>
        /// 初始化
        /// </summary>
        public A_FrmDCfgRealTime()
        {
            InitializeComponent();
            pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);//主函数中实例化,并且添加时间。
            this.MapGis.StationClick += new ZzhaControlLibrary.ZzhaMapGis.ClickStation(MapGis_StationClick);
        }
Example #48
0
        //如下的这个方法可以注释掉,没有任何的作用
        public void createXmlApp()
        {
            // 首先创建文件
            FileStream fs = File.Create(Application.StartupPath + "\\xmlAPP.xml");
            fs.Close();//关闭文件

            //创建 XmlDocument 以便操作
            XmlDocument xmlDoc = new XmlDocument();

            //xml 唯一的根,我设置的根都是root
            XmlElement xmlEleRoot = xmlDoc.CreateElement("root");

            // 这个配置还有一个是必须的,就是打印机的DPI, 其他的都不是必要的
            XmlElement xmlElePrinter = xmlDoc.CreateElement("printer");

            //打印机名称,这里直接设置默认打印机
            PrintDocument printDoc = new PrintDocument();
            xmlElePrinter.SetAttribute("PrinterName", printDoc.PrinterSettings.PrinterName);
            printDoc.Dispose();//释放资源

            //DPI有两个
            xmlElePrinter.SetAttribute("DPIX", "600");
            xmlElePrinter.SetAttribute("DPIY", "600");

            //如下是两个添加操作了
            xmlEleRoot.AppendChild(xmlElePrinter);
            xmlDoc.AppendChild(xmlEleRoot);

            //保存操作
            xmlDoc.Save(Application.StartupPath + "\\xmlAPP.xml");
        }
Example #49
0
 public void Run()
 {
     PrintDocument doc = new PrintDocument();
     doc.PrinterSettings = m_settings;
     doc.PrintPage += doc_PrintPage;
     doc.Print();
 }
 /* Events to execute when the "Print" button is clicked */
 private void Print_button_Click(object sender, EventArgs e)
 {
     /* Creates a new instance of printDocument, appends the result from PrintDocumentOnPrintPage and prints the result */
     PrintDocument printDocument = new PrintDocument();
     printDocument.PrintPage += PrintDocumentOnPrintPage;
     printDocument.Print();
 }
Example #51
0
        public UnitOpEditor(UnitOpControl unitOpCtrl)
            : base(unitOpCtrl)
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            this.menuItemReport       = new System.Windows.Forms.MenuItem();
            this.menuItemPageSetup    = new System.Windows.Forms.MenuItem();
            this.menuItemPrintPreview = new System.Windows.Forms.MenuItem();
            this.menuItemPrint        = new System.Windows.Forms.MenuItem();
            this.menuItemSave         = new System.Windows.Forms.MenuItem();
            this.printDocument        = new System.Drawing.Printing.PrintDocument();
            this.saveFileDialog       = new System.Windows.Forms.SaveFileDialog();

            //
            // menuItemReport
            //
            this.menuItemReport.Index = 1;
            this.menuItemReport.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
                this.menuItemPageSetup,
                this.menuItemPrintPreview,
                this.menuItemPrint,
                this.menuItemSave
            });
            this.menuItemReport.Text = "Report";
            //
            // menuItemPageSetup
            //
            this.menuItemPageSetup.Index  = 0;
            this.menuItemPageSetup.Text   = "Page Setup...";
            this.menuItemPageSetup.Click += new System.EventHandler(this.menuItemPageSetup_Click);
            //
            // menuItemPrintPreview
            //
            this.menuItemPrintPreview.Index  = 1;
            this.menuItemPrintPreview.Text   = "Print Preview...";
            this.menuItemPrintPreview.Click += new System.EventHandler(this.menuItemPrintPreview_Click);
            //
            // menuItemPrint
            //
            this.menuItemPrint.Index  = 2;
            this.menuItemPrint.Text   = "Print...";
            this.menuItemPrint.Click += new System.EventHandler(this.menuItemPrint_Click);
            //
            // menuItemSave
            //
            this.menuItemSave.Index  = 3;
            this.menuItemSave.Text   = "Save...";
            this.menuItemSave.Click += new System.EventHandler(this.menuItemSave_Click);

            this.mainMenu.MenuItems.Add(this.menuItemReport);

            //
            // printDocument
            //
            this.printDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.printDocument_PrintPage);
        }
Example #52
0
        public void StartPrint(T[] values, string printer, bool showPrinterDialog, PrintTemplate template)
        {
            if (template == null)
            {
                throw new Exception("打印失败参数:template 为空");
            }

            if (values == null)
            {
                throw new Exception("打印失败参数:vlaues 为空");
            }

            if (values.Length == 0)
            {
                throw new Exception("打印失败参数:vlaues 没有数据");
            }

            if (values.Any(obj => obj == null))
            {
                throw new Exception("打印失败参数:vlaues 中含有空对象");
            }
            System.Drawing.Printing.PrintDocument document = new System.Drawing.Printing.PrintDocument();
            if (showPrinterDialog == false)
            {
                if (string.IsNullOrWhiteSpace(printer))
                {
                    throw new Exception("打印机名称为空,请设置打印机");
                }
                if (System.Drawing.Printing.PrinterSettings.InstalledPrinters.OfType <string>().Contains(printer) == false)
                {
                    throw new Exception("打印机不存在此电脑上:" + printer);
                }
                document.PrinterSettings.PrinterName = printer;
            }
            else
            {
                var pd = new System.Windows.Forms.PrintDialog()
                {
                    UseEXDialog = true
                };
                var ret = pd.ShowDialog();
                if (ret != System.Windows.Forms.DialogResult.OK && ret != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }
                document.PrinterSettings.PrinterName = pd.PrinterSettings.PrinterName;
            }
            document.PrintController = new System.Drawing.Printing.StandardPrintController();
            document.DefaultPageSettings.PaperSize = new System.Drawing.Printing.PaperSize("shoperp_print_size", (int)MapToPrinterPix(template.Width), (int)MapToPrinterPix(template.Height));
            document.DefaultPageSettings.Margins   = new System.Drawing.Printing.Margins(0, 0, 0, 0);
            document.DocumentName = template.Name + DateTime.Now;
            document.PrintPage   += Document_PrintPage;
            document.BeginPrint  += Document_BeginPrint;
            document.EndPrint    += Document_EndPrint;
            this.index            = 0;
            this.Values           = values;
            this.Template         = template;
            document.Print();
        }
 public override System.Drawing.Graphics OnStartPage(System.Drawing.Printing.PrintDocument document, System.Drawing.Printing.PrintPageEventArgs e)
 {
     _pagenumber = _pagenumber + 1;
     _bitmap     = new Bitmap(e.PageBounds.Width, e.PageBounds.Height);
     _graphics   = Graphics.FromImage(_bitmap);
     _graphics.FillRectangle(Brushes.White, e.PageBounds);
     return(_graphics);
 }
Example #54
0
        /* final restando cantidad total y removiendo servicio de dtgvListaFactura*/


        private void button1_Click(object sender, EventArgs e)
        {
            printDocument1 = new System.Drawing.Printing.PrintDocument();
            PrinterSettings ps = new PrinterSettings();

            printDocument1.PrinterSettings = ps;
            printDocument1.PrintPage      += Imprimir;
            printDocument1.Print();
        }
Example #55
0
        private void cboPrinters_SelectedIndexChanged(object sender, EventArgs e)
        {
            int iMaxPaperHeight = 0;
            int iMaxPaperWidth  = 0;

            System.Drawing.Printing.PrintDocument pd     = new System.Drawing.Printing.PrintDocument();
            System.Drawing.Printing.PaperSize     pkSize = new System.Drawing.Printing.PaperSize();

            this.cboMapSize.Items.Clear();
            this.cboMapSize.Enabled = false;

            pd.PrinterSettings.PrinterName = this.cboPrinters.SelectedItem.ToString();

            foreach (PaperSize psize in pd.PrinterSettings.PaperSizes)
            {
                if (psize.Width > iMaxPaperWidth)
                {
                    iMaxPaperWidth = psize.Width;
                }
                if (psize.Height > iMaxPaperHeight)
                {
                    iMaxPaperHeight = psize.Height;
                }
            }

            if ((iMaxPaperWidth * .01) > 8.5)
            {
                if ((iMaxPaperWidth * .01) > 11.69)
                {
                    if ((iMaxPaperWidth * .01) > 17)
                    {
                        this.cboMapSize.Items.Add("8.5 x 11");
                        this.cboMapSize.Items.Add("11 x 17");
                        this.cboMapSize.Items.Add("17 x 22");
                        this.cboMapSize.Items.Add("34 x 44");
                    }
                    else
                    {
                        this.cboMapSize.Items.Add("8.5 x 11");
                        this.cboMapSize.Items.Add("11 x 17");
                        this.cboMapSize.Items.Add("17 x 22");
                    }
                }
                else
                {
                    this.cboMapSize.Items.Add("8.5 x 11");
                    this.cboMapSize.Items.Add("11 x 17");
                }
            }
            else
            {
                this.cboMapSize.Items.Add("8.5 x 11");
            }

            this.cboMapSize.Enabled       = true;
            this.cboMapSize.SelectedIndex = 0; // this.cboMapSize.Items.Count - 1;
        }
        private void Print(string thetext)
        {
            try //source: https://stackoverflow.com/questions/44979794/how-to-print-a-long-string-into-multiple-pages-in-c-sharp
            {
                System.Drawing.Printing.PrintDocument p = new System.Drawing.Printing.PrintDocument();

                var font  = new Font("Times New Roman", 12);
                var brush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);

                // what still needs to be printed
                var remainingText = thetext;

                p.PrintPage += delegate(object sender1, System.Drawing.Printing.PrintPageEventArgs e1)
                {
                    int charsFitted, linesFilled;

                    // measure how many characters will fit of the remaining text

                    var realsize = e1.Graphics.MeasureString(
                        remainingText,
                        font,
                        e1.MarginBounds.Size,
                        System.Drawing.StringFormat.GenericDefault,
                        out charsFitted,      // this will return what we need
                        out linesFilled);

                    // take from the remainingText what we're going to print on this page
                    var fitsOnPage = remainingText.Substring(0, charsFitted);
                    // keep what is not printed on this page
                    remainingText = remainingText.Substring(charsFitted).Trim();

                    // print what fits on the page
                    e1.Graphics.DrawString(
                        fitsOnPage,
                        font,
                        brush,
                        e1.MarginBounds);

                    // if there is still text left, tell the PrintDocument it needs to call
                    // PrintPage again.
                    e1.HasMorePages = remainingText.Length > 0;
                };

                System.Windows.Forms.PrintDialog pd = new System.Windows.Forms.PrintDialog();
                pd.Document = p;
                DialogResult result = pd.ShowDialog();

                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    p.Print();
                }
            }
            catch
            {
                //System.Windows.MessageBox.Show(e2.Message, "Unable to print", MessageBoxButton.OK);
            }
        }
Example #57
0
        /* Create a print preview */
        private void mnuPrintPreview_Click(object sender, EventArgs e)
        {
            PrintDocument      docPreview    = new System.Drawing.Printing.PrintDocument();
            PrintPreviewDialog previewDialog = new PrintPreviewDialog();

            docPreview.PrintPage  += new PrintPageEventHandler(Doc_PrintPage);
            previewDialog.Document = docPreview;
            previewDialog.ShowDialog();
        }
        public MainWindow()
        {
            InitializeComponent();

            objPrintDocument = new System.Drawing.Printing.PrintDocument();
            this.objPrintDocument.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.objPrintDocument_PrintPage);

            PopulateInstalledPrintersToComboBox();
        }
Example #59
0
        private void PrintChequeReport(String Date, String Pay, String Rupees, String Rs)
        {
            //Create new table in a dataset
            DataSet   ds = new DataSet();
            DataTable dt = new DataTable("tblCheque");

            dt.Columns.Add(new DataColumn("Date", typeof(string)));
            dt.Columns.Add(new DataColumn("Pay", typeof(string)));
            dt.Columns.Add(new DataColumn("Rupees", typeof(string)));
            dt.Columns.Add(new DataColumn("Rs", typeof(string)));
            //inserting new record to the table
            DataRow dr = dt.NewRow();

            dr["Date"]   = BuildDateToPrint(Date);
            dr["Pay"]    = Pay;
            dr["Rupees"] = Rupees;
            dr["Rs"]     = Rs;
            dt.Rows.Add(dr);
            ds.Tables.Add(dt);//inserted record is now ready to view in crystal report (ds)

            PrinterSettings settings    = new PrinterSettings();
            string          printerName = settings.PrinterName;

            if (!isPrinteroffline(printerName))
            {
                //direct print!
                rptDFCC_CHEQUE cr = new rptDFCC_CHEQUE(); // here rptDFCC_CHEQUE is the Crystal Report
                System.Drawing.Printing.PrintDocument doctoprint = new System.Drawing.Printing.PrintDocument();
                doctoprint.PrinterSettings.PrinterName = printerName;
                int rawKind = 0;
                for (int i = 0; i <= doctoprint.PrinterSettings.PaperSizes.Count - 1; i++)
                {
                    if (doctoprint.PrinterSettings.PaperSizes[i].PaperName == "DFCC-CHEQUE") // "DFCC-CHEQUE : Paper Size"
                    {
                        rawKind = Convert.ToInt32(doctoprint.PrinterSettings.PaperSizes[i].GetType().GetField
                                                      ("kind",
                                                      System.Reflection.BindingFlags.Instance |
                                                      System.Reflection.BindingFlags.NonPublic).GetValue(doctoprint.PrinterSettings.PaperSizes[i]));
                        break;
                    }
                }
                cr.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)rawKind;
                cr.SetDataSource(ds);
                cr.PrintToPrinter(1, false, 1, 2);
                MessageBox.Show("Cheque is sent to the " + printerName);
            }
            else
            {
                MessageBox.Show(printerName + " is workoffline!");
            }
            btnPrint.Text    = "Print";
            btnPrint.Enabled = true;

            //Show in cristal report viewer!
            //ChequeReport chkrpt = new ChequeReport(ds);
            //chkrpt.Show();
        }
Example #60
-1
 private void butPrint_Click(object sender,EventArgs e)
 {
     pagesPrinted=0;
     PrintDocument pd=new PrintDocument();
     pd.PrintPage += new PrintPageEventHandler(this.pd_PrintPage);
     pd.DefaultPageSettings.Margins=new Margins(25,25,40,40);
     //pd.OriginAtMargins=true;
     pd.DefaultPageSettings.Landscape=false;
     if(pd.DefaultPageSettings.PrintableArea.Height==0) {
         pd.DefaultPageSettings.PaperSize=new PaperSize("default",850,1100);
     }
     headingPrinted=false;
     try {
         #if DEBUG
             FormRpPrintPreview pView = new FormRpPrintPreview();
             pView.printPreviewControl2.Document=pd;
             pView.ShowDialog();
         #else
             if(PrinterL.SetPrinter(pd,PrintSituation.Default)) {
                 pd.Print();
             }
         #endif
     }
     catch {
         MessageBox.Show(Lan.g(this,"Printer not available"));
     }
 }