Example #1
0
        private void btnPageSetup_Click(object sender, EventArgs e)
        {
            DialogResult result = pageSetupDialog1.ShowDialog();

            document.PrinterSettings     = pageSetupDialog1.PrinterSettings;
            document.DefaultPageSettings = pageSetupDialog1.PageSettings;

            IEnumerator paperSizes = pageSetupDialog1.PrinterSettings.PaperSizes.GetEnumerator();

            paperSizes.Reset();

            for (int 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);
                }
            }
            IPaper paper = new PaperClass();

            paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());

            printer.Paper = paper;
            axPageLayoutControl1.Printer = printer;
        }
Example #2
0
        private void btnPageSize_Click(object sender, EventArgs e)
        {
            try
            {
                //实例化打印设置窗口
                DialogResult result = pageSetupDialog1.ShowDialog();
                //设置打印文档对象的打印机
                document.PrinterSettings = pageSetupDialog1.PrinterSettings;
                //设置打印文档对象的页面设置为用户在打印设置对话框中的设置
                document.DefaultPageSettings = pageSetupDialog1.PageSettings;
                //页面设置
                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);
                    }
                }

                //初始化纸张和打印机
                IPaper   paper   = new PaperClass();
                IPrinter printer = new EmfPrinterClass();
                //关联打印机对象和纸张对象
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                printer.Paper = paper;
                PrintPagelayoutControl.Printer = printer;
            }
            catch { }
        }
Example #3
0
        /// <summary>
        /// 页面设置
        /// </summary>
        public void PageSetUp()
        {
            //Show the page setup dialog storing the result.
            DialogResult result;

            try
            {
                result = pageSetupDialog1.ShowDialog();
            }
            catch
            {
                MessageBox.Show("未安装打印机", "提示");
                return;
            }
            if (result == DialogResult.OK)
            {
                //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;
            }
        }
Example #4
0
 public PrinterClass(MediaEnum?Media, PaperClass Paper, TonerEnum?Toner, InkEnum?Ink, LampEnum?Lamp, RetractBinsClass RetractBins, int?MediaOnStacker, PaperTypeClass PaperType, BlackMarkModeEnum?BlackMarkMode)
 {
     this.Media          = Media;
     this.Paper          = Paper;
     this.Toner          = Toner;
     this.Ink            = Ink;
     this.Lamp           = Lamp;
     this.RetractBins    = RetractBins;
     this.MediaOnStacker = MediaOnStacker;
     this.PaperType      = PaperType;
     this.BlackMarkMode  = BlackMarkMode;
 }
Example #5
0
        private void frmPrint_Load(object sender, EventArgs e)
        {
            PrintDocument document;
            IPaper        paper;

            if (this.iactiveView_0 is IPageLayout)
            {
                if ((this.iactiveView_0 as IPageLayout2).Printer != null)
                {
                    this.iprinter_0 = (this.iactiveView_0 as IPageLayout2).Printer;
                }
                else
                {
                    this.iprinter_0 = new EmfPrinterClass();
                    document        = new PrintDocument();
                    paper           = new PaperClass
                    {
                        PrinterName = document.PrinterSettings.PrinterName,
                        Orientation = (this.iactiveView_0 as IPageLayout2).Page.Orientation
                    };
                    this.iprinter_0.Paper = paper;
                }
            }
            else
            {
                this.iprinter_0 = new EmfPrinterClass();
                document        = new PrintDocument();
                paper           = new PaperClass
                {
                    PrinterName = document.PrinterSettings.PrinterName
                };
                this.iprinter_0.Paper = paper;
            }
            this.trackBar1.Value =
                (this.iactiveView_0.ScreenDisplay.DisplayTransformation as IOutputRasterSettings).ResampleRatio;
            this.txtQulity.Text = this.trackBar1.Value.ToString();
            this.method_2();
            this.method_3();
            this.bool_0 = true;
            if (this.iactiveView_0 is IPageLayout)
            {
                this.rdoTitle.Checked = (this.iactiveView_0 as IPageLayout).Page.PageToPrinterMapping ==
                                        esriPageToPrinterMapping.esriPageMappingTile;
            }
        }
Example #6
0
        private void btnPrinterPage_Click(object sender, EventArgs e)
        {
            //开始页面设置调用
            DialogResult result = pPageSetupDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                //set the printer settings of the preview document to the selected printer settings
                document.PrinterSettings = pPageSetupDialog.PrinterSettings;
                //set the page settings of the preview document to the selected page settings
                document.DefaultPageSettings = pPageSetupDialog.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 = pPageSetupDialog.PrinterSettings.PaperSizes.GetEnumerator();
                paperSizes.Reset();
                for (i = 0; i < pPageSetupDialog.PrinterSettings.PaperSizes.Count; ++i)
                {
                    paperSizes.MoveNext();
                    if (((PaperSize)paperSizes.Current).Kind == document.DefaultPageSettings.PaperSize.Kind)
                    {
                        if (((PaperSize)paperSizes.Current).PaperName == document.DefaultPageSettings.PaperSize.PaperName)
                        {
                            document.DefaultPageSettings.PaperSize = ((PaperSize)paperSizes.Current);
                        }
                    }
                }

                IPaper   paper   = new PaperClass();      //create a paper object
                IPrinter printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pPageSetupDialog.PrinterSettings.GetHdevmode(pPageSetupDialog.PageSettings).ToInt32(), pPageSetupDialog.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
                m_pPageLayoutCtl.Printer = printer;

                UpdatePageSizedisplay();
                m_pPageLayoutCtl.ActiveView.Refresh();
            }
        }
Example #7
0
        public static void SetPrinter(ref IPageLayoutControl pPageControl, ref PrintDocument document)
        {
            try
            {
                PageSetupDialog pageSetDlg = new PageSetupDialog();
                pageSetDlg.PageSettings    = new PageSettings();
                pageSetDlg.PrinterSettings = new PrinterSettings();
                pageSetDlg.ShowNetwork     = true;
                if (pageSetDlg.ShowDialog() == DialogResult.OK)
                {
                    document.PrinterSettings     = pageSetDlg.PrinterSettings;
                    document.DefaultPageSettings = pageSetDlg.PageSettings;

                    int         i;
                    IEnumerator paperSizes = pageSetDlg.PrinterSettings.PaperSizes.GetEnumerator();
                    paperSizes.Reset();

                    for (i = 0; i < pageSetDlg.PrinterSettings.PaperSizes.Count; ++i)
                    {
                        paperSizes.MoveNext();
                        if (((PaperSize)paperSizes.Current).Kind == document.DefaultPageSettings.PaperSize.Kind)
                        {
                            document.DefaultPageSettings.PaperSize = ((PaperSize)paperSizes.Current);
                            break;
                        }
                    }

                    IPaper paper;
                    paper = new PaperClass();        //create a paper object
                    IPrinter printer;
                    printer = new EmfPrinterClass(); //create a printer object
                    paper.Attach(pageSetDlg.PrinterSettings.GetHdevmode(pageSetDlg.PageSettings).ToInt32(), pageSetDlg.PrinterSettings.GetHdevnames().ToInt32());
                    printer.Paper        = paper;
                    pPageControl.Printer = printer;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("打印设置失败:" + ex.Message, "提示");
            }
        }
Example #8
0
        /// <summary>
        /// 页面设置
        /// </summary>
        public void PageSetUp()
        {
            //Show the page setup dialog storing the result.
            DialogResult result;
            try
            {
                result = pageSetupDialog1.ShowDialog();
            }
            catch
            {
                MessageBox.Show("未安装打印机", "提示");
                return;
            }
            if (result == DialogResult.OK)
            {

                //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;
            }
        }
Example #9
0
        //���õ�ͼ������Ϣ��������ߣ�ͼ���ȣ�
        private void SetMapFrame()
        {
            IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)this.axPageLayoutControl1.ActiveView;
            pGraphicsContainer.Reset();
               IElementProperties pElementProperties = (IElementProperties)pGraphicsContainer.Next();
            while (pElementProperties != null)
            {
                if (pElementProperties is ITextElement)  //�����ı�
                {
                    ITextElement ptextElement = new TextElementClass();
                    ptextElement = (ITextElement)pElementProperties;
                    if (ptextElement.Text.Trim() == "˫����ӱ���" ||ptextElement .Symbol.Size >25)
                    {
                        ptextElement.Text = m_textTitle;
                    }
                    if (ptextElement.Text.Trim().Contains("����ϵ"))
                    {
                        ptextElement.Text = "����ϵ��" + m_textProject + "\r" + "�߳�ϵ��" + m_textElevation;
                    }

                    if (ptextElement.Text.Trim().Contains("������"))
                    {
                        ptextElement.Text = "��ͼ�ˣ�"+m_textName+"\r"+"����ʱ�䣺"+m_textDate;
                    }

                }
               if (pElementProperties.Type == "Map Surround Frame")
               {

                    IMapSurroundFrame pMapSurrounFrame = pElementProperties as IMapSurroundFrame;
                    IElement pElement = (IElement)pElementProperties;

                    if (pMapSurrounFrame.MapSurround.Name.Trim() == "Legend")
                    {
                        ILegend pLegend = pMapSurrounFrame.MapSurround as ILegend;
                            pLegend.Map = m_Map;
                          //  IMapSurround pMapSurround = pMapSurrounFrame.MapSurround;
                          //pElement = pMapSurrounFrame.MapSurround as IElement;
                          //  pMapSurround.Map = m_Map;
                          //  m_Map.AddMapSurround(pMapSurround);

                    }
                     if (pMapSurrounFrame.MapSurround.Name == "Alternating Scale Bar" ||pMapSurrounFrame.MapSurround.Name == "Stepped Scale Line"||pMapSurrounFrame.MapSurround .Name =="Scale Line"||
                         pMapSurrounFrame .MapSurround .Name =="Hollow Scale Bar"||pMapSurrounFrame .MapSurround .Name =="Single Division Scale Bar"||
                         pMapSurrounFrame .MapSurround.Name =="Double Alternating Scale Bar")
                     {
                        // m_Map.MapScale = 5000;
                             IScaleBar pScaleBar = pMapSurrounFrame.MapSurround as IScaleBar;
                              pScaleBar.Map = m_Map;

                              pScaleBar.Units = m_Map.MapUnits;
                              pScaleBar.UseMapSettings();

                              pElement = pMapSurrounFrame.MapSurround as IElement;

                    }
                   if (pMapSurrounFrame.MapSurround.Name == "Scale Text")
                    {
                        IScaleText pScaleText = pMapSurrounFrame.MapSurround as IScaleText;
                            pScaleText.Map = m_Map;
                    }
                    if (pMapSurrounFrame.MapSurround.Name == "North Arrow")
                    {
                        INorthArrow pNorthArrow = pMapSurrounFrame.MapSurround as INorthArrow;

                            pNorthArrow.Map = m_Map;
                    }
                }
                if (pElementProperties.Type == "Data Frame")
                {
                    IFrameElement pFrameElement = pElementProperties as IFrameElement;
                    IMapFrame pMapframe = pFrameElement as IMapFrame;
                   // pMapframe.ExtentType = esriExtentTypeEnum.esriExtentBounds;
                    IMapGrids pmapGrids = pMapframe as IMapGrids;
                    IMapGrid pMapGrid = null;
                    for(int i =0;i<pmapGrids.MapGridCount ;i++)
                    {
                        pMapGrid = pmapGrids.get_MapGrid(i);
                      //�û�Ҫ����ʾ���
                            pMapGrid.Visible = true;
                    }
                }

                pElementProperties = (IElementProperties)pGraphicsContainer.Next();
            }
            if (axPageLayoutControl1.Page.Orientation == 2)
            {
                IPaper paper;
                paper = new PaperClass(); //create a paper object
                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                paper.Orientation = 2;
                printer.Paper = paper;
                axPageLayoutControl1.Printer = printer;

              pageSetupDialog1.PageSettings.Landscape = true;
              pageSetupDialog1.AllowOrientation = true;

            }
            if (axPageLayoutControl1.Page.Orientation == 1&&axPageLayoutControl1 .Printer .Paper .Orientation ==2)
            {
                IPaper paper;
                paper = new PaperClass(); //create a paper object
                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                paper.Orientation = 1;
                printer.Paper = paper;
                axPageLayoutControl1.Printer = printer;
                pageSetupDialog1.PageSettings.Landscape = false;
                pageSetupDialog1.AllowOrientation = true;
            }
        }
Example #10
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();
            }
        }
Example #11
0
        private void SetMapFrame()//设置地图基本信息,如比例尺,图例等:
        {
            IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)this.axPageLayoutControl1.ActiveView;

            pGraphicsContainer.Reset();
            IElementProperties pElementProperties = (IElementProperties)pGraphicsContainer.Next();

            while (pElementProperties != null)
            {
                if (pElementProperties is ITextElement)  //设置文本
                {
                    ITextElement ptextElement = new TextElementClass();
                    ptextElement = (ITextElement)pElementProperties;
                    if (ptextElement.Text.Trim() == "双击添加标题" || ptextElement.Symbol.Size > 25)
                    {
                        ptextElement.Text = m_textTitle;
                    }
                    if (ptextElement.Text.Trim().Contains("坐标系"))
                    {
                        ptextElement.Text = "坐标系:" + m_textProject + "\r" + "高程系:" + m_textElevation;
                    }

                    if (ptextElement.Text.Trim().Contains("制作者"))
                    {
                        ptextElement.Text = "制图人:" + m_textName + "\r" + "制作时间:" + m_textDate;
                    }
                }
                if (pElementProperties.Type == "Map Surround Frame")
                {
                    IMapSurroundFrame pMapSurrounFrame = pElementProperties as IMapSurroundFrame;
                    IElement          pElement         = (IElement)pElementProperties;

                    if (pMapSurrounFrame.MapSurround.Name.Trim() == "Legend")
                    {
                        ILegend pLegend = pMapSurrounFrame.MapSurround as ILegend;
                        pLegend.Map = m_Map;
                        //  IMapSurround pMapSurround = pMapSurrounFrame.MapSurround;
                        //pElement = pMapSurrounFrame.MapSurround as IElement;
                        //  pMapSurround.Map = m_Map;
                        //  m_Map.AddMapSurround(pMapSurround);
                    }
                    if (pMapSurrounFrame.MapSurround.Name == "Alternating Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Stepped Scale Line" || pMapSurrounFrame.MapSurround.Name == "Scale Line" ||
                        pMapSurrounFrame.MapSurround.Name == "Hollow Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Single Division Scale Bar" ||
                        pMapSurrounFrame.MapSurround.Name == "Double Alternating Scale Bar")
                    {
                        // m_Map.MapScale = 5000;
                        IScaleBar pScaleBar = pMapSurrounFrame.MapSurround as IScaleBar;
                        pScaleBar.Map = m_Map;


                        pScaleBar.Units = m_Map.MapUnits;
                        pScaleBar.UseMapSettings();

                        pElement = pMapSurrounFrame.MapSurround as IElement;
                    }
                    if (pMapSurrounFrame.MapSurround.Name == "Scale Text")
                    {
                        IScaleText pScaleText = pMapSurrounFrame.MapSurround as IScaleText;
                        pScaleText.Map = m_Map;
                    }
                    if (pMapSurrounFrame.MapSurround.Name == "North Arrow")
                    {
                        INorthArrow pNorthArrow = pMapSurrounFrame.MapSurround as INorthArrow;

                        pNorthArrow.Map = m_Map;
                    }
                }
                if (pElementProperties.Type == "Data Frame")
                {
                    IFrameElement pFrameElement = pElementProperties as IFrameElement;
                    IMapFrame     pMapframe     = pFrameElement as IMapFrame;
                    // pMapframe.ExtentType = esriExtentTypeEnum.esriExtentBounds;
                    IMapGrids pmapGrids = pMapframe as IMapGrids;
                    IMapGrid  pMapGrid  = null;
                    for (int i = 0; i < pmapGrids.MapGridCount; i++)
                    {
                        pMapGrid = pmapGrids.get_MapGrid(i);
                        //用户要求显示与否
                        pMapGrid.Visible = true;
                    }
                }

                pElementProperties = (IElementProperties)pGraphicsContainer.Next();
            }
            if (axPageLayoutControl1.Page.Orientation == 2)
            {
                IPaper paper;
                paper = new PaperClass();        //create a paper object
                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                paper.Orientation            = 2;
                printer.Paper                = paper;
                axPageLayoutControl1.Printer = printer;

                pageSetupDialog1.PageSettings.Landscape = true;
                pageSetupDialog1.AllowOrientation       = true;
            }
            if (axPageLayoutControl1.Page.Orientation == 1 && axPageLayoutControl1.Printer.Paper.Orientation == 2)
            {
                IPaper paper;
                paper = new PaperClass();        //create a paper object
                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                paper.Orientation                       = 1;
                printer.Paper                           = paper;
                axPageLayoutControl1.Printer            = printer;
                pageSetupDialog1.PageSettings.Landscape = false;
                pageSetupDialog1.AllowOrientation       = true;
            }
        }
    public void PrintActiveViewParameterized(int iResampleRatio)
    {
    
      /* Prints the Active View of the document to selected output format. */
      //          
			IActiveView docActiveView = ArcMap.Document.ActiveView;
      IPrinter docPrinter;
      IPrintAndExport PrintAndExport = new PrintAndExportClass();
      IPaper docPaper;
      /* printdocument is from the .NET assembly system.drawing.printing */
      System.Drawing.Printing.PrintDocument sysPrintDocumentDocument;
      short iNumPages;

      /* Now we need to get the default printer name.  Since this is a generic command,
       * we can't use the printername property of the document.  So instead, we use the 
       * System.Drawing.Printing objects to find the default printer.
       */
      docPrinter = new EmfPrinterClass();
      sysPrintDocumentDocument = new System.Drawing.Printing.PrintDocument();
      docPaper = new PaperClass();

      /* testing to see if printer instantiated in sysPrintDocumentDocument is the 
       * default printer.  It SHOULD be, but this is just a reality check.
       */
      bool isDefault = sysPrintDocumentDocument.PrinterSettings.IsDefaultPrinter;

      if (isDefault)
      {
        //Set docPaper's printername to the printername of the default printer
        docPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName;

      }
      else
      {
        //if we get an unexpected result, return.
        MessageBox.Show("Error getting default printer info, exiting...");
        return;
      }

      //make sure the paper orientation is set to the orientation matching the current view.
			docPaper.Orientation = ArcMap.Document.PageLayout.Page.Orientation;
      
      /* Now assign docPrinter the paper and with it the printername.  This process is two steps
       * because you cannot change an IPrinter's printer except by passing it as a part of 
       * the IPaper.  That's why we setup docPrinter.Paper.PrinterName first.
       */
      docPrinter.Paper = docPaper;

      //set the spoolfilename (this is the job name that shows up in the print queue)
      docPrinter.SpoolFileName = "PrintActiveViewSample";

      // Find out how many printer pages the output will cover. 
			if (ArcMap.Document.ActiveView is IPageLayout)
      {
				ArcMap.Document.PageLayout.Page.PrinterPageCount (docPrinter, 0, out iNumPages);
      }
      else
      {
        iNumPages = 1;
      }

      for (short lCurrentPageNum = 1; lCurrentPageNum <= iNumPages; lCurrentPageNum++)
      {
          try
          {
              PrintAndExport.Print(ArcMap.Document.ActiveView, docPrinter, ArcMap.Document.PageLayout.Page, lCurrentPageNum, iResampleRatio, null);
          }
          catch
          {
              //need to catch exceptions in PrintAndExport.Print - for instance if the job is cancelled.
              MessageBox.Show("An error has occurred.");
          }
      }
       
    }
Example #13
0
        private void printDocument_0_PrintPage(object sender, PrintPageEventArgs e)
        {
            short       dpiX;
            IEnvelope   envelopeClass;
            short       num;
            double      xMin;
            double      yMin;
            double      xMax;
            double      yMax;
            tagRECT     deviceFrame = new tagRECT();
            IEnvelope   visibleBounds;
            IntPtr      hdc;
            WKSEnvelope wKSEnvelope;
            WKSEnvelope wKSEnvelope1;

            if (this._context.ActiveView is IPageLayout)
            {
                IPageLayout2 activeView = this._context.ActiveView as IPageLayout2;
                dpiX          = (short)e.Graphics.DpiX;
                envelopeClass = new EnvelopeClass();
                IPage page = activeView.Page;
                activeView.Page.PrinterPageCount(activeView.Printer, 0, out num);
                CmdPrintPreview short0 = this;
                short0.short_0 = (short)(short0.short_0 + 1);
                IPrinter printer = activeView.Printer;
                page.GetDeviceBounds(printer, this.short_0, 0, dpiX, envelopeClass);
                envelopeClass.QueryCoords(out xMin, out yMin, out xMax, out yMax);
                deviceFrame.bottom = (int)yMax;
                deviceFrame.left   = (int)xMin;
                deviceFrame.top    = (int)yMin;
                deviceFrame.right  = (int)xMax;
                visibleBounds      = new EnvelopeClass();
                page.GetPageBounds(printer, this.short_0, 0, visibleBounds);
                hdc = e.Graphics.GetHdc();
                (activeView as IActiveView).Output(hdc.ToInt32(), dpiX, ref deviceFrame, visibleBounds, this.itrackCancel_0);
                e.Graphics.ReleaseHdc(hdc);
                if (this.short_0 >= num)
                {
                    e.HasMorePages = false;
                    this.short_0   = 0;
                }
                else
                {
                    e.HasMorePages = true;
                }
            }
            else if (this._context.ActiveView is IMap)
            {
                dpiX          = (short)e.Graphics.DpiX;
                envelopeClass = new EnvelopeClass();
                deviceFrame   = this._context.ActiveView.ScreenDisplay.DisplayTransformation.get_DeviceFrame();
                IEnvelope clipEnvelope = this._context.ActiveView.ScreenDisplay.ClipEnvelope;
                visibleBounds = this._context.ActiveView.ScreenDisplay.DisplayTransformation.VisibleBounds;
                visibleBounds.QueryCoords(out xMin, out yMin, out xMax, out yMax);
                hdc = e.Graphics.GetHdc();
                IPrinter      emfPrinterClass = new EmfPrinterClass();
                PrintDocument printDocument   = new PrintDocument();
                IPaper        paperClass      = new PaperClass()
                {
                    PrinterName = printDocument.PrinterSettings.PrinterName
                };
                emfPrinterClass.Paper = paperClass;
                emfPrinterClass.PrintableBounds.QueryWKSCoords(out wKSEnvelope);
                emfPrinterClass.PrintableBounds.QueryWKSCoords(out wKSEnvelope1);
                xMin               = wKSEnvelope1.XMin * (double)dpiX;
                xMax               = wKSEnvelope1.XMax * (double)dpiX;
                yMin               = wKSEnvelope1.YMin * (double)dpiX;
                yMax               = wKSEnvelope1.YMax * (double)dpiX;
                deviceFrame.left   = (int)Math.Round(xMin);
                deviceFrame.top    = (int)Math.Round(yMin);
                deviceFrame.right  = (int)Math.Round(xMax);
                deviceFrame.bottom = (int)Math.Round(yMax);
                try
                {
                    this._context.ActiveView.Output(hdc.ToInt32(), dpiX, ref deviceFrame, null, this.itrackCancel_0);
                }
                catch
                {
                }
                e.Graphics.ReleaseHdc(hdc);
            }
        }
Example #14
0
        private void uiCommandManager1_CommandClick(object sender, Janus.Windows.UI.CommandBars.CommandEventArgs e)
        {
            this.m_mapControl.CurrentTool = null;
            this.StatusBar.Panels[0].Text = "当前任务:" + e.Command.Text.ToString();
            this.m_rasterMeasureDis = false;
            this.m_rasterMeasureArea = false;
            //this.mapCtlMain.CurrentTool = null;
            if (e.Command.Key == "menuExit") //退出程序
            {
                Application.Exit();
            }

            switch (e.Command.CategoryName)
            {

                #region 标准工具栏
                case "Standard":
                    m_toolLib.StandardToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;
                #endregion

                #region 导航工具栏
                case"Navigation":
                    m_toolLib.NavigationToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;
                 #endregion 导航工具栏

                #region 数据库工具栏
                case "DB":
                    m_toolLib.DBToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));

                    break;
                #endregion 数据库工具栏

                #region 工具工具栏
                case "Tool":
                    m_toolLib.ToolToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;
                #endregion 工具工具栏

                case"CallMap":
                    m_toolLib.CallMapToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;

                case"3D":
                    m_toolLib.ThreeDToolLibrary(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;

                case"Index":
                    m_toolLib.IndexToolibrry(e.Command.Key.Substring(4, e.Command.Key.Length - 4));
                    break;
            }

            #region 出图制图栏
            if (e.Command.Key == "menuLegend") //设置比例尺
            {
                DesignPageLayout designPageLayout = new DesignPageLayout(m_mapControl, m_pageLayoutControl);
                designPageLayout.AddLegend();//添加图例
            }

            if (e.Command.Key == "menuText")
            {
                m_designPageLayout = new DesignPageLayout(m_mapControl, m_pageLayoutControl);
                m_designPageLayout.AddText();//添加文字
            }

            if (e.Command.Key == "menuNorthArrow")
            {
                m_designPageLayout = new DesignPageLayout(m_mapControl, m_pageLayoutControl);
                m_designPageLayout.AddNorthArrow();//添加指北针

            }

            if (e.Command.Key == "menuScaleBar")
            {
                m_designPageLayout = new DesignPageLayout(m_pageLayoutControl);
                m_designPageLayout.AddScaleBar();//添加比例尺
            }

            if (e.Command.Key == "menuScaleText")
            {
                m_designPageLayout = new DesignPageLayout(m_pageLayoutControl);
                m_designPageLayout.AddTextScale();//添加文字比例尺

            }

            if (e.Command.Key == "menuMapGrid")
            {
                m_designPageLayout = new DesignPageLayout(m_pageLayoutControl);
                m_designPageLayout.AddMapGrid();//添加地图格网
            }

            if (e.Command.Key == "menuPageAndPrintaSet")
            {
                #region//页面设置
                DialogResult result = pageSetupDialog1.ShowDialog();
                document.PrinterSettings = pageSetupDialog1.PrinterSettings;
                document.DefaultPageSettings = pageSetupDialog1.PageSettings;

                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);
                    }
                }
                IPaper paper;
                paper = new PaperClass(); //create a paper object

                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                printer.Paper = paper;
                m_pageLayoutControl.Printer = printer;
                #endregion
            }

            if (e.Command.Key == "menuPrintView")
            {
                #region//打印预览
                m_CurrentPrintPage = 0;
                if (axPageLayoutControl1.ActiveView.FocusMap == null) return;
                document.DocumentName = axPageLayoutControl1.DocumentFilename;
                printPreviewDialog1.Document = document;
                printPreviewDialog1.ShowDialog();
                #endregion

            }

            if (e.Command.Key == "menuPrintExport")
            {
                #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 == "menuPrintByAnyPolygonRegion")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!", "提示");
                    return;
                }
                ICommand pArePrintMapClass = new ExportMapProj.AreaPrintMapClass(this.mapCtlMain.Map);
                pArePrintMapClass.OnCreate(this.mapCtlMain.Object);
                this.mapCtlMain.CurrentTool = (ITool)pArePrintMapClass;
                mapCtlMain.ActiveView.Refresh();
            }

            if (e.Command.Key == "menuExportMap")
            {
                ICommand pExportMapAsPicture = new ExportMapProj.CmdExoprtMapAsPicture();
                pExportMapAsPicture.OnCreate(m_pageLayoutControl.Object);
                pExportMapAsPicture.OnClick();

            }
            #endregion

            #region 要素编辑
            if (e.Command.Key == "menuStart")
            {

                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先加载数据!");
                    return;
                }
                m_Map = mapCtlMain.Map;

                IFeatureLayer feaLayer = null;
                IDataset dataSet = null;
                IWorkspaceEdit wsEdit = null;
                for (int i = 0; i < m_Map.LayerCount; i++)
                {
                    if (m_Map.get_Layer(i) is IFeatureLayer)
                    {
                        feaLayer = m_Map.get_Layer(i) as IFeatureLayer;
                        dataSet = (IDataset)feaLayer.FeatureClass;
                        wsEdit = dataSet.Workspace as IWorkspaceEdit;
                        uiComboBox5.Items.Add(m_Map.get_Layer(i).Name);
                    }

                    if (wsEdit.IsBeingEdited()==true)
                    {
                        return;
                    }
                }

                this.menuStart.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                this.menuStop2.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuSketch1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuSaveEditing2.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuDelete1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuRedoEditing1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuUndoEditing1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuTask1.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                this.menuLayer1.Enabled = Janus.Windows.UI.InheritableBoolean.True;

                uiComboBox5.SelectedIndex = 0;
                for (int i = 0; i < m_Map.LayerCount; i++)
                {
                    if (m_Map.get_Layer(i).Name == uiComboBox5.Text)
                    {
                        m_CurrentLayer = m_Map.get_Layer(i);
                        break;
                    }
                }
                m_bModify = false;
                m_bSketch = true;
                uiComboBox4.SelectedIndex = 0;
                StartEditing();
                MapEditing.CreatShape m_CreateShapeStart = new CreatShape(m_CurrentLayer,this.m_dig);
                mapCtlMain.CurrentTool = (ITool)m_CreateShapeStart;
                m_CreateShapeStart.OnCreate(this.mapCtlMain.Object);
            }

            if (e.Command.Key == "menuStop")
            {
                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请加载数据!");
                    return;
                }
                if (StopEditing() == 1)
                {
                    mapCtlMain.Map.ClearSelection();
                    mapCtlMain.ActiveView.Refresh();
                    mapCtlMain.MousePointer = esriControlsMousePointer.esriPointerDefault;
                    this.menuStart.Enabled = Janus.Windows.UI.InheritableBoolean.True;
                    this.menuStop2.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuSketch1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuSaveEditing2.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.uiComboBox4.Text = "";
                    this.uiComboBox5.Text ="";
                    this.menuDelete1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuRedoEditing1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuUndoEditing1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuTask1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.menuLayer1.Enabled = Janus.Windows.UI.InheritableBoolean.False;
                    this.uiComboBox5.Items.Clear();
                }
            }

            if (e.Command.Key == "menuSaveEditing")
            {
                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请加载数据!");
                    return;
                }
                if (SaveEditing() == 1)
                {
                    mapCtlMain.Map.ClearSelection();
                    mapCtlMain.ActiveView.Refresh();
                }
            }

            if (e.Command.Key == "menuSketch")        //草图画笔工具
            {
                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请加载数据!");
                    return;
                }
                if (m_bSketch)
                {
                    CreatShape m_CreateShapeSketch = new CreatShape(m_CurrentLayer,this.m_dig);
                    mapCtlMain.CurrentTool = (ITool)m_CreateShapeSketch;
                    m_CreateShapeSketch.OnCreate(this.mapCtlMain.Object);
                }
                else if (m_bModify)
                {
                    ModifyShape m_ModifyShape = new ModifyShape(m_CurrentLayer);
                    mapCtlMain.CurrentTool = (ITool)m_ModifyShape;
                    m_ModifyShape.OnCreate(this.mapCtlMain.Object);
                }
                else if (m_bEditNode)
                {

                }
                else
                {
                    MessageBox.Show("编辑操作尚未开始,请先开始编辑!");
                    return;
                }
                StartEditing();//开始编辑
            }

            if (e.Command.Key == "menuDelete")
            {
                if (mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先加载数据!");
                    return;
                }
                DeleteSelectedFeatures();            //调用删除要素方法
            }

            if (e.Command.Key == "menuUndoEditing")
            {
                if (m_CurrentLayer == null)
                    return;
                IWorkspaceEdit pWorkSpaceEdit = GetWorkspaceEdit();
                bool bHasUndos = false;
                pWorkSpaceEdit.HasUndos(ref bHasUndos);
                if (bHasUndos)
                    pWorkSpaceEdit.UndoEditOperation();
                IActiveView pActiveView = m_Map as IActiveView;
                pActiveView.Refresh();
            }

            if (e.Command.Key == "menuRedoEditing")
            {
                if (m_CurrentLayer == null)
                    return;
                IWorkspaceEdit pWorkSpaceEdit = GetWorkspaceEdit();
                bool bHasRedo = false;
                pWorkSpaceEdit.HasRedos(ref bHasRedo);
                if (bHasRedo)
                    pWorkSpaceEdit.RedoEditOperation();
                IActiveView pActiveView = m_Map as IActiveView;
                pActiveView.Refresh();
            }
            #endregion

            if (e.Command.Key == "menuSelectbyAttribute")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }
                QueryForm pQueryForm = new QueryForm(this.m_mapControl);
                pQueryForm.Show();
            }

            if (e.Command.Key == "menuSelectbyLocation")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }
                SpatialQueryForm pSpatialQueryForm = new SpatialQueryForm(this.m_mapControl);
                pSpatialQueryForm.Show();
            }

            if (e.Command.Key == "menuBuffer")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }
                BufferForm pBufferForm = new BufferForm(this.m_mapControl);
                pBufferForm.Show();
            }

            if (e.Command.Key == "menuOverLay")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }
                OverLayerForm pOverLayerForm = new OverLayerForm(this.m_mapControl);
                pOverLayerForm.Show();
            }

            if (e.Command.Key == "menu3DForm")
            {
                if (e.Command.Checked == Janus.Windows.UI.InheritableBoolean.False)
                {
                    this.ThreeDtap.TabVisible = true;
                    this.mapTab.Enabled = false;
                    this.pageTab.Enabled = false;
                    this.uiTab1.SelectedTab = this.ThreeDtap;

                    this.ThreeDBar.Visible = true;

                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.True;
                    this.axTOCControl1.SetBuddyControl(this.axSceneControl1);
                }
                else
                {
                    this.ThreeDtap.TabVisible = false;
                    this.mapTab.Enabled = true;
                    this.pageTab.Enabled = true;
                    this.uiTab1.SelectedTab = this.mapTab;
                    this.ThreeDBar.Visible = false;
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.False;
                    this.axSceneControl1.CurrentTool = null;
                    this.axSceneControl1.Scene.ClearLayers();
                    this.axTOCControl1.SetBuddyControl(this.mapCtlMain);
                }

            }

            if (e.Command.Key == "menuCacu")
            {
                if (this.mapCtlMain.LayerCount == 0)
                {
                    MessageBox.Show("请先添加数据!");
                    return;
                }

                ICommand ff = new AreaPrintMapClass();
                ff.OnCreate(this.m_mapControl);
                this.m_mapControl.CurrentTool = (ITool)ff;

            }

            if (e.Command.Key == "menuRasDis")
            {
                this.mapCtlMain.CurrentTool = null;
                bool isRaster = false;
                ILayer layer = null;
                for (int i = 0; i < this.mapCtlMain.LayerCount; i++)
                {
                    layer = this.mapCtlMain.get_Layer(i);
                    if (layer is IRasterLayer)
                    {
                        isRaster = true;
                        break;
                    }
                }
                if (isRaster == false)
                {
                    MessageBox.Show("请先添加影像数据!", "提示");
                    return;
                }
                this.m_rasterMeasureDis = true;
                this.mapCtlMain.MousePointer = esriControlsMousePointer.esriPointerCrosshair;

            }

            if (e.Command.Key == "menuRasArea")
            {
                this.mapCtlMain.CurrentTool = null;
                bool isRaster = false;
                ILayer layer = null;

                for (int i = 0; i < this.mapCtlMain.LayerCount; i++)
                {
                    layer = this.mapCtlMain.get_Layer(i);
                    if (layer is IRasterLayer)
                    {
                        isRaster = true;
                        break;
                    }
                }
                if (isRaster == false)
                {
                    MessageBox.Show("请先添加影像数据!", "提示");
                    return;
                }
                this.m_rasterMeasureArea = true;
                this.mapCtlMain.MousePointer = esriControlsMousePointer.esriPointerCrosshair;
            }

            if (e.Command.Key == "menuTemplate")
            {
                ChoseTemple chosetem = new ChoseTemple();
                chosetem.ShowDialog();
                if (chosetem.m_templateName != "")
                {
                    this.axPageLayoutControl1.ActiveView.Clear();
                    if (chosetem.m_templateName.Contains("\\"))
                    {
                        this.axPageLayoutControl1.LoadMxFile(chosetem.m_templateName, Type.Missing);
                    }
                    else
                    {
                        this.axPageLayoutControl1.LoadMxFile(System.Windows.Forms.Application.StartupPath + @"\pagelayoutTemplate\" + chosetem.m_templateName, Type.Missing);
                    }
                    m_controlsSynchronizer.ReplaceMap(m_mapControl.Map);//重新联动

                    SetMapFrame();
                    m_pageLayoutControl.ActiveView.ShowScrollBars = true;

                }
            }

            if (e.Command.Key == "menuAbout")
            {
                frmAbout frmAbout = new frmAbout();
                frmAbout.ShowDialog();
            }

            if (e.Command.Key == "menuTOCControl")
            {
                if (this.menuTOCControl1.Checked == Janus.Windows.UI.InheritableBoolean.True)
                {
                    this.TOCPanel.Visible = false;
                    this.menuTOCControl1.Checked = Janus.Windows.UI.InheritableBoolean.False;
                }
                else
                {
                    this.TOCPanel.Visible = true;
                    this.menuTOCControl1.Checked = Janus.Windows.UI.InheritableBoolean.True;
                }
            }

            if (e.Command.Key == "menuAtrriWin")
            {
                if (this.menuAtrriWin1.Checked == Janus.Windows.UI.InheritableBoolean.True)
                {
                    this.SearchPanel.Closed = true;
                    this.menuAtrriWin1.Checked = Janus.Windows.UI.InheritableBoolean.False;
                }
                else
                {
                    this.SearchPanel.Closed = false;
                    this.menuAtrriWin1.Checked = Janus.Windows.UI.InheritableBoolean.True;
                }
            }

            if (e.Command.Key == "menuOut")
            {
                if (e.Command.Checked == Janus.Windows.UI.InheritableBoolean.True)
                {
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.False;
                    m_out = false;
                }
                else
                {
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.True;
                    m_out = true;
                    this.mapCtlMain.ClearLayers();

                    IWorkspaceFactory workspaceFactory = new RasterWorkspaceFactory();
                    IWorkspace workspace;
                    workspace = workspaceFactory.OpenFromFile(Application.StartupPath + "\\out", 0); //inPath栅格数据存储路径
                    IRasterWorkspace rastWork = (IRasterWorkspace)workspace;
                    IRasterDataset rastDataset;
                    rastDataset = rastWork.OpenRasterDataset("ps2010.img");//inName栅格文件名
                    IRasterLayer layer = new RasterLayerClass();
                    layer.CreateFromDataset(rastDataset);
                    m_mapControl.AddLayer(layer, 0);
                    m_mapControl.AddShapeFile(Application.StartupPath + "\\out", "WYDCZL.shp");

                    m_mapControl.ActiveView.Refresh();
                }

            }
            if (e.Command.Key == "menuDig")
            {
                if (e.Command.Checked == Janus.Windows.UI.InheritableBoolean.False)
                {
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.True;
                    this.m_dig = true;
                }
                else
                {
                    e.Command.Checked = Janus.Windows.UI.InheritableBoolean.False;
                    this.m_dig = false;
                }
            }

            if (e.Command.Key == "menuIndexCacu")
            {
                frmCacuIndex index = new frmCacuIndex();
                index.ShowDialog();
            }

            if (e.Command.Key == "menuSKC")
            {
                frmChart chart = new frmChart(this.m_oraCmd);
                chart.ShowDialog();
            }
            //******************************增加----陈*************************************************
            //if (e.Command.Key == "menuKMEANS")
            //{
            //    KMEANS kMEANS = new KMEANS(m_mapControl);
            //    kMEANS.ShowDialog();
            //}
            //if (e.Command.Key == "menuCalibration")
            //{
            //    OpenFileDialog openGD = new OpenFileDialog();
            //    openGD.Filter = "ERDAS格式(*.img)|*.img|所有文件|*.*";
            //    if (openGD.ShowDialog() == DialogResult.OK)
            //    {
            //        string filename = openGD.FileName;
            //        int bandCount;
            //        try
            //        {
            //            IRasterLayer rasterLayer = new RasterLayerClass();
            //            rasterLayer.CreateFromFilePath(filename);
            //            bandCount = rasterLayer.BandCount;
            //        }
            //        catch
            //        {
            //            MessageBox.Show("输入文件有误");
            //            return;
            //        }
            //        Calibration cali = new Calibration(filename, bandCount, m_mapControl);
            //        cali.ShowDialog();
            //    }

            //}
            //if (e.Command.Key == "menuISODATA")
            //{
            //    ISODATA isodata = new ISODATA(m_mapControl);
            //    isodata.ShowDialog();
            //}
            //if (e.Command.Key == "menuNDVI")
            //{
            //    NDVI ndvi = new NDVI(m_mapControl);
            //    ndvi.ShowDialog();
            //}
            //if (e.Command.Key == "menuRVI")
            //{
            //    RVI rvi = new RVI(m_mapControl);
            //    rvi.ShowDialog();
            //}
            //if (e.Command.Key == "menuSAVI")
            //{
            //    SAVI savi = new SAVI(m_mapControl);
            //    savi.ShowDialog();
            //}
            //if (e.Command.Key == "menuVC")
            //{
            //    VegCover vegCover = new VegCover(m_mapControl);
            //    vegCover.ShowDialog();
            //}
            //if (e.Command.Key == "menuTemprature")
            //{
            //    Temperature temperature = new Temperature(m_mapControl);
            //    temperature.ShowDialog();
            //}
            //if (e.Command.Key == "menuChangeD")
            //{
            //    ChangeDetection changeD = new ChangeDetection(m_mapControl);
            //    changeD.ShowDialog();

            //}
            //if (e.Command.Key == "menuIce")
            //{
            //    IceExtract iceExtract = new IceExtract(m_mapControl);
            //    iceExtract.ShowDialog();
            //}
            //if (e.Command.Key == "menuWater")
            //{
            //    WaterExtract waterExtract = new WaterExtract(m_mapControl);
            //    waterExtract.ShowDialog();

            //}
            //if (e.Command.Key == "menuHOT")
            //{
            //    HOT hot = new HOT(m_mapControl);
            //    hot.ShowDialog();

            //}
            //if (e.Command.Key == "menuQAC")
            //{
            //    QAC qac = new QAC(m_mapControl);
            //    qac.ShowDialog();
            //}
            //if (e.Command.Key == "menuLUC")
            //{
            //    LandUseChange luc = new LandUseChange(m_mapControl);
            //    luc.ShowDialog();
            //}
            //if (e.Command.Key == "menuComposite")
            //{
            //    Composite comp = new Composite(m_mapControl);
            //    comp.ShowDialog();
            //}
            //*****************************************************************************************
        }
