About the ArcReaderControl spatial query Sample
[C#]
SpatialQuery.cs
using System; using System.Windows.Forms; using System.Drawing; using ESRI.ArcGIS.PublisherControls; namespace Query { /// <summary> /// Summary description for Form1. /// </summary> public class SpatialQuery : System.Windows.Forms.Form { public System.Windows.Forms.Button cmdQuery; public System.Windows.Forms.Button cmdFullExtent; public System.Windows.Forms.RadioButton optTool2; public System.Windows.Forms.RadioButton optTool1; public System.Windows.Forms.RadioButton optTool0; public System.Windows.Forms.Button cmdLoad; public System.Windows.Forms.GroupBox Frame1; public System.Windows.Forms.Button cmdFeatureSet1; public System.Windows.Forms.Button cmdFeature3; public System.Windows.Forms.Button cmdFeature2; public System.Windows.Forms.Button cmdFeature1; public System.Windows.Forms.Button cmdFeature0; public System.Windows.Forms.Button cmdFeatureSet0; public System.Windows.Forms.Label lblRecords; public System.Windows.Forms.Label Label2; public System.Windows.Forms.Label Label3; public System.Windows.Forms.Label Label5; public System.Windows.Forms.Label Label6; private AxMSFlexGridLib.AxMSFlexGrid axMSFlexGrid1; private IARFeature m_feature; private IARFeatureSet m_featureSet; private bool m_queryFeatures; private bool m_queryValues; private int m_record; private System.Windows.Forms.OpenFileDialog openFileDialog1; private ESRI.ArcGIS.PublisherControls.AxArcReaderControl axArcReaderControl1; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public SpatialQuery() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call // } /// <summary> /// Clean up any resources being used. /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(SpatialQuery)); this.cmdQuery = new System.Windows.Forms.Button(); this.cmdFullExtent = new System.Windows.Forms.Button(); this.optTool2 = new System.Windows.Forms.RadioButton(); this.optTool1 = new System.Windows.Forms.RadioButton(); this.optTool0 = new System.Windows.Forms.RadioButton(); this.cmdLoad = new System.Windows.Forms.Button(); this.Frame1 = new System.Windows.Forms.GroupBox(); this.cmdFeatureSet1 = new System.Windows.Forms.Button(); this.cmdFeature3 = new System.Windows.Forms.Button(); this.cmdFeature2 = new System.Windows.Forms.Button(); this.cmdFeature1 = new System.Windows.Forms.Button(); this.cmdFeature0 = new System.Windows.Forms.Button(); this.cmdFeatureSet0 = new System.Windows.Forms.Button(); this.lblRecords = new System.Windows.Forms.Label(); this.axMSFlexGrid1 = new AxMSFlexGridLib.AxMSFlexGrid(); this.Label2 = new System.Windows.Forms.Label(); this.Label3 = new System.Windows.Forms.Label(); this.Label5 = new System.Windows.Forms.Label(); this.Label6 = new System.Windows.Forms.Label(); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); this.axArcReaderControl1 = new ESRI.ArcGIS.PublisherControls.AxArcReaderControl(); this.Frame1.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.axMSFlexGrid1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.axArcReaderControl1)).BeginInit(); this.SuspendLayout(); // // cmdQuery // this.cmdQuery.BackColor = System.Drawing.SystemColors.Control; this.cmdQuery.Cursor = System.Windows.Forms.Cursors.Default; this.cmdQuery.Enabled = false; this.cmdQuery.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdQuery.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdQuery.Location = new System.Drawing.Point(368, 8); this.cmdQuery.Name = "cmdQuery"; this.cmdQuery.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdQuery.Size = new System.Drawing.Size(73, 49); this.cmdQuery.TabIndex = 11; this.cmdQuery.Text = "Spatial Query"; this.cmdQuery.UseVisualStyleBackColor = false; this.cmdQuery.Click += new System.EventHandler(this.cmdQuery_Click); // // cmdFullExtent // this.cmdFullExtent.BackColor = System.Drawing.SystemColors.Control; this.cmdFullExtent.Cursor = System.Windows.Forms.Cursors.Default; this.cmdFullExtent.Enabled = false; this.cmdFullExtent.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdFullExtent.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdFullExtent.ImageAlign = System.Drawing.ContentAlignment.BottomCenter; this.cmdFullExtent.Location = new System.Drawing.Point(296, 8); this.cmdFullExtent.Name = "cmdFullExtent"; this.cmdFullExtent.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdFullExtent.Size = new System.Drawing.Size(73, 49); this.cmdFullExtent.TabIndex = 10; this.cmdFullExtent.Text = "FullExtent"; this.cmdFullExtent.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.cmdFullExtent.UseVisualStyleBackColor = false; this.cmdFullExtent.Click += new System.EventHandler(this.cmdFullExtent_Click); // // optTool2 // this.optTool2.Appearance = System.Windows.Forms.Appearance.Button; this.optTool2.BackColor = System.Drawing.SystemColors.Control; this.optTool2.Cursor = System.Windows.Forms.Cursors.Default; this.optTool2.Enabled = false; this.optTool2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.optTool2.ForeColor = System.Drawing.SystemColors.ControlText; this.optTool2.ImageAlign = System.Drawing.ContentAlignment.BottomCenter; this.optTool2.Location = new System.Drawing.Point(224, 8); this.optTool2.Name = "optTool2"; this.optTool2.RightToLeft = System.Windows.Forms.RightToLeft.No; this.optTool2.Size = new System.Drawing.Size(73, 49); this.optTool2.TabIndex = 9; this.optTool2.TabStop = true; this.optTool2.Text = "Pan"; this.optTool2.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.optTool2.UseVisualStyleBackColor = false; this.optTool2.Click += new System.EventHandler(this.CurrentTool_Click); // // optTool1 // this.optTool1.Appearance = System.Windows.Forms.Appearance.Button; this.optTool1.BackColor = System.Drawing.SystemColors.Control; this.optTool1.Cursor = System.Windows.Forms.Cursors.Default; this.optTool1.Enabled = false; this.optTool1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.optTool1.ForeColor = System.Drawing.SystemColors.ControlText; this.optTool1.ImageAlign = System.Drawing.ContentAlignment.BottomCenter; this.optTool1.Location = new System.Drawing.Point(152, 8); this.optTool1.Name = "optTool1"; this.optTool1.RightToLeft = System.Windows.Forms.RightToLeft.No; this.optTool1.Size = new System.Drawing.Size(73, 49); this.optTool1.TabIndex = 8; this.optTool1.TabStop = true; this.optTool1.Text = "ZoomOut"; this.optTool1.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.optTool1.UseVisualStyleBackColor = false; this.optTool1.Click += new System.EventHandler(this.CurrentTool_Click); // // optTool0 // this.optTool0.Appearance = System.Windows.Forms.Appearance.Button; this.optTool0.BackColor = System.Drawing.SystemColors.Control; this.optTool0.Cursor = System.Windows.Forms.Cursors.Default; this.optTool0.Enabled = false; this.optTool0.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.optTool0.ForeColor = System.Drawing.SystemColors.ControlText; this.optTool0.ImageAlign = System.Drawing.ContentAlignment.BottomCenter; this.optTool0.Location = new System.Drawing.Point(80, 8); this.optTool0.Name = "optTool0"; this.optTool0.RightToLeft = System.Windows.Forms.RightToLeft.No; this.optTool0.Size = new System.Drawing.Size(73, 49); this.optTool0.TabIndex = 7; this.optTool0.TabStop = true; this.optTool0.Text = "ZoomIn"; this.optTool0.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.optTool0.UseVisualStyleBackColor = false; this.optTool0.Click += new System.EventHandler(this.CurrentTool_Click); // // cmdLoad // this.cmdLoad.BackColor = System.Drawing.SystemColors.Control; this.cmdLoad.Cursor = System.Windows.Forms.Cursors.Default; this.cmdLoad.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdLoad.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdLoad.ImageAlign = System.Drawing.ContentAlignment.BottomCenter; this.cmdLoad.Location = new System.Drawing.Point(8, 8); this.cmdLoad.Name = "cmdLoad"; this.cmdLoad.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdLoad.Size = new System.Drawing.Size(73, 49); this.cmdLoad.TabIndex = 6; this.cmdLoad.Text = "Open"; this.cmdLoad.TextAlign = System.Drawing.ContentAlignment.TopCenter; this.cmdLoad.UseVisualStyleBackColor = false; this.cmdLoad.Click += new System.EventHandler(this.cmdLoad_Click); // // Frame1 // this.Frame1.BackColor = System.Drawing.SystemColors.Control; this.Frame1.Controls.Add(this.cmdFeatureSet1); this.Frame1.Controls.Add(this.cmdFeature3); this.Frame1.Controls.Add(this.cmdFeature2); this.Frame1.Controls.Add(this.cmdFeature1); this.Frame1.Controls.Add(this.cmdFeature0); this.Frame1.Controls.Add(this.cmdFeatureSet0); this.Frame1.Controls.Add(this.lblRecords); this.Frame1.Controls.Add(this.axMSFlexGrid1); this.Frame1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Frame1.ForeColor = System.Drawing.SystemColors.ControlText; this.Frame1.Location = new System.Drawing.Point(448, 128); this.Frame1.Name = "Frame1"; this.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Frame1.Size = new System.Drawing.Size(241, 369); this.Frame1.TabIndex = 19; this.Frame1.TabStop = false; // // cmdFeatureSet1 // this.cmdFeatureSet1.BackColor = System.Drawing.SystemColors.Control; this.cmdFeatureSet1.Cursor = System.Windows.Forms.Cursors.Default; this.cmdFeatureSet1.Enabled = false; this.cmdFeatureSet1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdFeatureSet1.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdFeatureSet1.Location = new System.Drawing.Point(120, 16); this.cmdFeatureSet1.Name = "cmdFeatureSet1"; this.cmdFeatureSet1.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdFeatureSet1.Size = new System.Drawing.Size(113, 25); this.cmdFeatureSet1.TabIndex = 14; this.cmdFeatureSet1.Text = "<< Previous Feature"; this.cmdFeatureSet1.UseVisualStyleBackColor = false; this.cmdFeatureSet1.Click += new System.EventHandler(this.cmdFeatureSet_Click); // // cmdFeature3 // this.cmdFeature3.BackColor = System.Drawing.SystemColors.Control; this.cmdFeature3.Cursor = System.Windows.Forms.Cursors.Default; this.cmdFeature3.Enabled = false; this.cmdFeature3.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdFeature3.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdFeature3.Location = new System.Drawing.Point(176, 328); this.cmdFeature3.Name = "cmdFeature3"; this.cmdFeature3.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdFeature3.Size = new System.Drawing.Size(57, 33); this.cmdFeature3.TabIndex = 11; this.cmdFeature3.Text = "Flicker"; this.cmdFeature3.UseVisualStyleBackColor = false; this.cmdFeature3.Click += new System.EventHandler(this.cmdFeature_Click); // // cmdFeature2 // this.cmdFeature2.BackColor = System.Drawing.SystemColors.Control; this.cmdFeature2.Cursor = System.Windows.Forms.Cursors.Default; this.cmdFeature2.Enabled = false; this.cmdFeature2.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdFeature2.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdFeature2.Location = new System.Drawing.Point(120, 328); this.cmdFeature2.Name = "cmdFeature2"; this.cmdFeature2.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdFeature2.Size = new System.Drawing.Size(57, 33); this.cmdFeature2.TabIndex = 10; this.cmdFeature2.Text = "Flash"; this.cmdFeature2.UseVisualStyleBackColor = false; this.cmdFeature2.Click += new System.EventHandler(this.cmdFeature_Click); // // cmdFeature1 // this.cmdFeature1.BackColor = System.Drawing.SystemColors.Control; this.cmdFeature1.Cursor = System.Windows.Forms.Cursors.Default; this.cmdFeature1.Enabled = false; this.cmdFeature1.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdFeature1.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdFeature1.Location = new System.Drawing.Point(64, 328); this.cmdFeature1.Name = "cmdFeature1"; this.cmdFeature1.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdFeature1.Size = new System.Drawing.Size(57, 33); this.cmdFeature1.TabIndex = 9; this.cmdFeature1.Text = "CenterAt"; this.cmdFeature1.UseVisualStyleBackColor = false; this.cmdFeature1.Click += new System.EventHandler(this.cmdFeature_Click); // // cmdFeature0 // this.cmdFeature0.BackColor = System.Drawing.SystemColors.Control; this.cmdFeature0.Cursor = System.Windows.Forms.Cursors.Default; this.cmdFeature0.Enabled = false; this.cmdFeature0.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdFeature0.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdFeature0.Location = new System.Drawing.Point(8, 328); this.cmdFeature0.Name = "cmdFeature0"; this.cmdFeature0.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdFeature0.Size = new System.Drawing.Size(57, 33); this.cmdFeature0.TabIndex = 8; this.cmdFeature0.Text = "ZoomTo"; this.cmdFeature0.UseVisualStyleBackColor = false; this.cmdFeature0.Click += new System.EventHandler(this.cmdFeature_Click); // // cmdFeatureSet0 // this.cmdFeatureSet0.BackColor = System.Drawing.SystemColors.Control; this.cmdFeatureSet0.Cursor = System.Windows.Forms.Cursors.Default; this.cmdFeatureSet0.Enabled = false; this.cmdFeatureSet0.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.cmdFeatureSet0.ForeColor = System.Drawing.SystemColors.ControlText; this.cmdFeatureSet0.Location = new System.Drawing.Point(8, 16); this.cmdFeatureSet0.Name = "cmdFeatureSet0"; this.cmdFeatureSet0.RightToLeft = System.Windows.Forms.RightToLeft.No; this.cmdFeatureSet0.Size = new System.Drawing.Size(113, 25); this.cmdFeatureSet0.TabIndex = 7; this.cmdFeatureSet0.Text = "Next Feature >>"; this.cmdFeatureSet0.UseVisualStyleBackColor = false; this.cmdFeatureSet0.Click += new System.EventHandler(this.cmdFeatureSet_Click); // // lblRecords // this.lblRecords.BackColor = System.Drawing.SystemColors.Control; this.lblRecords.Cursor = System.Windows.Forms.Cursors.Default; this.lblRecords.Enabled = false; this.lblRecords.Font = new System.Drawing.Font("Arial", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.lblRecords.ForeColor = System.Drawing.SystemColors.ControlText; this.lblRecords.Location = new System.Drawing.Point(8, 48); this.lblRecords.Name = "lblRecords"; this.lblRecords.RightToLeft = System.Windows.Forms.RightToLeft.No; this.lblRecords.Size = new System.Drawing.Size(225, 17); this.lblRecords.TabIndex = 13; this.lblRecords.Text = "0 of 0 features"; // // axMSFlexGrid1 // this.axMSFlexGrid1.Location = new System.Drawing.Point(8, 72); this.axMSFlexGrid1.Name = "axMSFlexGrid1"; this.axMSFlexGrid1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axMSFlexGrid1.OcxState"))); this.axMSFlexGrid1.Size = new System.Drawing.Size(224, 248); this.axMSFlexGrid1.TabIndex = 25; // // Label2 // this.Label2.BackColor = System.Drawing.SystemColors.Control; this.Label2.Cursor = System.Windows.Forms.Cursors.Default; this.Label2.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label2.ForeColor = System.Drawing.SystemColors.Highlight; this.Label2.Location = new System.Drawing.Point(448, 8); this.Label2.Name = "Label2"; this.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Label2.Size = new System.Drawing.Size(249, 17); this.Label2.TabIndex = 23; this.Label2.Text = "1) Browse to a PMF to load."; // // Label3 // this.Label3.BackColor = System.Drawing.SystemColors.Control; this.Label3.Cursor = System.Windows.Forms.Cursors.Default; this.Label3.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label3.ForeColor = System.Drawing.SystemColors.Highlight; this.Label3.Location = new System.Drawing.Point(448, 24); this.Label3.Name = "Label3"; this.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Label3.Size = new System.Drawing.Size(249, 17); this.Label3.TabIndex = 22; this.Label3.Text = "2) Navigate to some features of interest. "; // // Label5 // this.Label5.BackColor = System.Drawing.SystemColors.Control; this.Label5.Cursor = System.Windows.Forms.Cursors.Default; this.Label5.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label5.ForeColor = System.Drawing.SystemColors.Highlight; this.Label5.Location = new System.Drawing.Point(448, 72); this.Label5.Name = "Label5"; this.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Label5.Size = new System.Drawing.Size(225, 56); this.Label5.TabIndex = 21; this.Label5.Text = "4) Loop through the features to display field values and use the buttons to ident" + "ify each feature on the map."; // // Label6 // this.Label6.BackColor = System.Drawing.SystemColors.Control; this.Label6.Cursor = System.Windows.Forms.Cursors.Default; this.Label6.Font = new System.Drawing.Font("Verdana", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.Label6.ForeColor = System.Drawing.SystemColors.Highlight; this.Label6.Location = new System.Drawing.Point(448, 48); this.Label6.Name = "Label6"; this.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No; this.Label6.Size = new System.Drawing.Size(249, 30); this.Label6.TabIndex = 20; this.Label6.Text = "3) Query the focus map for all visible features within the current map extent. "; // // axArcReaderControl1 // this.axArcReaderControl1.Location = new System.Drawing.Point(8, 64); this.axArcReaderControl1.Name = "axArcReaderControl1"; this.axArcReaderControl1.OcxState = ((System.Windows.Forms.AxHost.State)(resources.GetObject("axArcReaderControl1.OcxState"))); this.axArcReaderControl1.Size = new System.Drawing.Size(432, 424); this.axArcReaderControl1.TabIndex = 24; this.axArcReaderControl1.OnCurrentViewChanged += new ESRI.ArcGIS.PublisherControls.IARControlEvents_Ax_OnCurrentViewChangedEventHandler(this.axArcReaderControl1_OnCurrentViewChanged); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(696, 502); this.Controls.Add(this.axArcReaderControl1); this.Controls.Add(this.Frame1); this.Controls.Add(this.Label2); this.Controls.Add(this.Label3); this.Controls.Add(this.Label5); this.Controls.Add(this.Label6); this.Controls.Add(this.cmdQuery); this.Controls.Add(this.cmdFullExtent); this.Controls.Add(this.optTool2); this.Controls.Add(this.optTool1); this.Controls.Add(this.optTool0); this.Controls.Add(this.cmdLoad); this.Name = "Form1"; this.Text = "SpatialQuery"; this.Closing += new System.ComponentModel.CancelEventHandler(this.Form1_Closing); this.Load += new System.EventHandler(this.Form1_Load); this.Frame1.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.axMSFlexGrid1)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.axArcReaderControl1)).EndInit(); this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.ArcReader)) { if (!ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop)) { MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down."); return; } } Application.Run(new SpatialQuery()); } private void Form1_Load(object sender, System.EventArgs e) { //Load command button images from the resource editor System.Drawing.Bitmap bitmap1 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "browse.bmp")); bitmap1.MakeTransparent(System.Drawing.Color.Teal); cmdLoad.Image = bitmap1; System.Drawing.Bitmap bitmap2 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "ZoomIn.bmp")); bitmap2.MakeTransparent(System.Drawing.Color.Teal); optTool0.Image = bitmap2; System.Drawing.Bitmap bitmap3 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "ZoomOut.bmp")); bitmap3.MakeTransparent(System.Drawing.Color.Teal); optTool1.Image = bitmap3; System.Drawing.Bitmap bitmap4 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "Pan.bmp")); bitmap4.MakeTransparent(System.Drawing.Color.Teal); optTool2.Image = bitmap4; System.Drawing.Bitmap bitmap5 = new System.Drawing.Bitmap (GetType().Assembly.GetManifestResourceStream(GetType(), "FullExtent.bmp")); bitmap5.MakeTransparent(System.Drawing.Color.Teal); cmdFullExtent.Image = bitmap5; } private void cmdFeature_Click(object sender, System.EventArgs e) { Button b = (Button) sender; //Navigate or show the selected feature switch (b.Name) { case "cmdFeature0": m_feature.ZoomTo(); break; case "cmdFeature1": m_feature.CenterAt(); break; case "cmdFeature2": m_feature.Flash(); break; case "cmdFeature3": m_feature.Flicker(); break; } } private void cmdFeatureSet_Click(object sender, System.EventArgs e) { Button b = (Button) sender; switch (b.Name) { case "cmdFeatureSet0": //Next record m_record = m_record + 1; break; case "cmdFeatureSet1": //Previous record m_record = m_record - 1; break; } //Get the next/previous feature m_feature = m_featureSet.get_ARFeature(m_record); //Display attribute values UpdateValueDisplay(); } private void cmdFullExtent_Click(object sender, System.EventArgs e) { double dXmax=0; double dXmin=0; double dYmin=0; double dYmax=0; //Get the coordinates of data's full extent axArcReaderControl1.ARPageLayout.FocusARMap.GetFullExtent(ref dXmin, ref dYmin, ref dXmax, ref dYmax); //Set the extent of the focus map axArcReaderControl1.ARPageLayout.FocusARMap.SetExtent(dXmin, dYmin, dXmax, dYmax); //Refresh the display axArcReaderControl1.ARPageLayout.FocusARMap.Refresh(true); } private void cmdLoad_Click(object sender, System.EventArgs e) { //Open a file dialog for selecting map documents openFileDialog1.Title = "Select Published Map Document"; openFileDialog1.Filter = "Published Map Documents (*.pmf)|*.pmf"; openFileDialog1.ShowDialog(); //Exit if no map document is selected string sFilePath = openFileDialog1.FileName; if (sFilePath == "") return; //Load the specified pmf if (axArcReaderControl1.CheckDocument(sFilePath) == true) { axArcReaderControl1.LoadDocument(sFilePath,""); } else { System.Windows.Forms.MessageBox.Show("This document cannot be loaded!"); return; } //Determine whether permission to search layers and query field values m_queryFeatures = axArcReaderControl1.HasDocumentPermission(esriARDocumentPermissions.esriARDocumentPermissionsQueryFeatures); m_queryValues = axArcReaderControl1.HasDocumentPermission(esriARDocumentPermissions.esriARDocumentPermissionsQueryValues); //Set current tool optTool0.Checked = true; } private void cmdQuery_Click(object sender, System.EventArgs e) { //Determine whether permission to search layers if (m_queryFeatures == false) { System.Windows.Forms.MessageBox.Show("You do not have permission to search for features!"); return; } //Get IARQueryDef interface ArcReaderSearchDefClass searchDef = new ArcReaderSearchDefClass(); //Set the spatial searching to intersects searchDef.SpatialRelationship = esriARSpatialRelationship.esriARSpatialRelationshipIntersects; //Get the coordinates of the current extent double dXmax=0; double dXmin=0; double dYmin=0; double dYmax=0; axArcReaderControl1.ARPageLayout.FocusARMap.GetExtent(ref dXmin, ref dYmin, ref dXmax, ref dYmax); //Set the envelope coordinates as the search shape searchDef.SetEnvelopeShape(dXmin, dYmin, dXmax, dYmax,0); //Get IARFeatureSet interface m_featureSet = axArcReaderControl1.ARPageLayout.FocusARMap.QueryARFeatures(searchDef); //Reset the featureset m_featureSet.Reset(); //Get the IARFeature interface m_feature = m_featureSet.Next(); //Display attribute values m_record = 0; UpdateValueDisplay(); } private void CurrentTool_Click(object sender, System.EventArgs e) { RadioButton b = (RadioButton) sender; //Navigate or show the selected feature switch (b.Name) { //Set current tool case "optTool0": axArcReaderControl1.CurrentARTool = esriARTool.esriARToolMapZoomIn; break; case "optTool1": axArcReaderControl1.CurrentARTool = esriARTool.esriARToolMapZoomOut; break; case "optTool2": axArcReaderControl1.CurrentARTool = esriARTool.esriARToolMapPan; break; } } private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { //Release COM objects ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown(); } private void axArcReaderControl1_OnCurrentViewChanged(object sender, ESRI.ArcGIS.PublisherControls.IARControlEvents_OnCurrentViewChangedEvent e) { bool enabled; //Set the current tool if (axArcReaderControl1.CurrentViewType == esriARViewType.esriARViewTypeNone) { enabled = false; } else if (axArcReaderControl1.CurrentViewType == esriARViewType.esriARViewTypePageLayout) { enabled = false; if (axArcReaderControl1.CurrentARTool != esriARTool.esriARToolNoneSelected) { axArcReaderControl1.CurrentARTool = esriARTool.esriARToolNoneSelected; } } else { enabled = true; if (axArcReaderControl1.CurrentARTool != esriARTool.esriARToolMapZoomIn) { optTool0.Checked = true; } } //Enable\disable controls cmdQuery.Enabled = enabled; optTool0.Enabled = enabled; optTool1.Enabled = enabled; optTool2.Enabled = enabled; cmdFullExtent.Enabled = enabled; } private void UpdateValueDisplay() { Graphics graphics = this.CreateGraphics(); //A grid row for each field if (m_feature == null) { axMSFlexGrid1.Rows = 0; } else { axMSFlexGrid1.Rows = m_feature.FieldCount; } //For each field that isn't the 'Shape' field int iRow=0; int nameWidth=0; int valueWidth=0; string fieldName; string fieldValue; SizeF textSize; for (int i = 0; i<= axMSFlexGrid1.Rows - 1; i++) { if (m_feature.get_FieldType(i) != esriARFieldType.esriARFieldTypeGeometry & (m_feature.get_FieldType(i) != esriARFieldType.esriARFieldTypeRaster) & (m_feature.get_FieldType(i) != esriARFieldType.esriARFieldTypeBlob)) { //Display field names axMSFlexGrid1.Col = 0; axMSFlexGrid1.Row = iRow; fieldName = m_feature.get_FieldAliasName(i); axMSFlexGrid1.Text = fieldName; textSize = graphics.MeasureString(fieldName, Font); if (textSize.Width > nameWidth) { nameWidth = (int) textSize.Width; } //Display field values axMSFlexGrid1.Col = 1; axMSFlexGrid1.Row = iRow; if (m_queryValues == true) { fieldValue = m_feature.get_ValueAsString(i); } else { fieldValue = "No Permission"; } axMSFlexGrid1.Text = fieldValue; textSize = graphics.MeasureString(fieldValue, Font); if (textSize.Width > valueWidth) { valueWidth = (int) textSize.Width; } iRow = iRow + 1; } } //Set column widths textSize = graphics.MeasureString(" ", Font); //textSize is measured in pixels but the FlexGrid expects twips axMSFlexGrid1.set_ColWidth(0, (nameWidth + (int) textSize.Width) * 15); axMSFlexGrid1.set_ColWidth(1, (valueWidth + (int) textSize.Width) * 15); //Enabled/disbale controls bool enabled; if( m_featureSet.ARFeatureCount == 0) { enabled = false; cmdFeatureSet0.Enabled = false; cmdFeatureSet1.Enabled = false; lblRecords.Text = m_record + " of " + m_featureSet.ARFeatureCount; } else if (m_featureSet.ARFeatureCount == 1) { enabled = true; cmdFeatureSet0.Enabled = false; cmdFeatureSet1.Enabled = false; lblRecords.Text = m_record + 1 + " of " + m_featureSet.ARFeatureCount; } else { enabled = true; if (m_record == 0) { cmdFeatureSet1.Enabled = false; } else { cmdFeatureSet1.Enabled = true; } if (m_record + 1 == m_featureSet.ARFeatureCount) { cmdFeatureSet0.Enabled = false; } else { cmdFeatureSet0.Enabled = true; } lblRecords.Text = m_record + 1 + " of " + m_featureSet.ARFeatureCount; } cmdFeature0.Enabled = enabled; cmdFeature1.Enabled = enabled; cmdFeature2.Enabled = enabled; cmdFeature3.Enabled = enabled; //Clean up the Graphics object graphics.Dispose(); } } }
[Visual Basic .NET]
SpatialQuery.vb
Imports ESRI.ArcGIS.PublisherControls Imports ESRI.ArcGIS Public Class SpatialQuery Inherits System.Windows.Forms.Form #Region "Windows Form Designer generated code " Public Sub New() MyBase.New() 'Load runtime If Not RuntimeManager.Bind(ProductCode.ArcReader) Then If Not RuntimeManager.Bind(ProductCode.EngineOrDesktop) Then MessageBox.Show("Unable to bind to ArcGIS runtime. Application will be shut down.") System.Environment.Exit(1) ' Force exit End If End If 'This call is required by the Windows Form Designer. InitializeComponent() End Sub 'Form overrides dispose to clean up the component list. Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean) If Disposing Then If Not components Is Nothing Then components.Dispose() End If End If MyBase.Dispose(Disposing) End Sub 'Required by the Windows Form Designer Private components As System.ComponentModel.IContainer Public WithEvents lblRecords As System.Windows.Forms.Label Public WithEvents Frame1 As System.Windows.Forms.GroupBox Public WithEvents cmdQuery As System.Windows.Forms.Button Public WithEvents cmdFullExtent As System.Windows.Forms.Button Public WithEvents cmdLoad As System.Windows.Forms.Button Public WithEvents Label2 As System.Windows.Forms.Label Public WithEvents Label3 As System.Windows.Forms.Label Public WithEvents Label5 As System.Windows.Forms.Label Public WithEvents Label6 As System.Windows.Forms.Label Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog Public WithEvents optTool2 As System.Windows.Forms.RadioButton Public WithEvents optTool1 As System.Windows.Forms.RadioButton Public WithEvents optTool0 As System.Windows.Forms.RadioButton Friend WithEvents AxMSFlexGrid1 As AxMSFlexGridLib.AxMSFlexGrid 'NOTE: The following procedure is required by the Windows Form Designer 'It can be modified using the Windows Form Designer. 'Do not modify it using the code editor. Public WithEvents cmdFeature3 As System.Windows.Forms.Button Public WithEvents cmdFeature2 As System.Windows.Forms.Button Public WithEvents cmdFeature1 As System.Windows.Forms.Button Public WithEvents cmdFeature0 As System.Windows.Forms.Button Public WithEvents cmdFeatureSet1 As System.Windows.Forms.Button Public WithEvents cmdFeatureSet0 As System.Windows.Forms.Button Friend WithEvents AxArcReaderControl1 As ESRI.ArcGIS.PublisherControls.AxArcReaderControl <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(SpatialQuery)) Me.Frame1 = New System.Windows.Forms.GroupBox Me.AxMSFlexGrid1 = New AxMSFlexGridLib.AxMSFlexGrid Me.cmdFeatureSet1 = New System.Windows.Forms.Button Me.cmdFeature3 = New System.Windows.Forms.Button Me.cmdFeature2 = New System.Windows.Forms.Button Me.cmdFeature1 = New System.Windows.Forms.Button Me.cmdFeature0 = New System.Windows.Forms.Button Me.cmdFeatureSet0 = New System.Windows.Forms.Button Me.lblRecords = New System.Windows.Forms.Label Me.cmdQuery = New System.Windows.Forms.Button Me.cmdFullExtent = New System.Windows.Forms.Button Me.optTool2 = New System.Windows.Forms.RadioButton Me.optTool1 = New System.Windows.Forms.RadioButton Me.optTool0 = New System.Windows.Forms.RadioButton Me.cmdLoad = New System.Windows.Forms.Button Me.Label2 = New System.Windows.Forms.Label Me.Label3 = New System.Windows.Forms.Label Me.Label5 = New System.Windows.Forms.Label Me.Label6 = New System.Windows.Forms.Label Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog Me.AxArcReaderControl1 = New ESRI.ArcGIS.PublisherControls.AxArcReaderControl Me.Frame1.SuspendLayout() CType(Me.AxMSFlexGrid1, System.ComponentModel.ISupportInitialize).BeginInit() CType(Me.AxArcReaderControl1, System.ComponentModel.ISupportInitialize).BeginInit() Me.SuspendLayout() ' 'Frame1 ' Me.Frame1.BackColor = System.Drawing.SystemColors.Control Me.Frame1.Controls.Add(Me.AxMSFlexGrid1) Me.Frame1.Controls.Add(Me.cmdFeatureSet1) Me.Frame1.Controls.Add(Me.cmdFeature3) Me.Frame1.Controls.Add(Me.cmdFeature2) Me.Frame1.Controls.Add(Me.cmdFeature1) Me.Frame1.Controls.Add(Me.cmdFeature0) Me.Frame1.Controls.Add(Me.cmdFeatureSet0) Me.Frame1.Controls.Add(Me.lblRecords) Me.Frame1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText Me.Frame1.Location = New System.Drawing.Point(456, 128) Me.Frame1.Name = "Frame1" Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Frame1.Size = New System.Drawing.Size(241, 369) Me.Frame1.TabIndex = 6 Me.Frame1.TabStop = False ' 'AxMSFlexGrid1 ' Me.AxMSFlexGrid1.ContainingControl = Me Me.AxMSFlexGrid1.Location = New System.Drawing.Point(8, 72) Me.AxMSFlexGrid1.Name = "AxMSFlexGrid1" Me.AxMSFlexGrid1.OcxState = CType(resources.GetObject("AxMSFlexGrid1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxMSFlexGrid1.Size = New System.Drawing.Size(224, 248) Me.AxMSFlexGrid1.TabIndex = 15 ' 'cmdFeatureSet1 ' Me.cmdFeatureSet1.BackColor = System.Drawing.SystemColors.Control Me.cmdFeatureSet1.Cursor = System.Windows.Forms.Cursors.Default Me.cmdFeatureSet1.Enabled = False Me.cmdFeatureSet1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdFeatureSet1.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdFeatureSet1.Location = New System.Drawing.Point(120, 16) Me.cmdFeatureSet1.Name = "cmdFeatureSet1" Me.cmdFeatureSet1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdFeatureSet1.Size = New System.Drawing.Size(113, 25) Me.cmdFeatureSet1.TabIndex = 14 Me.cmdFeatureSet1.Text = "<< Previous Feature" ' 'cmdFeature3 ' Me.cmdFeature3.BackColor = System.Drawing.SystemColors.Control Me.cmdFeature3.Cursor = System.Windows.Forms.Cursors.Default Me.cmdFeature3.Enabled = False Me.cmdFeature3.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdFeature3.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdFeature3.Location = New System.Drawing.Point(176, 328) Me.cmdFeature3.Name = "cmdFeature3" Me.cmdFeature3.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdFeature3.Size = New System.Drawing.Size(57, 33) Me.cmdFeature3.TabIndex = 11 Me.cmdFeature3.Text = "Flicker" ' 'cmdFeature2 ' Me.cmdFeature2.BackColor = System.Drawing.SystemColors.Control Me.cmdFeature2.Cursor = System.Windows.Forms.Cursors.Default Me.cmdFeature2.Enabled = False Me.cmdFeature2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdFeature2.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdFeature2.Location = New System.Drawing.Point(120, 328) Me.cmdFeature2.Name = "cmdFeature2" Me.cmdFeature2.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdFeature2.Size = New System.Drawing.Size(57, 33) Me.cmdFeature2.TabIndex = 10 Me.cmdFeature2.Text = "Flash" ' 'cmdFeature1 ' Me.cmdFeature1.BackColor = System.Drawing.SystemColors.Control Me.cmdFeature1.Cursor = System.Windows.Forms.Cursors.Default Me.cmdFeature1.Enabled = False Me.cmdFeature1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdFeature1.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdFeature1.Location = New System.Drawing.Point(64, 328) Me.cmdFeature1.Name = "cmdFeature1" Me.cmdFeature1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdFeature1.Size = New System.Drawing.Size(57, 33) Me.cmdFeature1.TabIndex = 9 Me.cmdFeature1.Text = "CenterAt" ' 'cmdFeature0 ' Me.cmdFeature0.BackColor = System.Drawing.SystemColors.Control Me.cmdFeature0.Cursor = System.Windows.Forms.Cursors.Default Me.cmdFeature0.Enabled = False Me.cmdFeature0.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdFeature0.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdFeature0.Location = New System.Drawing.Point(8, 328) Me.cmdFeature0.Name = "cmdFeature0" Me.cmdFeature0.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdFeature0.Size = New System.Drawing.Size(57, 33) Me.cmdFeature0.TabIndex = 8 Me.cmdFeature0.Text = "ZoomTo" ' 'cmdFeatureSet0 ' Me.cmdFeatureSet0.BackColor = System.Drawing.SystemColors.Control Me.cmdFeatureSet0.Cursor = System.Windows.Forms.Cursors.Default Me.cmdFeatureSet0.Enabled = False Me.cmdFeatureSet0.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdFeatureSet0.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdFeatureSet0.Location = New System.Drawing.Point(8, 16) Me.cmdFeatureSet0.Name = "cmdFeatureSet0" Me.cmdFeatureSet0.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdFeatureSet0.Size = New System.Drawing.Size(113, 25) Me.cmdFeatureSet0.TabIndex = 7 Me.cmdFeatureSet0.Text = "Next Feature >>" ' 'lblRecords ' Me.lblRecords.BackColor = System.Drawing.SystemColors.Control Me.lblRecords.Cursor = System.Windows.Forms.Cursors.Default Me.lblRecords.Enabled = False Me.lblRecords.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.lblRecords.ForeColor = System.Drawing.SystemColors.ControlText Me.lblRecords.Location = New System.Drawing.Point(8, 48) Me.lblRecords.Name = "lblRecords" Me.lblRecords.RightToLeft = System.Windows.Forms.RightToLeft.No Me.lblRecords.Size = New System.Drawing.Size(225, 17) Me.lblRecords.TabIndex = 13 Me.lblRecords.Text = "0 of 0 features" ' 'cmdQuery ' Me.cmdQuery.BackColor = System.Drawing.SystemColors.Control Me.cmdQuery.Cursor = System.Windows.Forms.Cursors.Default Me.cmdQuery.Enabled = False Me.cmdQuery.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdQuery.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdQuery.Location = New System.Drawing.Point(368, 8) Me.cmdQuery.Name = "cmdQuery" Me.cmdQuery.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdQuery.Size = New System.Drawing.Size(73, 49) Me.cmdQuery.TabIndex = 5 Me.cmdQuery.Text = "Spatial Query" ' 'cmdFullExtent ' Me.cmdFullExtent.BackColor = System.Drawing.SystemColors.Control Me.cmdFullExtent.Cursor = System.Windows.Forms.Cursors.Default Me.cmdFullExtent.Enabled = False Me.cmdFullExtent.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdFullExtent.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdFullExtent.ImageAlign = System.Drawing.ContentAlignment.BottomCenter Me.cmdFullExtent.Location = New System.Drawing.Point(296, 8) Me.cmdFullExtent.Name = "cmdFullExtent" Me.cmdFullExtent.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdFullExtent.Size = New System.Drawing.Size(73, 49) Me.cmdFullExtent.TabIndex = 4 Me.cmdFullExtent.Text = "FullExtent" Me.cmdFullExtent.TextAlign = System.Drawing.ContentAlignment.TopCenter ' 'optTool2 ' Me.optTool2.Appearance = System.Windows.Forms.Appearance.Button Me.optTool2.BackColor = System.Drawing.SystemColors.Control Me.optTool2.Cursor = System.Windows.Forms.Cursors.Default Me.optTool2.Enabled = False Me.optTool2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.optTool2.ForeColor = System.Drawing.SystemColors.ControlText Me.optTool2.ImageAlign = System.Drawing.ContentAlignment.BottomCenter Me.optTool2.Location = New System.Drawing.Point(224, 8) Me.optTool2.Name = "optTool2" Me.optTool2.RightToLeft = System.Windows.Forms.RightToLeft.No Me.optTool2.Size = New System.Drawing.Size(73, 49) Me.optTool2.TabIndex = 3 Me.optTool2.TabStop = True Me.optTool2.Text = "Pan" Me.optTool2.TextAlign = System.Drawing.ContentAlignment.TopCenter ' 'optTool1 ' Me.optTool1.Appearance = System.Windows.Forms.Appearance.Button Me.optTool1.BackColor = System.Drawing.SystemColors.Control Me.optTool1.Cursor = System.Windows.Forms.Cursors.Default Me.optTool1.Enabled = False Me.optTool1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.optTool1.ForeColor = System.Drawing.SystemColors.ControlText Me.optTool1.ImageAlign = System.Drawing.ContentAlignment.BottomCenter Me.optTool1.Location = New System.Drawing.Point(152, 8) Me.optTool1.Name = "optTool1" Me.optTool1.RightToLeft = System.Windows.Forms.RightToLeft.No Me.optTool1.Size = New System.Drawing.Size(73, 49) Me.optTool1.TabIndex = 2 Me.optTool1.TabStop = True Me.optTool1.Text = "ZoomOut" Me.optTool1.TextAlign = System.Drawing.ContentAlignment.TopCenter ' 'optTool0 ' Me.optTool0.Appearance = System.Windows.Forms.Appearance.Button Me.optTool0.BackColor = System.Drawing.SystemColors.Control Me.optTool0.Cursor = System.Windows.Forms.Cursors.Default Me.optTool0.Enabled = False Me.optTool0.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.optTool0.ForeColor = System.Drawing.SystemColors.ControlText Me.optTool0.ImageAlign = System.Drawing.ContentAlignment.BottomCenter Me.optTool0.Location = New System.Drawing.Point(80, 8) Me.optTool0.Name = "optTool0" Me.optTool0.RightToLeft = System.Windows.Forms.RightToLeft.No Me.optTool0.Size = New System.Drawing.Size(73, 49) Me.optTool0.TabIndex = 1 Me.optTool0.TabStop = True Me.optTool0.Text = "ZoomIn" Me.optTool0.TextAlign = System.Drawing.ContentAlignment.TopCenter ' 'cmdLoad ' Me.cmdLoad.BackColor = System.Drawing.SystemColors.Control Me.cmdLoad.Cursor = System.Windows.Forms.Cursors.Default Me.cmdLoad.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.cmdLoad.ForeColor = System.Drawing.SystemColors.ControlText Me.cmdLoad.ImageAlign = System.Drawing.ContentAlignment.BottomCenter Me.cmdLoad.Location = New System.Drawing.Point(8, 8) Me.cmdLoad.Name = "cmdLoad" Me.cmdLoad.RightToLeft = System.Windows.Forms.RightToLeft.No Me.cmdLoad.Size = New System.Drawing.Size(73, 49) Me.cmdLoad.TabIndex = 0 Me.cmdLoad.Text = "Open" Me.cmdLoad.TextAlign = System.Drawing.ContentAlignment.TopCenter ' 'Label2 ' Me.Label2.BackColor = System.Drawing.SystemColors.Control Me.Label2.Cursor = System.Windows.Forms.Cursors.Default Me.Label2.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label2.ForeColor = System.Drawing.SystemColors.Highlight Me.Label2.Location = New System.Drawing.Point(456, 8) Me.Label2.Name = "Label2" Me.Label2.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label2.Size = New System.Drawing.Size(249, 17) Me.Label2.TabIndex = 18 Me.Label2.Text = "1) Browse to a PMF to load." ' 'Label3 ' Me.Label3.BackColor = System.Drawing.SystemColors.Control Me.Label3.Cursor = System.Windows.Forms.Cursors.Default Me.Label3.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label3.ForeColor = System.Drawing.SystemColors.Highlight Me.Label3.Location = New System.Drawing.Point(456, 25) Me.Label3.Name = "Label3" Me.Label3.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label3.Size = New System.Drawing.Size(249, 17) Me.Label3.TabIndex = 17 Me.Label3.Text = "2) Navigate to some features of interest. " ' 'Label5 ' Me.Label5.BackColor = System.Drawing.SystemColors.Control Me.Label5.Cursor = System.Windows.Forms.Cursors.Default Me.Label5.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label5.ForeColor = System.Drawing.SystemColors.Highlight Me.Label5.Location = New System.Drawing.Point(456, 72) Me.Label5.Name = "Label5" Me.Label5.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label5.Size = New System.Drawing.Size(225, 56) Me.Label5.TabIndex = 16 Me.Label5.Text = "4) Loop through the features to display field values and use the buttons to ident" & _ "ify each feature on the map." ' 'Label6 ' Me.Label6.BackColor = System.Drawing.SystemColors.Control Me.Label6.Cursor = System.Windows.Forms.Cursors.Default Me.Label6.Font = New System.Drawing.Font("Verdana", 8.25!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.Label6.ForeColor = System.Drawing.SystemColors.Highlight Me.Label6.Location = New System.Drawing.Point(456, 42) Me.Label6.Name = "Label6" Me.Label6.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Label6.Size = New System.Drawing.Size(249, 30) Me.Label6.TabIndex = 15 Me.Label6.Text = "3) Query the focus map for all visible features within the current map extent. " ' 'AxArcReaderControl1 ' Me.AxArcReaderControl1.Location = New System.Drawing.Point(8, 64) Me.AxArcReaderControl1.Name = "AxArcReaderControl1" Me.AxArcReaderControl1.OcxState = CType(resources.GetObject("AxArcReaderControl1.OcxState"), System.Windows.Forms.AxHost.State) Me.AxArcReaderControl1.Size = New System.Drawing.Size(432, 424) Me.AxArcReaderControl1.TabIndex = 19 ' 'Form1 ' Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13) Me.BackColor = System.Drawing.SystemColors.Control Me.ClientSize = New System.Drawing.Size(708, 504) Me.Controls.Add(Me.AxArcReaderControl1) Me.Controls.Add(Me.Frame1) Me.Controls.Add(Me.cmdQuery) Me.Controls.Add(Me.cmdFullExtent) Me.Controls.Add(Me.optTool2) Me.Controls.Add(Me.optTool1) Me.Controls.Add(Me.optTool0) Me.Controls.Add(Me.cmdLoad) Me.Controls.Add(Me.Label2) Me.Controls.Add(Me.Label3) Me.Controls.Add(Me.Label5) Me.Controls.Add(Me.Label6) Me.Cursor = System.Windows.Forms.Cursors.Default Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte)) Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle Me.Location = New System.Drawing.Point(3, 22) Me.MaximizeBox = False Me.MinimizeBox = False Me.Name = "Form1" Me.RightToLeft = System.Windows.Forms.RightToLeft.No Me.Text = "Query" Me.Frame1.ResumeLayout(False) CType(Me.AxMSFlexGrid1, System.ComponentModel.ISupportInitialize).EndInit() CType(Me.AxArcReaderControl1, System.ComponentModel.ISupportInitialize).EndInit() Me.ResumeLayout(False) End Sub #End Region Private m_pFeature As ARFeature Private m_pFeatureSet As ARFeatureSet Private m_bQueryFeatures As Boolean Private m_bQueryValues As Boolean Private m_lRecord As Integer Private Sub cmdFeature_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFeature0.Click, cmdFeature1.Click, cmdFeature2.Click, cmdFeature3.Click Dim senderName As String senderName = sender.Name 'Navigate or show the selected feature Select Case senderName Case "cmdFeature0" m_pFeature.ZoomTo() Case "cmdFeature1" m_pFeature.CenterAt() Case "cmdFeature2" m_pFeature.Flash() Case "cmdFeature3" m_pFeature.Flicker() End Select End Sub Private Sub cmdFeatureSet_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFeatureSet0.Click, cmdFeatureSet1.Click Dim senderName As String senderName = sender.Name Select Case senderName Case "cmdFeatureSet0" 'Next record m_lRecord = m_lRecord + 1 Case "cmdFeatureSet1" 'Previous record m_lRecord = m_lRecord - 1 End Select 'Get the next/previous feature m_pFeature = m_pFeatureSet.ARFeature(m_lRecord) 'Display attribute values UpdateValueDisplay() End Sub Private Sub cmdFullExtent_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdFullExtent.Click Dim dXmax, dXmin, dYmin, dYmax As Double 'Get the coordinates of data's full extent AxArcReaderControl1.ARPageLayout.FocusARMap.GetFullExtent(dXmin, dYmin, dXmax, dYmax) 'Set the extent of the focus map AxArcReaderControl1.ARPageLayout.FocusARMap.SetExtent(dXmin, dYmin, dXmax, dYmax) 'Refresh the display AxArcReaderControl1.ARPageLayout.FocusARMap.Refresh() End Sub Private Sub cmdLoad_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdLoad.Click 'Open a file dialog for selecting map documents OpenFileDialog1.Title = "Select Published Map Document" OpenFileDialog1.Filter = "Published Map Documents (*.pmf)|*.pmf" OpenFileDialog1.ShowDialog() 'Exit if no map document is selected Dim sFilePath As String sFilePath = OpenFileDialog1.FileName If sFilePath = "" Then Exit Sub 'Load the specified pmf If AxArcReaderControl1.CheckDocument(sFilePath) = True Then AxArcReaderControl1.LoadDocument(sFilePath) Else MsgBox("This document cannot be loaded!") Exit Sub End If 'Determine whether permission to search layers and query field values m_bQueryFeatures = AxArcReaderControl1.HasDocumentPermission(esriARDocumentPermissions.esriARDocumentPermissionsQueryFeatures) m_bQueryValues = AxArcReaderControl1.HasDocumentPermission(esriARDocumentPermissions.esriARDocumentPermissionsQueryValues) 'Set current tool optTool0.Checked = True End Sub Private Sub cmdQuery_Click(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles cmdQuery.Click 'Determine whether permission to search layers If m_bQueryFeatures = False Then MsgBox("You do not have permission to search for features!") Exit Sub End If 'Get IARQueryDef interface Dim pSearchDef As ArcReaderSearchDef pSearchDef = New ArcReaderSearchDef 'Set the spatial searching to intersects pSearchDef.SpatialRelationship = esriARSpatialRelationship.esriARSpatialRelationshipIntersects 'Get the coordinates of the current extent Dim dXmax, dXmin, dYmin, dYmax As Double AxArcReaderControl1.ARPageLayout.FocusARMap.GetExtent(dXmin, dYmin, dXmax, dYmax) 'Set the envelope coordinates as the search shape pSearchDef.SetEnvelopeShape(dXmin, dYmin, dXmax, dYmax) 'Get IARFeatureSet interface m_pFeatureSet = AxArcReaderControl1.ARPageLayout.FocusARMap.QueryARFeatures(pSearchDef) 'Reset the featureset m_pFeatureSet.Reset() 'Get the IARFeature interface m_pFeature = m_pFeatureSet.Next 'Display attribute values m_lRecord = 0 UpdateValueDisplay() End Sub Private Sub Form1_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load 'Load command button images from the resource editor Dim pBitmap As System.Drawing.Bitmap pBitmap = New System.Drawing.Bitmap(GetType(SpatialQuery).Assembly.GetManifestResourceStream(GetType(SpatialQuery), "browse.bmp")) pBitmap.MakeTransparent(System.Drawing.Color.Teal) cmdLoad.Image = pBitmap pBitmap = New System.Drawing.Bitmap(GetType(SpatialQuery).Assembly.GetManifestResourceStream(GetType(SpatialQuery), "ZoomIn.bmp")) pBitmap.MakeTransparent(System.Drawing.Color.Teal) optTool0.Image = pBitmap pBitmap = New System.Drawing.Bitmap(GetType(SpatialQuery).Assembly.GetManifestResourceStream(GetType(SpatialQuery), "ZoomOut.bmp")) pBitmap.MakeTransparent(System.Drawing.Color.Teal) optTool1.Image = pBitmap pBitmap = New System.Drawing.Bitmap(GetType(SpatialQuery).Assembly.GetManifestResourceStream(GetType(SpatialQuery), "Pan.bmp")) pBitmap.MakeTransparent(System.Drawing.Color.Teal) optTool2.Image = pBitmap pBitmap = New System.Drawing.Bitmap(GetType(SpatialQuery).Assembly.GetManifestResourceStream(GetType(SpatialQuery), "FullExtent.bmp")) pBitmap.MakeTransparent(System.Drawing.Color.Teal) cmdFullExtent.Image = pBitmap End Sub Private Sub MixedControlsCurrentTool_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles optTool0.Click, optTool1.Click, optTool2.Click Dim senderName As String senderName = sender.Name Select Case senderName 'Set current tool Case "optTool0" AxArcReaderControl1.CurrentARTool = esriARTool.esriARToolMapZoomIn Case "optTool1" AxArcReaderControl1.CurrentARTool = esriARTool.esriARToolMapZoomOut Case "optTool2" AxArcReaderControl1.CurrentARTool = esriARTool.esriARToolMapPan End Select End Sub Public Sub UpdateValueDisplay() Dim i As Short Dim iRow As Short Dim lNameWidth As Integer Dim lValueWidth As Integer Dim sFieldName As String Dim sFieldValue As String Dim textSize As SizeF Dim pGraphics As Graphics = Me.CreateGraphics() 'A grid row for each field If m_pFeature Is Nothing Then AxMSFlexGrid1.Rows = 0 Else AxMSFlexGrid1.Rows = m_pFeature.FieldCount End If 'For each field that isn't the 'Shape' field For i = 0 To AxMSFlexGrid1.Rows - 1 If m_pFeature.FieldType(i) <> esriARFieldType.esriARFieldTypeGeometry And (m_pFeature.FieldType(i) <> esriARFieldType.esriARFieldTypeRaster) And (m_pFeature.FieldType(i) <> esriARFieldType.esriARFieldTypeBlob) Then 'Display field names AxMSFlexGrid1.Col = 0 AxMSFlexGrid1.Row = iRow sFieldName = m_pFeature.FieldAliasName(i) AxMSFlexGrid1.Text = sFieldName textSize = pGraphics.MeasureString(sFieldName, Font) If textSize.Width > lNameWidth Then lNameWidth = textSize.Width End If 'Display field values AxMSFlexGrid1.Col = 1 AxMSFlexGrid1.Row = iRow If m_bQueryValues = True Then sFieldValue = m_pFeature.ValueAsString(CInt(i)) Else sFieldValue = "No Permission" End If AxMSFlexGrid1.Text = sFieldValue textSize = pGraphics.MeasureString(sFieldValue, Font) If textSize.Width > lValueWidth Then lValueWidth = textSize.Width End If iRow = iRow + 1 End If Next i 'Set column widths textSize = pGraphics.MeasureString(" ", Font) 'textSize is measured in pixels but the FlexGrid expects twips AxMSFlexGrid1.set_ColWidth(0, (lNameWidth + textSize.Width) * 15) AxMSFlexGrid1.set_ColWidth(1, (lValueWidth + textSize.Width) * 15) 'Enabled/disbale controls Dim bEnabled As Boolean If m_pFeatureSet.ARFeatureCount = 0 Then bEnabled = False cmdFeatureSet0.Enabled = False cmdFeatureSet1.Enabled = False lblRecords.Text = m_lRecord & " of " & m_pFeatureSet.ARFeatureCount ElseIf m_pFeatureSet.ARFeatureCount = 1 Then bEnabled = True cmdFeatureSet0.Enabled = False cmdFeatureSet1.Enabled = False lblRecords.Text = m_lRecord + 1 & " of " & m_pFeatureSet.ARFeatureCount Else bEnabled = True If m_lRecord = 0 Then cmdFeatureSet1.Enabled = False Else cmdFeatureSet1.Enabled = True If m_lRecord + 1 = m_pFeatureSet.ARFeatureCount Then cmdFeatureSet0.Enabled = False Else cmdFeatureSet0.Enabled = True lblRecords.Text = m_lRecord + 1 & " of " & m_pFeatureSet.ARFeatureCount End If cmdFeature0.Enabled = bEnabled cmdFeature1.Enabled = bEnabled cmdFeature2.Enabled = bEnabled cmdFeature3.Enabled = bEnabled 'Clean up the Graphics object pGraphics.Dispose() End Sub Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing 'Release COM objects ESRI.ArcGIS.ADF.COMSupport.AOUninitialize.Shutdown() End Sub Private Sub AxArcReaderControl1_OnCurrentViewChanged(ByVal sender As Object, ByVal e As ESRI.ArcGIS.PublisherControls.IARControlEvents_OnCurrentViewChangedEvent) Handles AxArcReaderControl1.OnCurrentViewChanged Dim bEnabled As Boolean 'Set the current tool If AxArcReaderControl1.CurrentViewType = esriARViewType.esriARViewTypeNone Then bEnabled = False ElseIf AxArcReaderControl1.CurrentViewType = esriARViewType.esriARViewTypePageLayout Then bEnabled = False If AxArcReaderControl1.CurrentARTool <> esriARTool.esriARToolNoneSelected Then AxArcReaderControl1.CurrentARTool = esriARTool.esriARToolNoneSelected End If Else bEnabled = True If AxArcReaderControl1.CurrentARTool <> esriARTool.esriARToolMapZoomIn Then optTool0.Checked = True End If End If 'Enable/disbale controls cmdQuery.Enabled = bEnabled optTool0.Enabled = bEnabled optTool1.Enabled = bEnabled optTool2.Enabled = bEnabled cmdFullExtent.Enabled = bEnabled End Sub End Class