From: http://www.cnblogs.com/shenchao/p/3594394.html
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. windows. forms; using ESRI. arcGIS. controls; using ESRI. arcGIS. CARTO; using ESRI. arcGIS. display; using ESRI. arcGIS. geometry; using ESRI. arcGIS. esrisystem; namespace mypagelayoutcontrol // replace {class pagelayoutbaseoperate {// <summary> // according to the ArcGIS installation path, load the built-in information /// </Summary> /// <Param name = "symbol Ogycontrol "> </param> Public static void initaxsybologycontrol (isymbologycontroldefault symbologycontrol) {try {// Microsoft. win32.registrykey regkey = Microsoft. win32.registry. localmachine. opensubkey ("Software \ ESRI \ coreruntime", true); Microsoft. win32.registrykey regkey = Microsoft. win32.registry. localmachine. opensubkey ("Software \ ESRI \ topics top10.0", true); If (null! = Regkey) {symbologycontrol. loadstylefile (regkey. getvalue ("installdir") + "\ styles \ ESRI. serverstyle ");} else {MessageBox. show ("unable to obtain the style class of the symbologycontrol control! "," Prompt ", messageboxbuttons. OK, messageboxicon. warning);} symbologycontrol. getstyleclass (esrisymbologystyleclass. esristyleclassbackgrounds ). update (); symbologycontrol. getstyleclass (esrisymbologystyleclass. esristyleclassborders ). update (); symbologycontrol. getstyleclass (esrisymbologystyleclass. esristyleclassshadows ). update ();} catch (system. exception ex) {MessageBox. show ("failed to initialize symbologycontrol status! "+ Ex. message );}} /// <summary> /// load the map file /// </Summary> /// <Param name = "mapcontrol"> </param> Public static void loadmapdocument (ipagelayoutcontroldefault pagelayoutcontrol) {openfiledialog openfiledlg = new openfiledialog (); openfiledlg. title = "文"; openfiledlg. filter = "map document (*. mxd) | *. mxd "; openfiledlg. showdialog (); string filepath = openfiledlg. filename; mapdocumentclass mapdo C = new mapdocumentclass (); If (pagelayoutcontrol. checkmxfile (filepath) {mapdoc. open (filepath, ""); For (INT I = 0; I <mapdoc. mapcount; I ++) {pagelayoutcontrol. pagelayout = mapdoc. pagelayout;} pagelayoutcontrol. refresh ();} else {MessageBox. show (filepath + "is not a valid map! ");}} /// <Summary> /// set the border /// </Summary> /// <Param name = "symbologycontrol"> </param> Public static void setborders (isymbologycontroldefault symbologycontrol) {try {symbologycontrol. styleclass = esrisymbologystyleclass. esristyleclassborders;} catch (system. exception ex) {MessageBox. show ("failed to set border! "+ Ex. message );}} /// <summary> /// set the shadow /// </Summary> /// <Param name = "symbologycontrol"> </param> Public static void setshadows (isymbologycontroldefault symbologycontrol) {try {symbologycontrol. styleclass = esrisymbologystyleclass. esristyleclassshadows;} catch (system. exception ex) {MessageBox. show ("failed to set shadow! "+ Ex. message );}} /// <summary> /// set the background /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void setbackgrounds (isymbologycontroldefault symbologycontrol) {try {symbologycontrol. styleclass = esrisymbologystyleclass. esristyleclassbackgrounds;} catch (system. exception ex) {MessageBox. show ("failed to set the background! "+ Ex. message );}} /// <summary> /// set the grid /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void setgrid (ipagelayoutcontroldefault pagelayoutcontrol) {try {iactiveview activeview = pagelayoutcontrol. pagelayout as iactiveview; IMAP map = activeview. focusmap; imeasuredgrid measuredgrid = new measuredgridclass (); imapgrid mapgrid = measuredgrid as imapgrid; measuredgrid. fix Edorigin = true; measuredgrid. units = map. mapunits; measuredgrid. xintervalsize = 10; measuredgrid. yintervalsize = 10; measuredgrid. xorigin =-180; measuredgrid. yorigin =-90; iprojectedgrid projectedgrid = measuredgrid as iprojectedgrid; projectedgrid. spatialreference = map. spatialreference; mapgrid. name = "measured grid"; igraphicscontainer graphicscontainer = activeview as igraphicscontainer; Im Apframe mapframe = graphicscontainer. findframe (MAP) as imapframe; imapgrids mapgrids = mapframe as imapgrids; mapgrids. addmapgrid (mapgrid); activeview. partialrefresh (esriviewdrawphase. esriviewbackground, null, null);} catch (system. exception ex) {MessageBox. show ("failed to set grid! "+ Ex. message) ;}}/// <summary> /// selected value in symbologycontrol, set the pagelayout property /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> /// <Param name = "stylegalleryitem"> E. stylegalleryitem </param> Public static void controls (ipagelayoutcontroldefault pagelayoutcontrol, istylegalleryitem stylegalleryitem) {try {iframeproperties frameproperties = (iframeproperties) pagelayoutcontr Ol. graphicscontainer. findframe (pagelayoutcontrol. activeview. focusmap); If (stylegalleryitem. item is ibackground) {frameproperties. background = (ibackground) stylegalleryitem. item;} else if (stylegalleryitem. item is iborder) {frameproperties. border = (iborder) stylegalleryitem. item;} else if (stylegalleryitem. item is ishadow) {frameproperties. shadow = (ishadow) stylegalleryitem. item;} pagelayout Control. activeview. partialrefresh (esriviewdrawphase. esriviewbackground, null, null);} catch (system. Exception ex) {MessageBox. Show ("failed to set the pagelayout attribute! "+ Ex. message );}} /// <summary> /// zoom out /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void zoomout (ipagelayoutcontroldefault pagelayoutcontrol) {try {pagelayoutcontrol. mousepointer = esricontrolsmousepointer. esripointerpagezoomout; // ienvelope ipenv = mapcontrol. trackrectangle (); ienvelope ipenv = pagelayoutcontrol. extent; ipenv. expand (2, 2, true); pagelayoutcontrol. Extent = ipenv;} catch (system. Exception ex) {MessageBox. Show ("narrowing down failed! "+ Ex. message );}} /// <summary> /// zoom in /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void zoomin (ipagelayoutcontroldefault pagelayoutcontrol) {try {pagelayoutcontrol. mousepointer = esricontrolsmousepointer. esripointerpagezoomin; ienvelope ipenv = pagelayoutcontrol. trackrectangle (); If (ipenv. isempty) {ipenv = pagelayoutcontrol. extent; ipenv. expand (0.5, 0.5, true );} Pagelayoutcontrol. extent = ipenv;} catch (system. Exception ex) {MessageBox. Show ("amplification failed! "+ Ex. message );}} /// <summary> /// roaming // </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void Pan (ipagelayoutcontroldefault pagelayoutcontrol) {try {pagelayoutcontrol. mousepointer = esricontrolsmousepointer. esripointerpagepan; // ienvelope ipenv = mapcontrol. extent; pagelayoutcontrol. pan ();} catch (system. exception ex) {MessageBox. show ("Roaming failed! "+ Ex. message );}} /// <summary> /// full graph /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void fullextent (ipagelayoutcontroldefault pagelayoutcontrol) {try {pagelayoutcontrol. extent = pagelayoutcontrol. fullextent; pagelayoutcontrol. refresh ();} catch (system. exception ex) {MessageBox. show ("Full graph display failed! "+ Ex. message );}} /// <summary> /// add text /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void addtextelement (ipagelayoutcontroldefault pagelayoutcontrol, string text, irgbcolor color, ienvelope envelope, double textsize) {try {iactiveview activeview; igraphicscontainer graphicscontainer; itextelement textelement; itextsymbol textsymbol; // irgbcolor color; ielement ELEM Ent; // ienvelope envelope; activeview = pagelayoutcontrol. pagelayout as iactiveview; If (null = envelope) {envelope = new envelopeclass (); envelope. putcoords (0, 0, 5, 5);} textelement = new textelementclass (); element = textelement as ielement; element. geometry = envelope; If (null = text) {textelement. TEXT = "test map";} else {textelement. TEXT = text;} textsymbol = new textsymbolclass (); If (Null = color) {color = new rgbcolorclass (); color. green = 255; color. blue = 255; color. red = 0;} textsymbol. color = color as icolor; If (textsize <0.1 | textsize> 100) {textsymbol. size = 30;} else {textsymbol. size = textsize;} textelement. symbol = textsymbol; graphicscontainer = activeview as igraphicscontainer; graphicscontainer. addelement (element, 0); pagelayoutcontrol. refresh ();} Cat CH (system. Exception ex) {MessageBox. Show ("failed to add text! "+ Ex. message );}} /// <summary> /// add legend /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void addmapsurround (ipagelayoutcontroldefault pagelayoutcontrol, ienvelope envelope, string mapsurroundname) {uid; // ienvelope envelope; // imapsurround mapsurround; using graphicscontainer; imapframe mapframe; using mapsurroundframe; ielement element; using trackcancel; uid = new uidclass (); uid. value = "esricarto. legend "; if (null = envelope) {envelope = new envelopeclass (); envelope. putcoords (1, 1, 2, 2);} graphicscontainer = pagelayoutcontrol. pagelayout as igraphicscontainer; mapframe = graphicscontainer. findframe (pagelayoutcontrol. activeview. focusmap) as imapframe; mapsurroundframe = mapframe. createsurroundframe (UID, null); If (null = mapsurroundname) {mapsurroundframe. mapsurround. name = "legend";} else {mapsurroundframe. mapsurround. name = mapsurroundname;} element = mapsurroundframe as ielement; element. geometry = envelope; element. activate (pagelayoutcontrol. activeview. screendisplay); trackcancel = new canceltrackerclass (); element. draw (pagelayoutcontrol. activeview. screendisplay, trackcancel); graphicscontainer. addelement (element, 0); pagelayoutcontrol. refresh ();} /// <summary> /// text scale /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void scaletext (ipagelayoutcontroldefault pagelayoutcontrol, ienvelope envelope) {uid; // ienvelope envelope; // your mapsurround; your graphicscontainer; imapframe mapframe; your mapsurroundframe; ielement element; your trackcancel; uid = new uidclass (); UID. value = "esricarto. scaletext "; if (null = envelope) {envelope = new envelopeclass (); envelope. putcoords (1, 1, 2, 2);} graphicscontainer = pagelayoutcontrol. pagelayout as igraphicscontainer; mapframe = graphicscontainer. findframe (pagelayoutcontrol. activeview. focusmap) as imapframe; mapsurroundframe = mapframe. createsurroundframe (UID, null); element = mapsurroundframe as ielement; element. geometry = envelope; element. activate (pagelayoutcontrol. activeview. screendisplay); trackcancel = new canceltrackerclass (); element. draw (pagelayoutcontrol. activeview. screendisplay, trackcancel); graphicscontainer. addelement (element, 0); pagelayoutcontrol. refresh ();} /// <summary> /// legend scale /// </Summary> /// <Param name = "pagelayoutcontrol"> </param> Public static void scalemap (ipagelayoutcontroldefault pagelayoutcontrol, ienvelope envelope) {uid; // ienvelope envelope; // your mapsurround; your graphicscontainer; imapframe mapframe; your mapsurroundframe; ielement element; your trackcancel; uid = new uidclass (); UID. value = "esricarto. scaleline "; if (null = envelope) {envelope = new envelopeclass (); envelope. putcoords (1, 1, 10, 2);} graphicscontainer = pagelayoutcontrol. pagelayout as igraphicscontainer; mapframe = graphicscontainer. findframe (pagelayoutcontrol. activeview. focusmap) as imapframe; mapsurroundframe = mapframe. createsurroundframe (UID, null); element = mapsurroundframe as ielement; element. geometry = envelope; element. activate (pagelayoutcontrol. activeview. screendisplay); trackcancel = new canceltrackerclass (); element. draw (pagelayoutcontrol. activeview. screendisplay, trackcancel); graphicscontainer. addelement (element, 0); pagelayoutcontrol. refresh ();} /// <summary> /// color /// </Summary> /// <Param name = "R"> </param> /// <Param name =" G "> </param> // <Param name =" B "> </param> // <Param name =" T "> </param> /// <returns> </returns> Public static irgbcolor getcolor (int r, int g, int B, int t) {irgbcolor rgbcolor = new rgbcolorclass (); rgbcolor. red = r; rgbcolor. green = g; rgbcolor. blue = B; rgbcolor. transparency = (byte) T; return rgbcolor ;}}}
C # basic pagelayoutcontrol operations