Example #15
0
        public void PrintMultiPageParameterized(long iResampleRatio)
        {
            /* Prints tiled map by using IPrinterMPage. */

            IActiveView           docActiveView = ArcMap.Document.ActiveView;
            IPrinter              docPrinter;
            long                  iPrevOutputImageQuality;
            IOutputRasterSettings docOutputRasterSettings;
            tagRECT               deviceRECT;
            IPaper                docPaper;

            /* printdocument is from the .NET assembly system.drawing.printing */
            System.Drawing.Printing.PrintDocument sysPrintDocumentDocument;


            short     iNumPages;
            IEnvelope docPrinterBounds;
            IEnvelope VisibleBounds;


            docPrinterBounds = new EnvelopeClass();
            VisibleBounds    = new EnvelopeClass();

            // save the previous output image quality, so that when the export is complete it will be set back.
            docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
            iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;

            SetOutputQuality(docActiveView, iResampleRatio);


            /* Now we need to get the default printer name.  Since this is a generic command,
             * we can't use the printername property of the document.  So instead, we use the
             * System.Drawing.Printing objects to find the default printer.
             */
            docPrinter = new EmfPrinterClass();
            sysPrintDocumentDocument = new System.Drawing.Printing.PrintDocument();
            docPaper = new PaperClass();

            /* testing to see if printer instantiated in sysPrintDocumentDocument is the
             * default printer.  It SHOULD be, but this is just a reality check.
             */
            bool isDefault = sysPrintDocumentDocument.PrinterSettings.IsDefaultPrinter;

            if (isDefault)
            {
                //Set docPaper's printername to the printername of the default printer
                docPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName;
            }
            else
            {
                //if we get an unexpected result, return.
                MessageBox.Show("Error getting default printer info, exiting...");
                return;
            }


            //make sure the paper orientation is set to the orientation matching the current view.
            docPaper.Orientation = ArcMap.Document.PageLayout.Page.Orientation;

            /* Now assign docPrinter the paper and with it the printername.  This process is two steps
             * because you cannot change an IPrinter's printer except by passing it as a part of
             * the IPaper.  That's why we setup docPrinter.Paper.PrinterName first.
             */
            docPrinter.Paper = docPaper;

            //set the spoolfilename (this is the job name that shows up in the print queue)
            docPrinter.SpoolFileName = "PrintActiveViewSample";

            // Get the printer's hDC, so we can use the Win32 GetDeviceCaps function to
            //  get Printer's Physical Printable Area x and y margins
            int hInfoDC;

            hInfoDC = CreateDC(docPrinter.DriverName, docPrinter.Paper.PrinterName, "", IntPtr.Zero);

            // Find out how many printer pages the output will cover.
            if (ArcMap.Document.ActiveView is IPageLayout)
            {
                ArcMap.Document.PageLayout.Page.PrinterPageCount(docPrinter, 0, out iNumPages);
            }
            else
            {
                iNumPages = 1;
            }

            if (iNumPages < 2)
            {
                MessageBox.Show("Sample requires map in Layout View and map to be tiled to printer paper");
                return;
            }

            IPrinterMPage PrintMPage;
            int           intPageHandle;

            PrintMPage = docPrinter as IPrinterMPage;

            // Code inside StartMapDocument <-----> EndMapDocument is hard coded to print the first two pages of the tiled print
            // Printer and Page Bounds need to be calculated for each corresponding tile that gets printed

            PrintMPage.StartMapDocument();

            //calculate printer bounds for the first page
            ArcMap.Document.PageLayout.Page.GetDeviceBounds(docPrinter, 1, 0, docPrinter.Resolution, docPrinterBounds); // get device bounds of the first page

            //Transfer PrinterBounds envelope, offsetting by PHYSICALOFFSETX
            // the Win32 constant for PHYSICALOFFSETX is 112
            // the Win32 constant for PHYSICALOFFSETY is 113
            deviceRECT.bottom = (int)(docPrinterBounds.YMax - GetDeviceCaps(hInfoDC, 113));
            deviceRECT.left   = (int)(docPrinterBounds.XMin - GetDeviceCaps(hInfoDC, 112));
            deviceRECT.right  = (int)(docPrinterBounds.XMax - GetDeviceCaps(hInfoDC, 112));
            deviceRECT.top    = (int)(docPrinterBounds.YMin - GetDeviceCaps(hInfoDC, 113));

            // Transfer offsetted PrinterBounds envelope back to the deviceRECT
            docPrinterBounds.PutCoords(0, 0, deviceRECT.right - deviceRECT.left, deviceRECT.bottom - deviceRECT.top);

            if (ArcMap.Document.ActiveView is IPageLayout)
            {
                //get the visible bounds for this layout, based on the current page number.
                ArcMap.Document.PageLayout.Page.GetPageBounds(docPrinter, 1, 0, VisibleBounds); // get visible bounds of the first page
            }
            else
            {
                MessageBox.Show("Please Use Map Layout View for this Sample");
                return;
            }

            // start printing the first page bracket, returns handle of the current page.
            // handle is then passed to the ActiveView.Output()
            intPageHandle = PrintMPage.StartPage(docPrinterBounds, hInfoDC);

            ArcMap.Document.ActiveView.Output(intPageHandle, docPrinter.Resolution, ref deviceRECT, VisibleBounds, null);

            PrintMPage.EndPage(); //end printing the first page bracket


            // calculate printer bounds for the second page
            ArcMap.Document.PageLayout.Page.GetDeviceBounds(docPrinter, 2, 0, docPrinter.Resolution, docPrinterBounds); // get device bounds of the first page

            //Transfer PrinterBounds envelope, offsetting by PHYSICALOFFSETX
            // the Win32 constant for PHYSICALOFFSETX is 112
            // the Win32 constant for PHYSICALOFFSETY is 113
            deviceRECT.bottom = (int)(docPrinterBounds.YMax - GetDeviceCaps(hInfoDC, 113));
            deviceRECT.left   = (int)(docPrinterBounds.XMin - GetDeviceCaps(hInfoDC, 112));
            deviceRECT.right  = (int)(docPrinterBounds.XMax - GetDeviceCaps(hInfoDC, 112));
            deviceRECT.top    = (int)(docPrinterBounds.YMin - GetDeviceCaps(hInfoDC, 113));

            // Transfer offsetted PrinterBounds envelope back to the deviceRECT
            docPrinterBounds.PutCoords(0, 0, deviceRECT.right - deviceRECT.left, deviceRECT.bottom - deviceRECT.top);

            if (ArcMap.Document.ActiveView is IPageLayout)
            {
                //get the visible bounds for this layout, based on the current page number.
                ArcMap.Document.PageLayout.Page.GetPageBounds(docPrinter, 2, 0, VisibleBounds); // get visible bounds of the first page
            }
            else
            {
                MessageBox.Show("Please Use Map Layout View for this Sample");
                return;
            }

            // start printing the second page bracket, returns handle of the current page.
            // handle is then passed to the ActiveView.Output()
            intPageHandle = PrintMPage.StartPage(VisibleBounds, hInfoDC);

            ArcMap.Document.ActiveView.Output(intPageHandle, docPrinter.Resolution, ref deviceRECT, VisibleBounds, null);

            PrintMPage.EndPage();   //end printing the second page bracket



            PrintMPage.EndMapDocument();


            //now set the output quality back to the previous output quality.
            SetOutputQuality(docActiveView, iPrevOutputImageQuality);

            //release the DC...
            ReleaseDC(0, hInfoDC);
        }
