Exemplo n.º 1
0
        private void tsbPrintSetup_Click(object sender, EventArgs e)
        {
            try
            {
                GetSurroundPose();
                //显示打印设置页对话框
                DialogResult result = m_pageSetupDialog.ShowDialog();

                //设置预览文档属性
                m_PrintDocument.PrinterSettings     = m_pageSetupDialog.PrinterSettings;
                m_PrintDocument.DefaultPageSettings = m_pageSetupDialog.PageSettings;

                //遍历查找所选择的页面大小
                int         i;
                IEnumerator paperSizes = m_pageSetupDialog.PrinterSettings.PaperSizes.GetEnumerator();
                paperSizes.Reset();

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

                ///////////////////////////////////
                ///根据打印设置选项初始化当前打印机
                ///////////////////////////////////
                IPaper paper;
                paper = new Paper() as IPaper; //初始化页面

                IPrinter printer;
                printer = new EmfPrinter() as IPrinter; //初始化打印机

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

                //将页面传给打印机
                printer.Paper = paper;

                //设置PageLayoutControl打印机
                axPageLayoutControl1.Printer = printer;
                if (axPageLayoutControl1.Page.Orientation != printer.Paper.Orientation)
                {
                    axPageLayoutControl1.Page.Orientation = printer.Paper.Orientation;
                    IMapFrame mapFram  = axPageLayoutControl1.ActiveView.GraphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame;
                    IElement  element  = mapFram as IElement;
                    IEnvelope envelope = new EnvelopeClass();
                    envelope.XMax    = element.Geometry.Envelope.YMax;
                    envelope.XMin    = element.Geometry.Envelope.YMin;
                    envelope.YMax    = element.Geometry.Envelope.XMax;
                    envelope.YMin    = element.Geometry.Envelope.YMin;
                    element.Geometry = envelope;
                    UpdataSurroundPose();
                    //axPageLayoutControl1.ActiveView.Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        private void tsbPrintSetup_Click(object sender, EventArgs e)
        {
            try
            {
                GetSurroundPose();
                //显示打印设置页对话框
                DialogResult result = m_pageSetupDialog.ShowDialog();

                //设置预览文档属性
                m_PrintDocument.PrinterSettings = m_pageSetupDialog.PrinterSettings;
                m_PrintDocument.DefaultPageSettings = m_pageSetupDialog.PageSettings;

                //遍历查找所选择的页面大小
                int i;
                IEnumerator paperSizes = m_pageSetupDialog.PrinterSettings.PaperSizes.GetEnumerator();
                paperSizes.Reset();

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

                ///////////////////////////////////
                ///根据打印设置选项初始化当前打印机
                ///////////////////////////////////
                IPaper paper;
                paper = new Paper() as IPaper; //初始化页面

                IPrinter printer;
                printer = new EmfPrinter() as IPrinter; //初始化打印机

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

                //将页面传给打印机
                printer.Paper = paper;

                //设置PageLayoutControl打印机
                axPageLayoutControl1.Printer = printer;
                if (axPageLayoutControl1.Page.Orientation != printer.Paper.Orientation)
                {
                    axPageLayoutControl1.Page.Orientation = printer.Paper.Orientation;
                    IMapFrame mapFram = axPageLayoutControl1.ActiveView.GraphicsContainer.FindFrame(axPageLayoutControl1.ActiveView.FocusMap) as IMapFrame;
                    IElement element = mapFram as IElement;
                    IEnvelope envelope = new EnvelopeClass();
                    envelope.XMax = element.Geometry.Envelope.YMax;
                    envelope.XMin = element.Geometry.Envelope.YMin;
                    envelope.YMax = element.Geometry.Envelope.XMax;
                    envelope.YMin = element.Geometry.Envelope.YMin;
                    element.Geometry = envelope;
                    UpdataSurroundPose();
                    //axPageLayoutControl1.ActiveView.Refresh();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }