Professional Documents
Culture Documents
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------- 1
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------- 2
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
ESRI.ArcGIS.Display ESRI.ArcGIS.SystemUI
ESRI.ArcGIS.Geometry ESRI.ArcGIS.Utility
esriMapControl esriTOCControl
esriPageLayoutControl esriToolbarControl
Thc thi ng dng:
Np cc iu khin ArcGIS:
Trc khi bt u lp trnh ng dng, cc iu khin ArcGIS v cc tham
chiu th vin ArcGIS Engine khc m ng dng s dng phai c np trong
mi trng ng dng.
1. Khi ng VS.NET v to mt ng dng Windows Application ca C# t
hp thoi New project.
2. t tn ng dng l Controls, v duyt v tr save ng dng.
3. Bm chut phi vo tab Windows Form ca thanh cng c v chn Add/
Remove Items t menu ng cnh.
4. Trong hp thoi Customize Toolbox, chn .NET Framework v check vo
AxMapControl, AxPageLayoutControl,v AxTOCControl. Chn OK.
Cc iu khin ny gi y xut hin trong tab Windows Forms ca thanh
cng c.
----------------------------------------------------------------------------------------------------------------- 3
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
1. M .NET Form
2. Kch p vo AxMapControl trong Windows Forms tab ca thanh cng c
them mt MapControl trn form.
3. Lp li thao tc ny vi AxPageLayoutControl, AxTOCControl v
AxToolbarControl.
4. Thay i kch thc v thay i v tr ca cc iu khin trn form nh sau:
----------------------------------------------------------------------------------------------------------------- 4
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
using System;
using System.Windows.Forms;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.esriSystem;
using esriToolbarControl;
using esriTOCControl;
----------------------------------------------------------------------------------------------------------------- 5
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
@"..\..\..\..\..\..\..\..\Data\\ArcGIS_Engine_Developer_Guide\Gulf of St.
Lawrence.mxd";
if (axPageLayoutControl1.CheckMxFile(fileName))
{
axPageLayoutControl1.LoadMxFile(fileName,"");
}
}
----------------------------------------------------------------------------------------------------------------- 6
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
axMapControl1.Extent = axMapControl1.FullExtent;
}
----------------------------------------------------------------------------------------------------------------- 7
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------- 8
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------- 9
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
protected override void OnNotifyMessage(System.Windows.Forms.Message m)
{
base.OnNotifyMessage (m);
if (m.Msg == WM_ENTERSIZEMOVE)
{
axMapControl1.SuppressResizeDrawing(true, 0);
axPageLayoutControl1.SuppressResizeDrawing(true, 0);
}
else if (m.Msg == WM_EXITSIZEMOVE)
{
axMapControl1.SuppressResizeDrawing(false, 0);
axPageLayoutControl1.SuppressResizeDrawing(false, 0);
}
}
ArcGIS Engine xy dng trn 120 cu lnh v cng c lm vic trc tip
vi MapControl, PageLayoutControl v ToolbarControl. Nhng cu lnh v cng
c ny cung cp cho bn rt nhiu cc chc nng GIS c s dng thng xuyn
cho vic iu chnh bn , qun l nh v la chn cc tnh nng. Bn s thm
nhng cu lnh v cng c vo ng dng ca bn.
----------------------------------------------------------------------------------------------------------------- 10
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
"esriControlToolsPageLayout.ControlsPageZoomPageToLastExtentBackCommand";
axToolbarControl1.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID =
"esriControlToolsPageLayout.ControlsPageZoomPageToLastExtentForwardCommand";
axToolbarControl1.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
//Thm
//Thm nhng cu lnh iu chnh Map.
progID = "esriControlToolsMapNavigation.ControlsMapZoomInTool";
axToolbarControl1.AddItem(progID, -1, -1, true, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID = "esriControlToolsMapNavigation.ControlsMapZoomOutTool";
axToolbarControl1.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID = "esriControlToolsMapNavigation.ControlsMapPanTool";
axToolbarControl1.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
progID = "esriControlToolsMapNavigation.ControlsMapFullExtentCommand";
axToolbarControl1.AddItem(progID, -1, -1, false, 0,
esriCommandStyles.esriCommandStyleIconOnly);
}
----------------------------------------------------------------------------------------------------------------- 11
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------- 12
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
2. Thm nhng dng code sau vo s kin Form_Load tip theo nhng dng
code thm cc lnh vo ToolbarControl, nhng trc cc dng code np (load)
bn :
----------------------------------------------------------------------------------------------------------------- 13
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
5.Xy dng v chy th chng trnh. Kch chut phi ln vng hin th ca
PageLayoutControl hin th popup menu, v sau iu chnh quanh page
layout.
Theo mc nh, TOCControl cho php ngi dng thit t vic n hay hin
ca cc lp v thay i bn v tn cc lp khi chng xut hin. Bn s thm code
ngn cn user chnh sa tn v thay th chng vi mt chui trng.
1.Thm nhng dng code vo u s kin Form_Load:
private
private void Form1_Load(object sender, System.EventArgs e)
{
axTOCControl1.LabelEdit = esriTOCControlEdit.esriTOCControlManual;
//Thm nhng cu lnh chung
}
----------------------------------------------------------------------------------------------------------------- 14
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------- 15
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
2. To mt hm mi gi l CreateOverviewSymbol. y l ni bn s to ra cc
biu tng c s dng trong MapControl i din cho phm vi ca d
liu trong bn ca PageLayoutControl. Thm nhng dng code sau to
ra hm:
----------------------------------------------------------------------------------------------------------------- 16
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------- 17
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
axMapControl1.LoadMxFile(axPageLayoutControl1.DocumentFilename,null,null);
//t
//t phm vi ca MapControl vi pham vi y ca d liu.
axMapControl1.Extent = axMapControl1.FullExtent;
}
----------------------------------------------------------------------------------------------------------------- 18
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
To cng c mi
namespace CSharpDotNETCommands
{
.
using System;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.ControlCommands;
using ESRI.ArcGIS.Utility.BaseClasses;
using System.Runtime.InteropServices;
public AddDateTool()
{
//Ly mng cc ti nguyn trong Assembly.
string[] res = GetType().Assembly.GetManifestResourceNames();
//Thit t thuc tnh cho cng c.
base.m_bitmap = new
System.Drawing.Bitmap(GetType().Assembly.GetManifestResourceStream(res[0]));
base.m_caption = Add Date;
base.m_category = "CustomCommands";
base.m_message = "Adds a date element to the page layout";
base.m_name = "CustomCommands_Add Date";
base.m_toolTip = "Add date";
}
----------------------------------------------------------------------------------------------------------------- 20
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------- 21
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
textSymbol.Size = 25;
//Thit t thuc tnh ca vn bn.
textElement.Symbol = textSymbol;
textElement.Text = DateTime.Now.ToShortDateString();
//QI cho IElement.
IElement element = (IElement) textElement;
//To mt page point.
IPoint point = new PointClass();
point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(X,Y);
//Thit t elements geometry
element.Geometry = point;
activeView.GraphicsContainer.AddElement(element, 0);
//Lm ti graphics.
activeView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null,
null);
}
[ClassInterface(ClassInterfaceType.None)]
[Guid("D880184E-AC81-47E5-B363-781F4DC4528F")]
22. Thm nhng dng m vo lop AddDateTool sau khi khai bo bin.on code
nh ngha cc hm ng k v khng ng k lp AddDateTool vi loi
thnh phn ESRI Controls Commands s dng cc loi tin ch (categories
utility.)
----------------------------------------------------------------------------------------------------------------- 22
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
regKey.CreateSubKey("{B284D891-22EE-4F12-A0A9-
B1DDED9197F4}");
}
}
[ComUnregisterFunction()]
[ComVisible(false)]
static void UnregisterFunction(String sKey)
{
string fullKey = sKey.Remove(0, 18) + @"\Implemented Categories";
Microsoft.Win32.RegistryKey regKey =
Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(fullKey, true);
if (regKey != null)
{
regKey.DeleteSubKey("{B284D891-22EE-4F12-A0A9-B1DDED9197F4}");
}
}
#endregion
----------------------------------------------------------------------------------------------------------------- 23
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
C nhn ha ToolbarControl
private ITransformEvents_VisibleBoundsUpdatedEventHandler
visBoundsUpdatedE;
private ICustomizeDialog m_CustomizeDialog = new
CustomizeDialogClass();
//CustomizeDialog c s dng bi ToolbarControl.
private ICustomizeDialogEvents_OnStartDialogEventHandler
startDialogE;
private ICustomizeDialogEvents_OnCloseDialogEventHandler
closeDialogE;
----------------------------------------------------------------------------------------------------------------- 24
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
2.To mt hm mi c tn l CreateCustomizeDialog. y l ni bn s to
mt hp thoi customize bng cch thm nhng cu lnh sau trong hm:
startDialogE = new
ICustomizeDialogEvents_OnStartDialogEventHandler(OnStartDialog);
((ICustomizeDialogEvents_Event)m_CustomizeDialog).OnStartDialog +=
startDialogE;
closeDialogE = new
ICustomizeDialogEvents_OnCloseDialogEventHandler(OnCloseDialog);
((ICustomizeDialogEvents_Event)m_CustomizeDialog).OnCloseDialog +=
closeDialogE;
//Thit t ta
m_CustomizeDialog.DialogTitle = Customize ToolbarControl Items;
//Hin th nt lnh Add from file
m_CustomizeDialog.ShowAddFromFile = true;
//Thit t ToolbarControl c th thm cc item.
m_CustomizeDialog.SetDoubleClickDestination(axToolbarControl1);
}
----------------------------------------------------------------------------------------------------------------- 25
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
m_CustomizeDialog.StartDialog(axToolbarControl1.hWnd);
axToolbarControl1.Customize = true;
}
}
----------------------------------------------------------------------------------------------------------------- 26
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------- 27
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows
Nguyn Hong Minh
----------------------------------------------------------------------------------------------------------------------
+ File chy ca chng trnh v DLL cha lnh c nhn ha cn c trin khai
trn cc my khch. Cng c ng k thnh phn (RegAsm.exe) c s dng
thm thng tin v cc lp c xy dng vi registry.
+My khch cn phi ci t ArcGIS Engine Runtime v bn quyn ArcGIS
Engine tiu chun.
+My khch phi c ci t .NET Framework 1.1.
----------------------------------------------------------------------------------------------------------------- 28
Xy dng ng dng ArcGIS Engine vi cc iu khin Windows