Example #16
0
        public void PrintActiveViewParameterized(int iResampleRatio)
        {
            /* Prints the Active View of the document to selected output format. */
            //
            IActiveView     docActiveView = ArcMap.Document.ActiveView;
            IPrinter        docPrinter;
            IPrintAndExport PrintAndExport = new PrintAndExportClass();
            IPaper          docPaper;

            /* printdocument is from the .NET assembly system.drawing.printing */
            System.Drawing.Printing.PrintDocument sysPrintDocumentDocument;
            short iNumPages;

            /* Now we need to get the default printer name.  Since this is a generic command,
             * we can't use the printername property of the document.  So instead, we use the
             * System.Drawing.Printing objects to find the default printer.
             */
            docPrinter = new EmfPrinterClass();
            sysPrintDocumentDocument = new System.Drawing.Printing.PrintDocument();
            docPaper = new PaperClass();

            /* testing to see if printer instantiated in sysPrintDocumentDocument is the
             * default printer.  It SHOULD be, but this is just a reality check.
             */
            bool isDefault = sysPrintDocumentDocument.PrinterSettings.IsDefaultPrinter;

            if (isDefault)
            {
                //Set docPaper's printername to the printername of the default printer
                docPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName;
            }
            else
            {
                //if we get an unexpected result, return.
                MessageBox.Show("Error getting default printer info, exiting...");
                return;
            }

            //make sure the paper orientation is set to the orientation matching the current view.
            docPaper.Orientation = ArcMap.Document.PageLayout.Page.Orientation;

            /* Now assign docPrinter the paper and with it the printername.  This process is two steps
             * because you cannot change an IPrinter's printer except by passing it as a part of
             * the IPaper.  That's why we setup docPrinter.Paper.PrinterName first.
             */
            docPrinter.Paper = docPaper;

            //set the spoolfilename (this is the job name that shows up in the print queue)
            docPrinter.SpoolFileName = "PrintActiveViewSample";

            // Find out how many printer pages the output will cover.
            if (ArcMap.Document.ActiveView is IPageLayout)
            {
                ArcMap.Document.PageLayout.Page.PrinterPageCount(docPrinter, 0, out iNumPages);
            }
            else
            {
                iNumPages = 1;
            }

            for (short lCurrentPageNum = 1; lCurrentPageNum <= iNumPages; lCurrentPageNum++)
            {
                try
                {
                    PrintAndExport.Print(ArcMap.Document.ActiveView, docPrinter, ArcMap.Document.PageLayout.Page, lCurrentPageNum, iResampleRatio, null);
                }
                catch
                {
                    //need to catch exceptions in PrintAndExport.Print - for instance if the job is cancelled.
                    MessageBox.Show("An error has occurred.");
                }
            }
        }
