mapxtreme开发小结2(c#)

  1 // 监听地图控件事件
  2 mapControl1.Map.ViewChangedEvent += new ViewChangedEventHandler(Map_ViewChanged);
  3 mapControl1.Map.Layers.Added += new CollectionEventHandler(Layers_CountChanged);
  4 mapControl1.Map.Layers.Removed += new CollectionEventHandler(Layers_CountChanged);
  5 // 监听地图工具事件
  6 mapControl1.Tools.Activating += new ToolActivatingEventHandler(ToolActivating);
  7 mapControl1.Tools.Activated += new ToolActivatedEventHandler(ToolActivatedFired);
  8 mapControl1.Tools.Used += new ToolUsedEventHandler(ToolUsed);
  9 mapControl1.Tools.Ending += new ToolEndingEventHandler(ToolEnding);
 10 mapControl1.Tools.FeatureAdding += new FeatureAddingEventHandler(FeatureAdding);
 11 mapControl1.Tools.FeatureAdded += new FeatureAddedEventHandler(FeatureAdded);
 12 mapControl1.Tools.FeatureSelecting += new FeatureSelectingEventHandler(FeatureSelecting);
 13 mapControl1.Tools.FeatureSelected += new FeatureSelectedEventHandler(FeatureSelected);
 14 mapControl1.Tools.FeatureChanging += new FeatureChangingEventHandler(FeatureChanging);
 15 mapControl1.Tools.FeatureChanged += new MapInfo.Tools.FeatureChangedEventHandler(FeatureChanged);
 16 mapControl1.Tools.NodeChanging += new NodeChangingEventHandler(NodeChanging);
 17 mapControl1.Tools.NodeChanged += new NodeChangedEventHandler(NodeChanged);
 18 mapControl1.Tools.LabelAdding += new LabelAddingEventHandler(LabelAdding);
 19 mapControl1.Tools.LabelAdded += new LabelAddedEventHandler(LabelAdded);
 20 mapControl1.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.mapControl1_MouseWheel);
 21 
 22 // 监听地图控件事件实现函数部分
 23 private void Map_ViewChanged(object o, ViewChangedEventArgs e) 
 24 {
 25     // Get the map
 26     MapInfo.Mapping.Map map = (MapInfo.Mapping.Map) o;
 27         // Display the zoom level
 28     Double dblZoom = System.Convert.ToDouble(String.Format("{0:E2}",mapControl1.Map.Zoom.Value));
 29     statusBarPanelZoom.Text = "Zoom: " + dblZoom.ToString() + " " + mapControl1.Map.Zoom.Unit.ToString();
 30 }
 31 
 32 // This method makes sure the tool buttons are enabled only if
 33 //  the map contains at least one layer.
 34 private void Layers_CountChanged(object o, CollectionEventArgs e) 
 35 {
 36     EnableToolButtons(mapControl1.Map.Layers.Count > 0);
 37 }
 38 
 39 #region Code reporting relevant map, tool, and mouse events to user
 40         
 41 private void ToolActivating(object sender, ToolActivatingEventArgs e) 
 42 {
 43             // if Activation combo-box is set to cancel this tool, cancel it!
 44             if (e.ToolName == comboCancelActivation.Text) e.Cancel = true;
 45 
 46             txtResults.Text = "ToolActivating: " + e.ToolName + " " + e.ButtonTool
 47                 + " " + (e.Cancel ? "Cancel: " + e.ToString() : e.ToString());
 48             txtResults.Refresh();
 49 }
 50 
 51 private void ToolActivatedFired(object sender, ToolActivatedEventArgs e) 
 52 {
 53             txtResults.Text = txtResults.Text + "\r\nToolActivated: " + e.ToolName + " " + e.ButtonTool;
 54             txtResults.Refresh();
 55 }
 56 
 57 private void ToolUsed(object sender, ToolUsedEventArgs e) 
 58 {
 59             // when starting to use a tool, clear out the Events textbox
 60             if (e.ToolStatus==ToolStatus.Start) txtResults.Text="";
 61 
 62             txtResults.Text = txtResults.Text + "\r\nToolUsed: " + e.ToString();
 63             txtResults.Refresh();
 64 }
 65     
 66 private void ToolEnding(object sender, ToolEndingEventArgs e) 
 67 {
 68             // if ToolEnding combo-box is set to cancel this tool cancel it!
 69             if (e.ToolName == comboCancelToolEnding.Text) e.Cancel = true;
 70 
 71             txtResults.Text = txtResults.Text + "\r\n" + (e.Cancel ? "ToolEnding:  Cancel" : "ToolEnding:");
 72             txtResults.Refresh();
 73 }
 74 
 75 private void FeatureAdding(object sender, FeatureAddingEventArgs e) 
 76 {
 77             if (chkCancelObjAdd.Checked) e.Cancel=true;
 78             
 79             if (e.Feature != null
 80             {
 81                 txtResults.Text = txtResults.Text + "\r\nFeatureAdding: " + (e.Cancel ? "Cancel: " + e.ToString() : e.ToString());
 82                 txtResults.Refresh();
 83             }
 84 }
 85 
 86 private void FeatureAdded(object sender, FeatureAddedEventArgs e) 
 87 {
 88             if (e.Feature != null
 89             {
 90                 txtResults.Text = txtResults.Text + "\r\nFeatureAdded: " + e.ToString();
 91                 txtResults.Refresh();
 92 
 93                 UpdateObjCount();
 94             }
 95 }
 96 
 97 private void FeatureSelecting(object sender, FeatureSelectingEventArgs e)
 98 {
 99             if (chkCancelSelect.Checked) e.Cancel=true;
100 
101             txtResults.Text = txtResults.Text + "\r\nFeatureSelecting:  " + (e.Cancel ? "Cancel" : e.ToString());
102             txtResults.Refresh();
103 }
104 
105 private void FeatureSelected(object sender, FeatureSelectedEventArgs e) 
106 {
107             txtResults.Text = txtResults.Text + "\r\nFeatureSelected:  " + e.ToString();
108             txtResults.Refresh();
109 
110             UpdateSelCount();
111 }
112 
113 private void FeatureChanging(object sender, FeatureChangingEventArgs e) 
114 {
115             if (chkCancelObjChanges.Checked) e.Cancel=true;
116 
117             txtResults.Text = txtResults.Text + "\r\nFeatureChanging:  " + (e.Cancel ? "Cancel" : e.ToString());
118             txtResults.Refresh();
119 }
120 
121 private void FeatureChanged(object sender, MapInfo.Tools.FeatureChangedEventArgs e) 
122 {
123             txtResults.Text = txtResults.Text + "\r\nFeatureChanged:  " + e.ToString();
124             txtResults.Refresh();
125 
126             UpdateObjCount();
127 }
128 
129 private void NodeChanging(object sender, NodeChangingEventArgs e) 
130 {
131             if (chkCancelNodeEdit.Checked) e.Cancel=true;
132 
133             txtResults.Text = txtResults.Text + "\r\nNodeChanging:  " + (e.Cancel ? "Cancel" : e.ToString());
134             txtResults.Refresh();
135 }
136 
137 private void NodeChanged(object sender, NodeChangedEventArgs e) 
138 {
139             txtResults.Text = txtResults.Text + "\r\nNodeChanged:  " + e.ToString();
140             txtResults.Refresh();
141 }
142 
143 private void LabelAdding(object sender, LabelAddingEventArgs e) 
144 {
145             if (chkCancelLabel.Checked) e.Cancel=true;
146 
147             txtResults.Text = txtResults.Text + "\r\nLabelAdding:  " + (e.Cancel ? "Cancel" : e.ToString());
148             txtResults.Refresh();
149 }
150 private void LabelAdded(object sender, LabelAddedEventArgs e) 
151 {
152             txtResults.Text = txtResults.Text + "\r\nLabelAdded:  " + e.ToString();
153             txtResults.Refresh();
154 }
155 
156 private void mapControl1_MouseWheel(object sender, System.Windows.Forms.MouseEventArgs e)
157 {
158             txtResults.Text=txtResults.Text + "\r\nMouseWheel:  Delta=" + e.Delta
159                 + ", X=" + e.X + ", Y=" +e.Y;
160             txtResults.Refresh();
161 }
162 #endregion 
原文地址:https://www.cnblogs.com/aion111/p/1437808.html