예제 #1
0
        private void uiCommandBar2_CommandClick(object sender, Janus.Windows.UI.CommandBars.CommandEventArgs e)
        {
            if (e.Command.Key == "cmdPageSet")
            {
                /*  if (this.axPageLayoutControl1.PageLayout.Page.Orientation == 2)
                 *    pageSetupDialog1.PageSettings.Landscape = true ;
                 * else pageSetupDialog1.PageSettings.Landscape = false ; */
                #region//页面设置
                //Show the page setup dialog storing the result.
                DialogResult result = pageSetupDialog1.ShowDialog();

                //set the printer settings of the preview document to the selected printer settings
                document.PrinterSettings = pageSetupDialog1.PrinterSettings;

                //set the page settings of the preview document to the selected page settings
                document.DefaultPageSettings = pageSetupDialog1.PageSettings;

                //due to a bug in PageSetupDialog the PaperSize has to be set explicitly by iterating through the
                //available PaperSizes in the PageSetupDialog finding the selected PaperSize
                int         i;
                IEnumerator paperSizes = pageSetupDialog1.PrinterSettings.PaperSizes.GetEnumerator();
                paperSizes.Reset();

                for (i = 0; i < pageSetupDialog1.PrinterSettings.PaperSizes.Count; ++i)
                {
                    paperSizes.MoveNext();
                    if (((PaperSize)paperSizes.Current).Kind == document.DefaultPageSettings.PaperSize.Kind)
                    {
                        document.DefaultPageSettings.PaperSize = ((PaperSize)paperSizes.Current);
                    }
                }
                ///initialize the current printer from the printer settings selected
                ///in the page setup dialog

                IPaper paper;
                paper = new PaperClass(); //create a paper object

                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                //in this case an EMF printer, alternatively a PS printer could be used

                //initialize the paper with the DEVMODE and DEVNAMES structures from the windows GDI
                //these structures specify information about the initialization and environment of a printer as well as
                //driver, device, and output port names for a printer
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());

                //pass the paper to the emf printer
                printer.Paper = paper;

                //set the page layout control's printer to the currently selected printer
                axPageLayoutControl1.Printer = printer;
                #endregion
            }
            if (e.Command.Key == "cmdPrintView")
            {
                #region//打印预览
                //initialize the currently printed page number
                m_CurrentPrintPage = 0;

                //check if a document is loaded into PageLayout  control
                if (axPageLayoutControl1.ActiveView.FocusMap == null)
                {
                    return;
                }
                //set the name of the print preview document to the name of the mxd doc
                document.DocumentName = axPageLayoutControl1.DocumentFilename;

                //set the PrintPreviewDialog.Document property to the PrintDocument object selected by the user
                printPreviewDialog1.Document = document;
                //   printPreviewDialog1 .pa
                printPreviewDialog1.Document.DefaultPageSettings = pageSetupDialog1.PageSettings;

                //show the dialog - this triggers the document's PrintPage event
                printPreviewDialog1.ShowDialog();
                #endregion
            }
            if (e.Command.Key == "cmdPrint")
            {
                #region //打印
                //allow the user to choose the page range to be printed
                printDialog1.AllowSomePages = true;
                //show the help button.
                printDialog1.ShowHelp = true;

                //set the Document property to the PrintDocument for which the PrintPage Event
                //has been handled. To display the dialog, either this property or the
                //PrinterSettings property must be set
                printDialog1.Document = document;

                //show the print dialog and wait for user input
                DialogResult result = printDialog1.ShowDialog();

                // If the result is OK then print the document.
                if (result == DialogResult.OK)
                {
                    document.Print();
                }
                #endregion
            }
            if (e.Command.Key == "cmdOpenFile")
            {
                m_Command = new ControlsOpenDocCommandClass();
                m_Command.OnCreate(axPageLayoutControl1.Object);
                m_Command.OnClick();
            }
            if (e.Command.Key == "cmdSaveFile")
            {
                m_Command = new ControlsSaveAsDocCommandClass();
                m_Command.OnCreate(axPageLayoutControl1.Object);
                m_Command.OnClick();
            }
            if (e.Command.Key == "cmdSelectElement")
            {
                m_Command = new ControlsSelectToolClass();
                this.axPageLayoutControl1.CurrentTool = (ITool)m_Command;
                m_Command.OnCreate(axPageLayoutControl1.Object);
                m_Command.OnClick();
            }
            if (e.Command.Key == "CmdExportMapAsPicture")
            {
                ICommand pExportMapAsPicture = new ExportMapProj.CmdExoprtMapAsPicture();
                pExportMapAsPicture.OnCreate(m_pageLayoutControl.Object);
                pExportMapAsPicture.OnClick();
            }
            if (e.Command.Key == "cmdChoseTemplete")
            {
                ChoseTemple chosetem = new ChoseTemple();
                chosetem.ShowDialog();
                if (chosetem.m_templateName != "")
                {
                    this.axPageLayoutControl1.ActiveView.Clear();
                    this.axPageLayoutControl1.LoadMxFile(System.Windows.Forms.Application.StartupPath + @"\pagelayoutTemplate\" + chosetem.m_templateName, Type.Missing);
                    SetMapFrame();
                    IMaps maps = new Maps();
                    maps.Add(m_Map);
                    m_pageLayoutControl.PageLayout.ReplaceMaps(maps);
                    axPageLayoutControl1.ActiveView.Refresh();
                }
            }
            if (e.Command.Key == "cmdScaleSetandPrint")//比例设置
            {
                frmSetMapScale frmSMS       = new frmSetMapScale();
                double         pnewMapScale = frmSMS.setMapScale(m_mapScale, this.axPageLayoutControl1.ActiveView.FocusMap.MapScale);
                this.axPageLayoutControl1.ActiveView.FocusMap.MapScale = pnewMapScale;
                this.axPageLayoutControl1.ActiveView.Refresh();
            }
        }
예제 #2
0
        private void uiCommandBar2_CommandClick(object sender, Janus.Windows.UI.CommandBars.CommandEventArgs e)
        {
            if (e.Command.Key == "cmdPageSet")
            {
              /*  if (this.axPageLayoutControl1.PageLayout.Page.Orientation == 2)
                    pageSetupDialog1.PageSettings.Landscape = true ;
                else pageSetupDialog1.PageSettings.Landscape = false ; */
                #region//ҳ������
                //Show the page setup dialog storing the result.
                DialogResult result = pageSetupDialog1.ShowDialog();

                //set the printer settings of the preview document to the selected printer settings
                document.PrinterSettings = pageSetupDialog1.PrinterSettings;

                //set the page settings of the preview document to the selected page settings
                document.DefaultPageSettings = pageSetupDialog1.PageSettings;

                //due to a bug in PageSetupDialog the PaperSize has to be set explicitly by iterating through the
                //available PaperSizes in the PageSetupDialog finding the selected PaperSize
                int i;
                IEnumerator paperSizes = pageSetupDialog1.PrinterSettings.PaperSizes.GetEnumerator();
                paperSizes.Reset();

                for (i = 0; i < pageSetupDialog1.PrinterSettings.PaperSizes.Count; ++i)
                {
                    paperSizes.MoveNext();
                    if (((PaperSize)paperSizes.Current).Kind == document.DefaultPageSettings.PaperSize.Kind)
                    {
                        document.DefaultPageSettings.PaperSize = ((PaperSize)paperSizes.Current);
                    }
                }
                ///initialize the current printer from the printer settings selected
                ///in the page setup dialog

                IPaper paper;
                paper = new PaperClass(); //create a paper object

                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                //in this case an EMF printer, alternatively a PS printer could be used

                //initialize the paper with the DEVMODE and DEVNAMES structures from the windows GDI
                //these structures specify information about the initialization and environment of a printer as well as
                //driver, device, and output port names for a printer
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());

                //pass the paper to the emf printer
                printer.Paper = paper;

                //set the page layout control's printer to the currently selected printer
                axPageLayoutControl1.Printer = printer;
                #endregion

            }
            if (e.Command.Key == "cmdPrintView")
            {

                #region//��ӡԤ��
                //initialize the currently printed page number
                m_CurrentPrintPage = 0;

                //check if a document is loaded into PageLayout  control
                if (axPageLayoutControl1.ActiveView.FocusMap == null) return;
                //set the name of the print preview document to the name of the mxd doc
                document.DocumentName = axPageLayoutControl1.DocumentFilename;

                //set the PrintPreviewDialog.Document property to the PrintDocument object selected by the user
                printPreviewDialog1.Document = document;
               //   printPreviewDialog1 .pa
                printPreviewDialog1.Document.DefaultPageSettings = pageSetupDialog1.PageSettings;

                //show the dialog - this triggers the document's PrintPage event
                printPreviewDialog1.ShowDialog();
                #endregion
            }
            if (e.Command.Key == "cmdPrint")
            {
                #region //��ӡ
                //allow the user to choose the page range to be printed
                printDialog1.AllowSomePages = true;
                //show the help button.
                printDialog1.ShowHelp = true;

                //set the Document property to the PrintDocument for which the PrintPage Event
                //has been handled. To display the dialog, either this property or the
                //PrinterSettings property must be set
                printDialog1.Document = document;

                //show the print dialog and wait for user input
                DialogResult result = printDialog1.ShowDialog();

                // If the result is OK then print the document.
                if (result == DialogResult.OK) document.Print();
                #endregion
            }
            if (e.Command.Key == "cmdOpenFile")
            {

                m_Command = new ControlsOpenDocCommandClass();
                m_Command.OnCreate(axPageLayoutControl1.Object);
                m_Command.OnClick();

            }
            if (e.Command.Key == "cmdSaveFile")
            {
                m_Command = new ControlsSaveAsDocCommandClass();
                m_Command.OnCreate(axPageLayoutControl1.Object);
                m_Command.OnClick();
            }
            if (e.Command.Key == "cmdSelectElement")
            {
                m_Command = new ControlsSelectToolClass();
                this.axPageLayoutControl1.CurrentTool = (ITool)m_Command;
                m_Command.OnCreate(axPageLayoutControl1.Object);
                m_Command.OnClick();
            }
            if (e.Command.Key == "CmdExportMapAsPicture")
            {
                ICommand pExportMapAsPicture = new ExportMapProj.CmdExoprtMapAsPicture();
                pExportMapAsPicture.OnCreate(m_pageLayoutControl.Object);
                pExportMapAsPicture.OnClick();

            }
            if (e.Command.Key == "cmdChoseTemplete")
            {
                ChoseTemple chosetem = new ChoseTemple();
                chosetem.ShowDialog();
                if (chosetem.m_templateName != "")
                {
                    this.axPageLayoutControl1.ActiveView.Clear();
                    this.axPageLayoutControl1.LoadMxFile(System.Windows.Forms.Application.StartupPath + @"\pagelayoutTemplate\" + chosetem.m_templateName, Type.Missing);
                    SetMapFrame();
                    IMaps maps = new Maps();
                    maps.Add(m_Map);
                    m_pageLayoutControl.PageLayout.ReplaceMaps(maps);
                    axPageLayoutControl1.ActiveView.Refresh();

                }
            }
            if (e.Command.Key == "cmdScaleSetandPrint")//��������
            {
                frmSetMapScale frmSMS = new frmSetMapScale();
                 double pnewMapScale=frmSMS.setMapScale(m_mapScale,this .axPageLayoutControl1 .ActiveView .FocusMap.MapScale );
                 this.axPageLayoutControl1.ActiveView.FocusMap.MapScale = pnewMapScale;
                 this.axPageLayoutControl1.ActiveView.Refresh();
            }
        }