Example #17
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();
            }
        }
    public void PrintMultiPageParameterized(long iResampleRatio)
    {

      /* Prints tiled map by using IPrinterMPage. */
        
      IActiveView docActiveView = ArcMap.Document.ActiveView;
      IPrinter docPrinter;
      long iPrevOutputImageQuality;
      IOutputRasterSettings docOutputRasterSettings;
      tagRECT deviceRECT;
      IPaper docPaper;
      /* printdocument is from the .NET assembly system.drawing.printing */
      System.Drawing.Printing.PrintDocument sysPrintDocumentDocument;


      short iNumPages;
      IEnvelope docPrinterBounds;
      IEnvelope VisibleBounds;


      docPrinterBounds = new EnvelopeClass();
      VisibleBounds = new EnvelopeClass();

      // save the previous output image quality, so that when the export is complete it will be set back.
      docOutputRasterSettings = docActiveView.ScreenDisplay.DisplayTransformation as IOutputRasterSettings;
      iPrevOutputImageQuality = docOutputRasterSettings.ResampleRatio;

      SetOutputQuality(docActiveView, iResampleRatio);


      /* Now we need to get the default printer name.  Since this is a generic command,
       * we can't use the printername property of the document.  So instead, we use the 
       * System.Drawing.Printing objects to find the default printer.
       */
      docPrinter = new EmfPrinterClass();
      sysPrintDocumentDocument = new System.Drawing.Printing.PrintDocument();
      docPaper = new PaperClass();

      /* testing to see if printer instantiated in sysPrintDocumentDocument is the 
       * default printer.  It SHOULD be, but this is just a reality check.
       */
      bool isDefault = sysPrintDocumentDocument.PrinterSettings.IsDefaultPrinter;

      if (isDefault)
      {
        //Set docPaper's printername to the printername of the default printer
        docPaper.PrinterName = sysPrintDocumentDocument.PrinterSettings.PrinterName;

      }
      else
      {
        //if we get an unexpected result, return.
        MessageBox.Show("Error getting default printer info, exiting...");
        return;
      }


      //make sure the paper orientation is set to the orientation matching the current view.
      docPaper.Orientation = ArcMap.Document.PageLayout.Page.Orientation;

      /* Now assign docPrinter the paper and with it the printername.  This process is two steps
       * because you cannot change an IPrinter's printer except by passing it as a part of 
       * the IPaper.  That's why we setup docPrinter.Paper.PrinterName first.
       */
      docPrinter.Paper = docPaper;

      //set the spoolfilename (this is the job name that shows up in the print queue)
      docPrinter.SpoolFileName = "PrintActiveViewSample";

      // Get the printer's hDC, so we can use the Win32 GetDeviceCaps function to
      //  get Printer's Physical Printable Area x and y margins
      int hInfoDC;
      hInfoDC = CreateDC(docPrinter.DriverName, docPrinter.Paper.PrinterName, "", IntPtr.Zero);

      // Find out how many printer pages the output will cover. 
      if (ArcMap.Document.ActiveView is IPageLayout)
      {
        ArcMap.Document.PageLayout.Page.PrinterPageCount(docPrinter, 0, out iNumPages);
      }
      else
      {
        iNumPages = 1;
      }
      
      if (iNumPages < 2)
      {
        MessageBox.Show("Sample requires map in Layout View and map to be tiled to printer paper");
        return;
      }

      IPrinterMPage PrintMPage;
      int intPageHandle;
      
      PrintMPage = docPrinter as IPrinterMPage;

      // Code inside StartMapDocument <-----> EndMapDocument is hard coded to print the first two pages of the tiled print
      // Printer and Page Bounds need to be calculated for each corresponding tile that gets printed

      PrintMPage.StartMapDocument();  

          //calculate printer bounds for the first page
          ArcMap.Document.PageLayout.Page.GetDeviceBounds(docPrinter, 1, 0, docPrinter.Resolution, docPrinterBounds); // get device bounds of the first page

          //Transfer PrinterBounds envelope, offsetting by PHYSICALOFFSETX
          // the Win32 constant for PHYSICALOFFSETX is 112
          // the Win32 constant for PHYSICALOFFSETY is 113
          deviceRECT.bottom = (int)(docPrinterBounds.YMax - GetDeviceCaps(hInfoDC, 113));
          deviceRECT.left = (int)(docPrinterBounds.XMin - GetDeviceCaps(hInfoDC, 112));
          deviceRECT.right = (int)(docPrinterBounds.XMax - GetDeviceCaps(hInfoDC, 112));
          deviceRECT.top = (int)(docPrinterBounds.YMin - GetDeviceCaps(hInfoDC, 113));

          // Transfer offsetted PrinterBounds envelope back to the deviceRECT
          docPrinterBounds.PutCoords(0, 0, deviceRECT.right - deviceRECT.left, deviceRECT.bottom - deviceRECT.top);

          if (ArcMap.Document.ActiveView is IPageLayout)
          {
            //get the visible bounds for this layout, based on the current page number.
            ArcMap.Document.PageLayout.Page.GetPageBounds(docPrinter, 1, 0, VisibleBounds); // get visible bounds of the first page
          }
          else
          {
            MessageBox.Show("Please Use Map Layout View for this Sample");
            return;
          }

          // start printing the first page bracket, returns handle of the current page.  
          // handle is then passed to the ActiveView.Output()
          intPageHandle = PrintMPage.StartPage(docPrinterBounds, hInfoDC);
                
                ArcMap.Document.ActiveView.Output(intPageHandle, docPrinter.Resolution, ref deviceRECT, VisibleBounds, null);
          
          PrintMPage.EndPage(); //end printing the first page bracket

          
          // calculate printer bounds for the second page
          ArcMap.Document.PageLayout.Page.GetDeviceBounds(docPrinter, 2, 0, docPrinter.Resolution, docPrinterBounds); // get device bounds of the first page
          
          //Transfer PrinterBounds envelope, offsetting by PHYSICALOFFSETX
          // the Win32 constant for PHYSICALOFFSETX is 112
          // the Win32 constant for PHYSICALOFFSETY is 113
          deviceRECT.bottom = (int)(docPrinterBounds.YMax - GetDeviceCaps(hInfoDC, 113));
          deviceRECT.left = (int)(docPrinterBounds.XMin - GetDeviceCaps(hInfoDC, 112));
          deviceRECT.right = (int)(docPrinterBounds.XMax - GetDeviceCaps(hInfoDC, 112));
          deviceRECT.top = (int)(docPrinterBounds.YMin - GetDeviceCaps(hInfoDC, 113));

          // Transfer offsetted PrinterBounds envelope back to the deviceRECT
          docPrinterBounds.PutCoords(0, 0, deviceRECT.right - deviceRECT.left, deviceRECT.bottom - deviceRECT.top);

          if (ArcMap.Document.ActiveView is IPageLayout)
          {
            //get the visible bounds for this layout, based on the current page number.
            ArcMap.Document.PageLayout.Page.GetPageBounds(docPrinter, 2, 0, VisibleBounds); // get visible bounds of the first page
          }
          else
          {
            MessageBox.Show("Please Use Map Layout View for this Sample");
            return;
          }

          // start printing the second page bracket, returns handle of the current page.  
          // handle is then passed to the ActiveView.Output()
          intPageHandle = PrintMPage.StartPage(VisibleBounds, hInfoDC);
              
              ArcMap.Document.ActiveView.Output(intPageHandle, docPrinter.Resolution, ref deviceRECT, VisibleBounds, null);

              PrintMPage.EndPage(); //end printing the second page bracket

       

      PrintMPage.EndMapDocument();


      //now set the output quality back to the previous output quality.
      SetOutputQuality(docActiveView, iPrevOutputImageQuality);

      //release the DC...
      ReleaseDC(0, hInfoDC);
    }
Example #19
0
        //设置地图基本信息,如比例尺,图例等:
        private void SetMapFrame()
        {
            IGraphicsContainer pGraphicsContainer = (IGraphicsContainer)this.axPageLayoutControl1.ActiveView;
            pGraphicsContainer.Reset();
            IElementProperties pElementProperties = (IElementProperties)pGraphicsContainer.Next();
            while (pElementProperties != null)
            {
                if (pElementProperties.Type == "Map Surround Frame")
                {

                    IMapSurroundFrame pMapSurrounFrame = pElementProperties as IMapSurroundFrame;
                    IElement pElement = (IElement)pElementProperties;

                    if (pMapSurrounFrame.MapSurround.Name.Trim() == "Legend")
                    {
                        ILegend pLegend = pMapSurrounFrame.MapSurround as ILegend;
                        pLegend.Map = this.mapCtlMain.Map;

                    }
                    if (pMapSurrounFrame.MapSurround.Name == "Alternating Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Stepped Scale Line" || pMapSurrounFrame.MapSurround.Name == "Scale Line" ||
                        pMapSurrounFrame.MapSurround.Name == "Hollow Scale Bar" || pMapSurrounFrame.MapSurround.Name == "Single Division Scale Bar" ||
                        pMapSurrounFrame.MapSurround.Name == "Double Alternating Scale Bar")
                    {
                        // m_Map.MapScale = 5000;
                        IScaleBar pScaleBar = pMapSurrounFrame.MapSurround as IScaleBar;
                        pScaleBar.Map = this.mapCtlMain.Map;

                        pScaleBar.Units = this.mapCtlMain.Map.MapUnits;
                        pScaleBar.UseMapSettings();

                        pElement = pMapSurrounFrame.MapSurround as IElement;

                    }
                    if (pMapSurrounFrame.MapSurround.Name == "Scale Text")
                    {
                        IScaleText pScaleText = pMapSurrounFrame.MapSurround as IScaleText;
                        pScaleText.Map = this.mapCtlMain.Map;
                    }
                    if (pMapSurrounFrame.MapSurround.Name == "North Arrow")
                    {
                        INorthArrow pNorthArrow = pMapSurrounFrame.MapSurround as INorthArrow;

                        pNorthArrow.Map = this.mapCtlMain.Map;
                    }
                }
                if (pElementProperties.Type == "Data Frame")
                {
                    IFrameElement pFrameElement = pElementProperties as IFrameElement;
                    IMapFrame pMapframe = pFrameElement as IMapFrame;
                    // pMapframe.ExtentType = esriExtentTypeEnum.esriExtentBounds;
                    IMapGrids pmapGrids = pMapframe as IMapGrids;
                    IMapGrid pMapGrid = null;
                    for (int i = 0; i < pmapGrids.MapGridCount; i++)
                    {
                        pMapGrid = pmapGrids.get_MapGrid(i);
                        //用户要求显示与否
                        pMapGrid.Visible = true;
                    }
                }

                pElementProperties = (IElementProperties)pGraphicsContainer.Next();
            }
            if (axPageLayoutControl1.Page.Orientation == 2)
            {
                IPaper paper;
                paper = new PaperClass(); //create a paper object
                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                paper.Orientation = 2;
                printer.Paper = paper;
                axPageLayoutControl1.Printer = printer;

                pageSetupDialog1.PageSettings.Landscape = true;
                pageSetupDialog1.AllowOrientation = true;

            }
            if (axPageLayoutControl1.Page.Orientation == 1 && axPageLayoutControl1.Printer.Paper.Orientation == 2)
            {
                IPaper paper;
                paper = new PaperClass(); //create a paper object
                IPrinter printer;
                printer = new EmfPrinterClass(); //create a printer object
                paper.Attach(pageSetupDialog1.PrinterSettings.GetHdevmode(pageSetupDialog1.PageSettings).ToInt32(), pageSetupDialog1.PrinterSettings.GetHdevnames().ToInt32());
                paper.Orientation = 1;
                printer.Paper = paper;
                axPageLayoutControl1.Printer = printer;
                pageSetupDialog1.PageSettings.Landscape = false;
                pageSetupDialog1.AllowOrientation = true;
            }
        }