1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132 |
-
- using System;
- using Tofly.Core.Stereotype;
- using Tofly.CoreUI.Message;
- using Tofly.OutputUI.Form;
- using Tofly.Core.Context.Support;
- using Tofly.GISUI.Controls;
- using System.Collections.Generic;
- using System.Drawing.Printing;
- using System.Data;
- using System.Management;
- using Tofly.GIS.Carto;
- using Tofly.GIS;
- using Tofly.GIS.Geometry;
- using Tofly.GIS.Display;
- using System.Drawing;
- namespace Tofly.OutputUI
- {
-
-
-
- [Component(IsSingleton = "false", Name = "PageSetClass")]
- public class PageSetClass : IPageSet
- {
- #region 构造
- private IPageSetForm pPageSetForm;
- private IPageLayoutControl pPageLayoutControl;
- private Dictionary<int, int> m_PaperFormID = new Dictionary<int, int>();
- private double m_MaxWidth;
- private double m_MaxHeight;
- private Units m_CurrentUnit;
- private short m_lOldFormID;
- private int m_iOldPaperOrientation;
- private string m_oldPrinterName = "";
- public PageSetClass()
- {
- pPageSetForm = ContextRegistry.GetContext().GetObject("PageSetForm") as IPageSetForm;
- pPageSetForm.PaperCombox.SelectedIndexChangedEvent += new CoreUI.Control.DataListSelectChanged(PaperCombox_SelectedIndexChangedEvent);
- pPageSetForm.PrinterPaperCheck.CheckedChangedEvent += new CoreUI.Control.EventHandler(PrinterPaperCheck_CheckedChangedEvent);
- pPageSetForm.PrinterNameCombox.SelectedIndexChangedEvent += new CoreUI.Control.DataListSelectChanged(PrinterNameCombox_SelectedIndexChangedEvent);
- pPageSetForm.StretchGraphicsCheck.CheckedChangedEvent += new CoreUI.Control.EventHandler(StretchGraphicsCheck_CheckedChangedEvent);
- pPageSetForm.PrintableAreaCheck.CheckedChangedEvent += new CoreUI.Control.EventHandler(PrintableAreaCheck_CheckedChangedEvent);
- pPageSetForm.UnitsCombox.SelectedIndexChangedEvent += new CoreUI.Control.DataListSelectChanged(UnitsCombox_SelectedIndexChangedEvent);
- pPageSetForm.LocationRadio1.SelectedIndexChangedEvent += new CoreUI.Control.DataListSelectChanged(LocationRadio1_SelectedIndexChangedEvent);
- pPageSetForm.LocationRadio2.SelectedIndexChangedEvent += new CoreUI.Control.DataListSelectChanged(LocationRadio2_SelectedIndexChangedEvent);
- pPageSetForm.HeightSpin.TextChangedEvent += new CoreUI.Control.ValueChangedEventHandler(HeightSpin_TextChangedEvent);
- pPageSetForm.WidthSpin.TextChangedEvent += new CoreUI.Control.ValueChangedEventHandler(WidthSpin_TextChangedEvent);
- pPageSetForm.PictureControl.PaintEvent += new CoreUI.Control.PaintHandle(PictureControl_PaintEvent);
- pPageSetForm.OKButton.ClickEvent += new CoreUI.Control.EventHandler(OKButton_ClickEvent);
- pPageSetForm.ExitButton.ClickEvent += new CoreUI.Control.EventHandler(ExitButton_ClickEvent);
- pPageSetForm.FormIDCombox.SelectedIndexChangedEvent += new CoreUI.Control.DataListSelectChanged(FormIDCombox_SelectedIndexChangedEvent);
- }
- #endregion
- #region IPageSet 成员
- public IPageSetForm PageSetForm
- {
- get { return pPageSetForm; }
- }
- public IPageLayoutControl PageLayoutControl
- {
- set { pPageLayoutControl = value; }
- }
- public bool InitForm()
- {
- try
- {
- if (pPageLayoutControl == null) return false;
- if (pPageLayoutControl.Printer == null)
- {
- MessageManager.Show("没有可用的打印设备", "提示");
- return false;
- }
- if (pPageLayoutControl.Printer.Paper != null)
- {
- m_oldPrinterName = pPageLayoutControl.Printer.Paper.PrinterName;
- m_lOldFormID = pPageLayoutControl.Printer.Paper.FormID;
- m_iOldPaperOrientation = pPageLayoutControl.Printer.Paper.Orientation;
- InitPrinter();
- InitPage();
- optPageDerectionChange();
- }
- return true;
- }
- catch (Exception)
- {
- MessageManager.Show("没有可用的打印设备", "提示");
- return false;
- }
- }
- #endregion
- #region 窗体控件事件
- void PaperCombox_SelectedIndexChangedEvent(object sender, object data)
- {
- int iIndex = pPageSetForm.PaperCombox.SelectedIndex;
- int iFormID;
- m_PaperFormID.TryGetValue(iIndex, out iFormID);
- IPaper pPaper = pPageLayoutControl.Printer.Paper;
- if (iFormID == pPaper.FormID)
- {
- return;
- }
- else
- {
- pPaper.FormID = (short)iFormID;
- object obj1 = new object();
- PrinterPaperCheck_CheckedChangedEvent(obj1);
- pPageSetForm.PictureControl.Refresh();
- }
- }
- void PrinterPaperCheck_CheckedChangedEvent(object sender)
- {
- PageSamePrinter(pPageSetForm.PrinterPaperCheck.Checked);
- IPrinter pPrinter = pPageLayoutControl.Printer;
- IPage pPage = pPageLayoutControl.Page;
- pPrinter.QueryPaperSize(out m_MaxWidth, out m_MaxHeight);
- m_MaxWidth = m_MaxWidth * OutputCommon.GetUnitScale(pPrinter.Units);
- m_MaxHeight = m_MaxHeight * OutputCommon.GetUnitScale(pPrinter.Units);
- if (pPageSetForm.PrinterPaperCheck.Checked)
- {
- pPageSetForm.WidthSpin.Value = (decimal)Math.Round(m_MaxWidth, 2);
- pPageSetForm.HeightSpin.Value = (decimal)Math.Round(m_MaxHeight, 2);
- pPageSetForm.LocationRadio2.SelectedIndex = pPageSetForm.LocationRadio1.SelectedIndex;
- m_CurrentUnit = Units.Centimeters;
- pPageSetForm.UnitsCombox.Text = "厘米";
- }
- else
- {
- double dwidth = 0;
- double dheight = 0;
- dwidth = Convert.ToDouble(pPageSetForm.WidthSpin.Value) * OutputCommon.GetUnitScale(GetUnit());
- dheight = Convert.ToDouble(pPageSetForm.HeightSpin.Value) * OutputCommon.GetUnitScale(GetUnit());
- if (pPageSetForm.LocationRadio2.SelectedIndex == 0)
- {
- pPageSetForm.FormIDCombox.SelectedIndex = GetPageFormID(dwidth, dheight);
- }
- else
- {
- pPageSetForm.FormIDCombox.SelectedIndex = GetPageFormID(dheight, dwidth);
- }
- }
- pPageSetForm.PictureControl.Refresh();
- }
- void PrinterNameCombox_SelectedIndexChangedEvent(object sender, object data)
- {
- if (pPageSetForm.PrinterNameCombox.Text.ToString() == "")
- {
- return;
- }
- if (pPageSetForm.PrinterNameCombox.Text.ToString() == pPageLayoutControl.Printer.Paper.PrinterName)
- {
- SetPrinterAtti();
- initCombPaper();
- return;
- }
- else
- {
- SetPrinter(pPageSetForm.PrinterNameCombox.Text.ToString());
- initCombPaper();
- SetPrinterAtti();
- }
- pPageSetForm.PictureControl.Refresh();
- }
- void PrintableAreaCheck_CheckedChangedEvent(object sender)
- {
- pPageSetForm.PictureControl.Refresh();
- }
- void StretchGraphicsCheck_CheckedChangedEvent(object sender)
- {
- pPageLayoutControl.Page.StretchGraphicsWithPage = pPageSetForm.StretchGraphicsCheck.Checked;
- pPageSetForm.PictureControl.Refresh();
- }
- void UnitsCombox_SelectedIndexChangedEvent(object sender, object data)
- {
- Units pOldUnit = m_CurrentUnit;
-
- if (pPageSetForm.UnitsCombox.Text.IndexOf("点") != -1)
- {
- m_CurrentUnit = Units.Points;
- }
- else if (pPageSetForm.UnitsCombox.Text.IndexOf("毫米") != -1)
- {
- m_CurrentUnit = Units.Millimeters;
- }
- else if (pPageSetForm.UnitsCombox.Text.IndexOf("英寸") != -1)
- {
- m_CurrentUnit = Units.Inches;
- }
- else
- m_CurrentUnit = Units.Centimeters;
-
- m_MaxWidth = Math.Round(m_MaxWidth * OutputCommon.GetUnitScale(pOldUnit) / OutputCommon.GetUnitScale(m_CurrentUnit), 2);
- m_MaxHeight = Math.Round(m_MaxHeight * OutputCommon.GetUnitScale(pOldUnit) / OutputCommon.GetUnitScale(m_CurrentUnit), 2);
-
- pPageSetForm.WidthSpin.Text = m_MaxWidth.ToString();
- pPageSetForm.HeightSpin.Text = m_MaxHeight.ToString();
- }
- void LocationRadio2_SelectedIndexChangedEvent(object sender, object data)
- {
- optPageDerectionChange();
- }
- void LocationRadio1_SelectedIndexChangedEvent(object sender, object data)
- {
- if (pPageSetForm.LocationRadio1.SelectedIndex == 0)
- pPageLayoutControl.Printer.Paper.Orientation = 1;
- else
- pPageLayoutControl.Printer.Paper.Orientation = 2;
- if (pPageSetForm.PrinterPaperCheck.Checked)
- {
- pPageSetForm.LocationRadio2.SelectedIndex = pPageSetForm.LocationRadio1.SelectedIndex;
- }
-
- pPageSetForm.PictureControl.Refresh();
- }
- void WidthSpin_TextChangedEvent(object value)
- {
- if (pPageSetForm.FormIDCombox.Text == "自定义")
- {
- pPageSetForm.PictureControl.Refresh();
- }
- }
- void HeightSpin_TextChangedEvent(object value)
- {
- if (pPageSetForm.FormIDCombox.Text == "自定义")
- {
- pPageSetForm.PictureControl.Refresh();
- }
- }
- void ExitButton_ClickEvent(object sender)
- {
-
- if (pPageLayoutControl.Printer != null)
- {
- if (m_oldPrinterName == pPageLayoutControl.Printer.Paper.PrinterName)
- {
- if (pPageLayoutControl.Printer.Paper.FormID != m_lOldFormID)
- {
- pPageLayoutControl.Printer.Paper.FormID = m_lOldFormID;
- }
- if (pPageLayoutControl.Printer.Paper.Orientation != (short)m_iOldPaperOrientation)
- {
- pPageLayoutControl.Printer.Paper.Orientation = (short)m_iOldPaperOrientation;
- }
- }
- else
- {
- if (m_oldPrinterName != "")
- {
- SetPrinter(m_oldPrinterName);
- pPageLayoutControl.Printer.Paper.FormID = m_lOldFormID;
- pPageLayoutControl.Printer.Paper.Orientation = (short)m_iOldPaperOrientation;
- }
- }
- }
- pPageSetForm.Close();
- }
- void OKButton_ClickEvent(object sender)
- {
-
- IPage pPage = pPageLayoutControl.Page;
- pPage.Units = m_CurrentUnit;
-
- if (pPageSetForm.PrinterPaperCheck.Checked)
- {
- pPage.PutCustomSize(Convert.ToDouble(pPageSetForm.WidthSpin.Value), Convert.ToDouble(pPageSetForm.HeightSpin.Value));
- pPage.FormID = PageFormID.PageFormSameAsPrinter;
- }
- else
- {
- pPage.FormID = (PageFormID)pPageSetForm.FormIDCombox.SelectedIndex;
- if (pPage.FormID == PageFormID.PageFormCUSTOM)
- {
- pPage.PutCustomSize((double)(pPageSetForm.WidthSpin.Value), (double)(pPageSetForm.HeightSpin.Value));
- }
- if (pPageSetForm.LocationRadio2.SelectedIndex == 0)
- pPage.Orientation = 1;
- else
- pPage.Orientation = 2;
- }
-
- pPage.StretchGraphicsWithPage = false;
- pPage.IsPrintableAreaVisible = pPageSetForm.PrintableAreaCheck.Checked;
- pPageSetForm.Close();
- }
- void PictureControl_PaintEvent(CoreUI.Control.ControlPaintEventArgs e)
- {
- ITransformation pTransformation;
- TagRECT pRect = new TagRECT();
- int dGap = 4;
- pRect.top = (int)dGap;
- pRect.left = (int)dGap;
- pRect.bottom = pPageSetForm.PictureControl.Height - dGap;
- pRect.right = pPageSetForm.PictureControl.Width - dGap;
- e.Graphics.Clear(Color.White);
- Color pPageColor = pPageSetForm.ColorLabel2.ForeColor;
- Color pPaperColor = pPageSetForm.ColorLabel1.ForeColor;
- Color pMapFrameColor = pPageSetForm.ColorLabel0.ForeColor;
-
- IEnvelope pMapEnv = null;
- IEnvelope pPaperEnv = null;
- IPrinter pPrinter = null;
- IElement pMapFrame = null;
- IGraphicsContainer pGC = pPageLayoutControl.ActiveView as IGraphicsContainer;
-
- IEnvelope pPageEnv = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- pPageEnv.PutCoords(0, 0, Convert.ToDouble(pPageSetForm.WidthSpin.Value) * OutputCommon.GetUnitScale(m_CurrentUnit),
- Convert.ToDouble(pPageSetForm.HeightSpin.Value) * OutputCommon.GetUnitScale(m_CurrentUnit));
-
- pMapFrame = pGC.FindFrame(pPageLayoutControl.ActiveView.FocusMap as object) as IElement;
- if (pMapFrame != null)
- {
- pMapEnv = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- pMapFrame.QueryBounds(pPageLayoutControl.ActiveView.ScreenDisplay as IDisplay, pMapEnv);
-
- pMapEnv.XMin = pMapEnv.XMin * OutputCommon.GetUnitScale(pPageLayoutControl.Page.Units);
- pMapEnv.XMax = pMapEnv.XMax * OutputCommon.GetUnitScale(pPageLayoutControl.Page.Units);
- pMapEnv.YMax = pMapEnv.YMax * OutputCommon.GetUnitScale(pPageLayoutControl.Page.Units);
- pMapEnv.YMin = pMapEnv.YMin * OutputCommon.GetUnitScale(pPageLayoutControl.Page.Units);
- }
-
- if (pPageLayoutControl.Printer != null)
- {
- double dWidth;
- double dHeight;
- pPrinter = pPageLayoutControl.Printer;
- if (pPageSetForm.PrinterPaperCheck.Checked)
- {
- if (pPageSetForm.PrintableAreaCheck.Checked)
- {
- pPaperEnv = pPrinter.PrintableBounds;
- dWidth = pPaperEnv.Width;
- dHeight = pPaperEnv.Height;
- double dxmin = pPaperEnv.XMin;
- double dxmax = pPaperEnv.XMax;
- double dymin = pPaperEnv.YMin;
- double dymax = pPaperEnv.YMax;
- dxmin = dxmin * OutputCommon.GetUnitScale(pPrinter.Units);
- dxmax = dxmax * OutputCommon.GetUnitScale(pPrinter.Units);
- dymin = dymin * OutputCommon.GetUnitScale(pPrinter.Units);
- dymax = dymax * OutputCommon.GetUnitScale(pPrinter.Units);
- pPaperEnv = null;
- pPaperEnv = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- pPaperEnv.PutCoords(dxmin, dymin, dxmax, dymax);
- }
- else
- {
- pPaperEnv = null;
- }
- }
- else
- {
- pPrinter.QueryPaperSize(out dWidth, out dHeight);
- dWidth = dWidth * OutputCommon.GetUnitScale(pPrinter.Units);
- dHeight = dHeight * OutputCommon.GetUnitScale(pPrinter.Units);
- pPaperEnv = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- pPaperEnv.PutCoords(0, 0, dWidth, dHeight);
- }
- }
-
- IEnvelope pFullEnv = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- if (pPageEnv != null)
- pFullEnv = pFullEnv.Union(pPageEnv) as IEnvelope;
- if (pMapEnv != null)
- pFullEnv = pFullEnv.Union(pMapEnv) as IEnvelope;
- if (pPaperEnv != null)
- pFullEnv = pFullEnv.Union(pPaperEnv) as IEnvelope;
- double dx = 0;
- double dy = 0;
- if (!pFullEnv.IsEmpty)
- {
- double dScaleX = (pRect.right - pRect.left) / pFullEnv.Width;
- double dScaleY = (pRect.bottom - pRect.top) / pFullEnv.Height;
- if (dScaleX > dScaleY)
- {
- dScaleX = dScaleY;
- dx = ((pRect.right - pRect.left) - pFullEnv.Width * dScaleX) / 2.00;
- }
- else
- dy = ((pRect.bottom - pRect.top) - pFullEnv.Height * dScaleY) / 2.00;
- pTransformation = OutputCommon.CreateTransFromDC(e.Graphics, pRect.right - pRect.left, pRect.bottom - pRect.top);
- ISymbol pSymbol;
- IEnvelope pEnvelope;
-
- if (pMapEnv != null)
- {
-
- pEnvelope = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- pEnvelope.XMin = pMapEnv.XMin * dScaleX;
- pEnvelope.XMax = pMapEnv.XMax * dScaleX;
- pEnvelope.YMin = pMapEnv.YMin * dScaleY;
- pEnvelope.YMax = pMapEnv.YMax * dScaleY;
- pEnvelope.Offset(dx, dy);
- Image image = Properties.Resources.MapElements1;
- e.Graphics.DrawImage(image, (float)pEnvelope.XMin, (float)pEnvelope.YMin, (float)pEnvelope.Width, (float)pEnvelope.Height);
- pEnvelope = null;
- }
-
- if (pPageEnv != null)
- {
-
- pSymbol = OutputCommon.CreateSimpleFillSym(pPageColor, SimpleFillStyle.Null, pPageColor, SimpleLineStyle.Solid, 0.2);
-
- pEnvelope = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- pEnvelope.XMin = pPageEnv.XMin * dScaleX;
- pEnvelope.XMax = pPageEnv.XMax * dScaleX;
- pEnvelope.YMin = pPageEnv.YMin * dScaleY;
- pEnvelope.YMax = pPageEnv.YMax * dScaleY;
- pEnvelope.Offset(dx, dy);
-
- if (pTransformation != null)
- {
- pSymbol.SetupDC((int)e.Graphics.GetHdc(), pTransformation);
- pSymbol.Draw(pEnvelope as IGeometry);
- pSymbol.ResetDC();
- e.Graphics.ReleaseHdc();
- }
- pEnvelope = null;
- pSymbol = null;
- }
-
- if (pPaperEnv != null)
- {
-
- if (pPageSetForm.PrinterPaperCheck.Checked)
- {
- pSymbol = OutputCommon.CreateSimpleFillSym(pPaperColor, SimpleFillStyle.Null, pPaperColor, SimpleLineStyle.DashDot, 0.15);
- }
- else
- {
- pSymbol = OutputCommon.CreateSimpleFillSym(pMapFrameColor, SimpleFillStyle.Null, pPaperColor, SimpleLineStyle.Solid, 0.15);
- }
-
- pEnvelope = ContextRegistry.GetContext().GetObject("GIS_Envelope") as IEnvelope;
- pEnvelope.XMin = pPaperEnv.XMin * dScaleX;
- pEnvelope.XMax = pPaperEnv.XMax * dScaleX;
- pEnvelope.YMin = pPaperEnv.YMin * dScaleY;
- pEnvelope.YMax = pPaperEnv.YMax * dScaleY;
- pEnvelope.Offset(dx, dy);
-
- if (pTransformation != null)
- {
- pSymbol.SetupDC((int)e.Graphics.GetHdc(), pTransformation);
- pSymbol.Draw(pEnvelope as IGeometry);
- pSymbol.ResetDC();
- e.Graphics.ReleaseHdc();
- }
- pEnvelope = null;
- pSymbol = null;
- }
- }
- }
- void FormIDCombox_SelectedIndexChangedEvent(object sender, object data)
- {
-
- switch (pPageSetForm.FormIDCombox.SelectedIndex)
- {
- case 0:
- {
- m_MaxWidth = 8.5 * OutputCommon.GetUnitScale(Units.Inches);
- m_MaxHeight = 11 * OutputCommon.GetUnitScale(Units.Inches);
- }
- break;
- case 1:
- {
- m_MaxWidth = 8.5 * OutputCommon.GetUnitScale(Units.Inches);
- m_MaxHeight = 14 * OutputCommon.GetUnitScale(Units.Inches);
- }
- break;
- case 2:
- {
- m_MaxWidth = 11 * OutputCommon.GetUnitScale(Units.Inches);
- m_MaxHeight = 17 * OutputCommon.GetUnitScale(Units.Inches);
- }
- break;
- case 3:
- {
- m_MaxWidth = 17 * OutputCommon.GetUnitScale(Units.Inches);
- m_MaxHeight = 22 * OutputCommon.GetUnitScale(Units.Inches);
- }
- break;
- case 4:
- {
- m_MaxWidth = 22 * OutputCommon.GetUnitScale(Units.Inches);
- m_MaxHeight = 34 * OutputCommon.GetUnitScale(Units.Inches);
- }
- break;
- case 5:
- {
- m_MaxWidth = 34 * OutputCommon.GetUnitScale(Units.Inches);
- m_MaxHeight = 34 * OutputCommon.GetUnitScale(Units.Inches);
- }
- break;
- case 6:
- {
- m_MaxWidth = 148 * OutputCommon.GetUnitScale(Units.Millimeters);
- m_MaxHeight = 210 * OutputCommon.GetUnitScale(Units.Millimeters);
- }
- break;
- case 7:
- {
- m_MaxWidth = 210 * OutputCommon.GetUnitScale(Units.Millimeters);
- m_MaxHeight = 297 * OutputCommon.GetUnitScale(Units.Millimeters);
- }
- break;
- case 8:
- {
- m_MaxWidth = 297 * OutputCommon.GetUnitScale(Units.Millimeters);
- m_MaxHeight = 420 * OutputCommon.GetUnitScale(Units.Millimeters);
- }
- break;
- case 9:
- {
- m_MaxWidth = 420 * OutputCommon.GetUnitScale(Units.Millimeters);
- m_MaxHeight = 594 * OutputCommon.GetUnitScale(Units.Millimeters);
- }
- break;
- case 10:
- {
- m_MaxWidth = 594 * OutputCommon.GetUnitScale(Units.Millimeters);
- m_MaxHeight = 841 * OutputCommon.GetUnitScale(Units.Millimeters);
- }
- break;
- case 11:
- {
- m_MaxWidth = 841 * OutputCommon.GetUnitScale(Units.Millimeters);
- m_MaxHeight = 1189 * OutputCommon.GetUnitScale(Units.Millimeters);
- }
- break;
- case 12:
- {
- pPageLayoutControl.Page.QuerySize(out m_MaxWidth, out m_MaxHeight);
- m_MaxWidth = m_MaxWidth * OutputCommon.GetUnitScale(pPageLayoutControl.Page.Units);
- m_MaxHeight = m_MaxHeight * OutputCommon.GetUnitScale(pPageLayoutControl.Page.Units);
- }
- break;
- }
-
- if (pPageSetForm.LocationRadio2.SelectedIndex == 0)
- {
- pPageSetForm.WidthSpin.Value = (decimal)Math.Round(m_MaxWidth, 2);
- pPageSetForm.HeightSpin.Value = (decimal)Math.Round(m_MaxHeight, 2);
- }
- else
- {
- pPageSetForm.WidthSpin.Value = (decimal)Math.Round(m_MaxHeight, 2);
- pPageSetForm.HeightSpin.Value = (decimal)Math.Round(m_MaxWidth, 2);
- m_MaxHeight = Convert.ToDouble(pPageSetForm.WidthSpin.Value);
- m_MaxWidth = Convert.ToDouble(pPageSetForm.HeightSpin.Value);
- }
- if (m_MaxWidth <= m_MaxHeight)
- pPageSetForm.LocationRadio2.SelectedIndex = 0;
- else
- pPageSetForm.LocationRadio2.SelectedIndex = 1;
- m_CurrentUnit = Units.Centimeters;
- pPageSetForm.UnitsCombox.Text = "厘米";
-
- pPageSetForm.PictureControl.Refresh();
- }
- #endregion
- #region 私用方法
- private void InitPrinter()
- {
- List<string> listNames = GetPrintersName();
- DataTable pDT = new DataTable();
- pDT.Columns.Add("打印机名"); pDT.Columns.Add("CODE");
- for (int i = 0; i < listNames.Count; i++)
- {
- DataRow pDr = pDT.NewRow();
- pDr[0] = listNames[i]; pDr[1] = i;
- pDT.Rows.Add(pDr);
- }
- pPageSetForm.PrinterNameCombox.DisplayFieldName = "打印机名";
- pPageSetForm.PrinterNameCombox.CodeFieldName = "CODE";
- pPageSetForm.PrinterNameCombox.DataSource = pDT;
- SetPrinterAtti();
- initCombPaper();
- }
- private void InitPage()
- {
- DataTable FormIDDT = new DataTable();
- FormIDDT.Columns.Add("标准尺寸"); FormIDDT.Columns.Add("CODE");
- List<string> LstFormID = new List<string>();
- LstFormID.Add("Letter - 8.5in x 11in");
- LstFormID.Add("Legal - 8.5in x 14in");
- LstFormID.Add("Tabloid - 11in x 17in");
- LstFormID.Add("ANSI C - 17in x 22in");
- LstFormID.Add("ANSI D - 22in x 34in");
- LstFormID.Add("ANSI E - 34in x 44in");
- LstFormID.Add("A5 - 148mm x 210mm");
- LstFormID.Add("A4 - 210mm x 297mm");
- LstFormID.Add("A3 - 297mm x 420mm");
- LstFormID.Add("A2 - 420mm x 594mm");
- LstFormID.Add("A1 - 594mm x 841mm");
- LstFormID.Add("A0 - 841mm x 1189mm");
- LstFormID.Add("自定义");
- for (int i = 0; i < LstFormID.Count; i++)
- {
- DataRow pDr = FormIDDT.NewRow();
- pDr[0] = LstFormID[i]; pDr[1] = i;
- FormIDDT.Rows.Add(pDr);
- }
- pPageSetForm.FormIDCombox.DisplayFieldName = "标准尺寸";
- pPageSetForm.FormIDCombox.CodeFieldName = "CODE";
- pPageSetForm.FormIDCombox.DataSource = FormIDDT;
- DataTable UnitsDT = new DataTable();
- UnitsDT.Columns.Add("单位");
- UnitsDT.Columns.Add("CODE");
- List<string> LstUnits = new List<string>();
- LstUnits.Add("点"); LstUnits.Add("英寸"); LstUnits.Add("厘米"); LstUnits.Add("毫米");
- for (int i = 0; i < LstUnits.Count; i++)
- {
- DataRow pDr = UnitsDT.NewRow();
- pDr[0] = LstUnits[i]; pDr[1] = i;
- UnitsDT.Rows.Add(pDr);
- }
- pPageSetForm.UnitsCombox.DisplayFieldName = "单位";
- pPageSetForm.UnitsCombox.CodeFieldName = "CODE";
- pPageSetForm.UnitsCombox.DataSource = UnitsDT;
- IPage pPage = pPageLayoutControl.Page;
- if (pPage.FormID == PageFormID.PageFormSameAsPrinter)
- {
- pPageSetForm.PrinterPaperCheck.Checked = true;
- pPageSetForm.PrintableAreaCheck.Enabled = true;
- pPageSetForm.PrintableAreaCheck.Checked = true;
- }
- else
- {
- pPageSetForm.PrinterPaperCheck.Checked = false;
- pPageSetForm.PrintableAreaCheck.Enabled = false;
- pPageSetForm.PrintableAreaCheck.Checked = false;
- pPageSetForm.FormIDCombox.SelectedIndex = (int)pPage.FormID;
- pPageSetForm.LocationRadio2.SelectedIndex = (int)pPage.Orientation - 1;
- }
- pPageSetForm.StretchGraphicsCheck.Checked = pPageLayoutControl.Page.StretchGraphicsWithPage;
- }
- private List<string> GetPrintersName()
- {
- List<string> strNames = new List<string>();
- foreach (string pkInstalledPrinters in
- PrinterSettings.InstalledPrinters)
- {
- string name = pkInstalledPrinters;
- strNames.Add(name);
- }
- return strNames;
- }
- private string GetDefaultPrinterName()
- {
- PrintDocument pd = new PrintDocument();
- return pd.PrinterSettings.PrinterName;
- }
- private void SetPrinter(string strNewPrinterName)
- {
- IPrinter pPrinter;
- IPaper pPaper;
- IPaper pNewPaper;
- IPage pPage;
- string sNewPrinterName;
- Dictionary<int, string> eFormEnum;
- double dPageWidth;
- double dPageHeight;
- double dNewPageWidth;
- double dNewPageHeight;
- double doldW = 0;
- double doldh = 0;
- pPageLayoutControl.Printer.Paper.QueryPaperSize(out doldW, out doldh);
- doldW = doldW * OutputCommon.GetUnitScale(pPageLayoutControl.Printer.Units);
- doldh = doldh * OutputCommon.GetUnitScale(pPageLayoutControl.Printer.Units);
- bool bNeedPrinter;
- bool bFormFound;
- pPaper = ContextRegistry.GetContext().GetObject("GIS_Paper") as IPaper;
- pNewPaper = ContextRegistry.GetContext().GetObject("GIS_Paper") as IPaper;
- pPage = ContextRegistry.GetContext().GetObject("GIS_Page") as IPage;
- pPrinter = ContextRegistry.GetContext().GetObject("GIS_EmfPrinter") as IPrinter;
- bNeedPrinter = false;
- bFormFound = false;
- dPageWidth = 0;
- dPageHeight = 0;
- dNewPageWidth = 0;
- dNewPageHeight = 0;
- sNewPrinterName = strNewPrinterName;
- if (pPageLayoutControl != null)
- {
- pPage = pPageLayoutControl.Page;
- pPage.QuerySize(out dPageWidth, out dPageHeight);
- if (dPageWidth == 0)
- {
- if (pPage.Orientation == 2)
- {
- dPageWidth = 11;
- dPageHeight = 8.5;
- }
- else
- {
- dPageWidth = 8.5;
- dPageHeight = 11;
- }
- }
- try
- {
- string strNa = pPageLayoutControl.Printer.Paper.PrinterName;
- bNeedPrinter = false;
- }
- catch
- {
- bNeedPrinter = true;
- }
- if (bNeedPrinter)
- {
- if (pPage.StretchGraphicsWithPage == true)
- {
- pPage.StretchGraphicsWithPage = false;
- }
- pPage.FormID = PageFormID.PageFormCUSTOM;
- pPage.PutCustomSize(dPageWidth, dPageHeight);
- }
- pPage.StretchGraphicsWithPage = false;
- pPaper.PrinterName = sNewPrinterName;
- pPrinter.Paper = pPaper;
- eFormEnum = pPaper.FormIDs;
- dPageWidth = dPageWidth * OutputCommon.GetUnitScale(pPageLayoutControl.Page.Units);
- dPageHeight = dPageHeight * OutputCommon.GetUnitScale(pPageLayoutControl.Page.Units);
- foreach (int iCounter in eFormEnum.Keys)
- {
- pNewPaper = ContextRegistry.GetContext().GetObject("GIS_Paper") as IPaper;
- pNewPaper.PrinterName = sNewPrinterName;
- pNewPaper.Orientation = pPage.Orientation;
- pNewPaper.FormID = (short)iCounter;
- pNewPaper.QueryPaperSize(out dNewPageWidth, out dNewPageHeight);
- dNewPageWidth = dNewPageWidth * OutputCommon.GetUnitScale(pNewPaper.Units);
- dNewPageHeight = dNewPageHeight * OutputCommon.GetUnitScale(pNewPaper.Units);
- if (pPage.FormID == PageFormID.PageFormSameAsPrinter)
- {
- if ((Math.Round(dPageHeight) == (Math.Round(dNewPageHeight))) && (Math.Round(dPageWidth) == (Math.Round(dNewPageWidth))))
- {
- bFormFound = true;
- pPageLayoutControl.Printer.Paper = pNewPaper;
- pPageLayoutControl.Page.PutCustomSize(dPageWidth, dPageHeight);
- pPageLayoutControl.Page.FormID = PageFormID.PageFormSameAsPrinter;
- pPageLayoutControl.ActiveView.PrinterChanged(pPageLayoutControl.Printer);
- break;
- }
- }
- else
- {
- if ((Math.Round(doldW) == (Math.Round(dNewPageHeight))) && (Math.Round(doldh) == (Math.Round(dNewPageWidth))))
- {
- bFormFound = true;
- pPageLayoutControl.Printer.Paper = pNewPaper;
- pPageLayoutControl.ActiveView.PrinterChanged(pPageLayoutControl.Printer);
- break;
- }
- }
- }
- if (!bFormFound)
- {
- if (pPage.FormID == PageFormID.PageFormSameAsPrinter)
- {
- pPageLayoutControl.Printer.Paper = pNewPaper;
- pPage.FormID = PageFormID.PageFormCUSTOM;
- pPage.PutCustomSize(dPageWidth, dPageHeight);
- pPageLayoutControl.ActiveView.PrinterChanged(pPageLayoutControl.Printer);
- }
- else
- {
- pPageLayoutControl.Printer.Paper = pNewPaper;
- pPageLayoutControl.ActiveView.PrinterChanged(pPageLayoutControl.Printer);
- }
- }
- }
- }
- private void SetPrinterAtti()
- {
- if (pPageSetForm.PrinterNameCombox.Text.ToString() == "")
- {
- return;
- }
- string path = @"win32_printer.DeviceId='" + @pPageSetForm.PrinterNameCombox.Text.ToString() + "'";
- ManagementObject printer = new ManagementObject(path);
- printer.Get();
- PropertyDataCollection.PropertyDataEnumerator pde = printer.Properties.GetEnumerator();
- string str = "";
- while (pde.MoveNext())
- {
- object obj = pde.Current.Value;
- if (pde.Current.Name == "PortName")
- {
- pPageSetForm.PrinterLocationLabel.Text = (pde.Current.Value == null) ? "" : pde.Current.Value.ToString();
- }
- if (pde.Current.Name == "PrinterState")
- {
-
- }
- if (pde.Current.Name == "DriverName")
- {
- pPageSetForm.PrinterLXLabel.Text = (pde.Current.Value == null) ? "" : pde.Current.Value.ToString();
- }
- if (pde.Current.Name == "Comment")
- {
- pPageSetForm.PrinterBZLabel.Text = (pde.Current.Value == null) ? "" : pde.Current.Value.ToString();
- }
- str = str + "(" + pde.Current.Name + ":" + ((pde.Current.Value == null) ? "" : pde.Current.Value.ToString()) + ")";
- }
- }
- private void initCombPaper()
- {
- DataTable pDT = new DataTable();
- pDT.Columns.Add("纸张");
- pDT.Columns.Add("CODE");
- m_PaperFormID.Clear();
- IPaper pPaper = pPageLayoutControl.Printer.Paper;
- short iOrent = pPaper.Orientation;
- Dictionary<int, string> eFormEnum = pPaper.FormIDs;
- int j = 0;
- foreach (int FormID in eFormEnum.Keys)
- {
- m_PaperFormID.Add(j, FormID);
- DataRow pDr = pDT.NewRow();
- pDr[0] = eFormEnum[FormID]; pDr[1] = j;
- pDT.Rows.Add(pDr);
- j = j + 1;
- }
- pPageSetForm.PaperCombox.DisplayFieldName = "纸张";
- pPageSetForm.PaperCombox.CodeFieldName = "CODE";
- pPageSetForm.PaperCombox.DataSource = pDT;
- pPageSetForm.LocationRadio1.SelectedIndex = iOrent - 1;
- }
- private void optPageDerectionChange()
- {
- double dTempW;
- double dTempH;
- double dTemp;
- dTempW = Convert.ToDouble(pPageSetForm.WidthSpin.Value);
- dTempH = Convert.ToDouble(pPageSetForm.HeightSpin.Value);
- if (pPageSetForm.LocationRadio2.SelectedIndex == 0)
- {
- if (dTempW > dTempH)
- {
-
- dTemp = m_MaxWidth;
- m_MaxWidth = m_MaxHeight;
- m_MaxHeight = dTemp;
-
- pPageSetForm.WidthSpin.Text = dTempH.ToString();
- pPageSetForm.HeightSpin.Text = dTempW.ToString();
- }
- }
- else
- {
- if (dTempW < dTempH)
- {
-
- dTemp = m_MaxWidth;
- m_MaxWidth = m_MaxHeight;
- m_MaxHeight = dTemp;
-
- pPageSetForm.WidthSpin.Text = dTempH.ToString();
- pPageSetForm.HeightSpin.Text = dTempW.ToString();
- }
- }
-
- pPageSetForm.PictureControl.Refresh();
- }
- private void PageSamePrinter(bool isSame)
- {
- if (isSame)
- {
- pPageSetForm.EqualsLabel.Visible = true;
- pPageSetForm.FormIDLabel.Visible = false;
- pPageSetForm.FormIDCombox.Visible = false;
- pPageSetForm.PrintableAreaCheck.Enabled = true;
- pPageSetForm.WidthSpin.Enabled = false;
- pPageSetForm.HeightSpin.Enabled = false;
- pPageSetForm.LocationRadio2.Enabled = false;
- pPageSetForm.PrintableAreaCheck.Enabled = true;
- pPageSetForm.PrintableAreaCheck.Checked = true;
- }
- else
- {
- pPageSetForm.EqualsLabel.Visible = false;
- pPageSetForm.FormIDLabel.Visible = true;
- pPageSetForm.FormIDCombox.Visible = true;
- pPageSetForm.PrintableAreaCheck.Enabled = false;
- pPageSetForm.WidthSpin.Enabled = true;
- pPageSetForm.HeightSpin.Enabled = true;
- pPageSetForm.PrintableAreaCheck.Enabled = false;
- pPageSetForm.PrintableAreaCheck.Checked = false;
- pPageSetForm.LocationRadio2.Enabled = true;
- }
- }
- private Units GetUnit()
- {
- switch (pPageSetForm.UnitsCombox.SelectedIndex)
- {
- case 0:
- return Units.Points;
- case 1:
- return Units.Inches;
- case 2:
- return Units.Centimeters;
- case 3:
- return Units.Millimeters;
- default:
- return Units.Centimeters;
- }
- }
- private int GetPageFormID(double dWidth, double dHeight)
- {
- double iMaxWidth = 0;
- double iMaxHeight = 0;
- DataTable FormIDDT = pPageSetForm.FormIDCombox.DataSource as DataTable;
- if (FormIDDT == null || FormIDDT.Rows.Count == 0) return 12;
- for (int i = 0; i < FormIDDT.Rows.Count; i++)
- {
- int m = Convert.ToInt32(FormIDDT.Rows[i]["CODE"]);
- switch (m)
- {
- case 0:
- {
- iMaxWidth = 8.5 * OutputCommon.GetUnitScale(Units.Inches);
- iMaxHeight = 11 * OutputCommon.GetUnitScale(Units.Inches);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 0;
- }
- }
- break;
- case 1:
- {
- iMaxWidth = 8.5 * OutputCommon.GetUnitScale(Units.Inches);
- iMaxHeight = 14 * OutputCommon.GetUnitScale(Units.Inches);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 1;
- }
- }
- break;
- case 2:
- {
- iMaxWidth = 11 * OutputCommon.GetUnitScale(Units.Inches);
- iMaxHeight = 17 * OutputCommon.GetUnitScale(Units.Inches);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 2;
- }
- }
- break;
- case 3:
- {
- iMaxWidth = 17 * OutputCommon.GetUnitScale(Units.Inches);
- iMaxHeight = 22 * OutputCommon.GetUnitScale(Units.Inches);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 3;
- }
- }
- break;
- case 4:
- {
- iMaxWidth = 22 * OutputCommon.GetUnitScale(Units.Inches);
- iMaxHeight = 34 * OutputCommon.GetUnitScale(Units.Inches);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 4;
- }
- }
- break;
- case 5:
- {
- iMaxWidth = 34 * OutputCommon.GetUnitScale(Units.Inches);
- iMaxHeight = 34 * OutputCommon.GetUnitScale(Units.Inches);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 5;
- }
- }
- break;
- case 6:
- {
- iMaxWidth = 148 * OutputCommon.GetUnitScale(Units.Millimeters);
- iMaxHeight = 210 * OutputCommon.GetUnitScale(Units.Millimeters);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 6;
- }
- }
- break;
- case 7:
- {
- iMaxWidth = 210 * OutputCommon.GetUnitScale(Units.Millimeters);
- iMaxHeight = 297 * OutputCommon.GetUnitScale(Units.Millimeters);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 7;
- }
- }
- break;
- case 8:
- {
- iMaxWidth = 297 * OutputCommon.GetUnitScale(Units.Millimeters);
- iMaxHeight = 420 * OutputCommon.GetUnitScale(Units.Millimeters);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 8;
- }
- }
- break;
- case 9:
- {
- iMaxWidth = 420 * OutputCommon.GetUnitScale(Units.Millimeters);
- iMaxHeight = 594 * OutputCommon.GetUnitScale(Units.Millimeters);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 9;
- }
- }
- break;
- case 10:
- {
- iMaxWidth = 594 * OutputCommon.GetUnitScale(Units.Millimeters);
- iMaxHeight = 841 * OutputCommon.GetUnitScale(Units.Millimeters);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 10;
- }
- }
- break;
- case 11:
- {
- iMaxWidth = 841 * OutputCommon.GetUnitScale(Units.Millimeters);
- iMaxHeight = 1189 * OutputCommon.GetUnitScale(Units.Millimeters);
- if (Math.Round(dWidth) == Math.Round(iMaxWidth) && Math.Round(dHeight) == Math.Round(iMaxHeight))
- {
- return 11;
- }
- }
- break;
- default:
- {
- return 12;
- }
- break;
- }
- }
- return 12;
- }
- #endregion
- }
- }
|