大赵传奇

援引事类,扬搉古今,举要删芜,言辩而理切--QQ276605216

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
  1 using System;
  2 using System.Collections.Generic;
  3 using System.ComponentModel;
  4 using System.Data;
  5 using System.Drawing;
  6 using System.Linq;
  7 using System.Text;
  8 using System.Windows.Forms;
  9 using ESRI.ArcGIS.Geometry;
 10 using ESRI.ArcGIS.Controls;
 11 using System.Runtime.InteropServices;
 12 using ESRI.ArcGIS.Display;
 13 
 14 namespace WindowsFormsApplication2
 15 {
 16     public partial class Form1 : Form
 17     {
 18         public Form1()
 19         {
 20             InitializeComponent();            
 21         }
 22 
 23 
 24         double xmin, ymin, xmax, ymax;
 25         double Xmin, Ymin, Xmax, Ymax;
 26         int Xvalue = 0;
 27         int Yvalue = 0;
 28         int Xlarge = 0;
 29         int Ylarge = 0;
 30         double heightFullenv, h, widthFullEnv, w;
 31         double initScale = 0d;
 32         int vscrollMaxium = 0;
 33         int hscrollMaxium = 0;
 34 
 35         IEnvelope pEnvMap = null;
 36         IMapControl2 pMapControl = null;
 37         private void axMapControl1_OnExtentUpdated(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnExtentUpdatedEvent e)
 38         {
 39             pEnvMap = e.newEnvelope as IEnvelope;
 40             pMapControl = axMapControl1.Object as IMapControl2;
 41             if(initScale < 1)
 42                 initScale = pMapControl.MapScale;
 43 
 44             xmin = pEnvMap.XMin;
 45             ymin = pEnvMap.YMin;
 46             xmax = pEnvMap.XMax;
 47             ymax = pEnvMap.YMax;
 48             w = pEnvMap.Width;
 49             h = pEnvMap.Height;
 50             lblLeftBottom.Text = Math.Round(pEnvMap.XMin,2).ToString() + "," + Math.Round(pEnvMap.YMin,2).ToString();
 51             lblRightTop.Text = Math.Round(pEnvMap.XMax, 2).ToString() + "," + Math.Round(pEnvMap.YMax, 2).ToString();
 52             lblw.Text = pEnvMap.Width.ToString();
 53 
 54 
 55             IEnvelope pEnvFull = pMapControl.ActiveView.FullExtent as IEnvelope;
 56             Xmin = pEnvFull.XMin;
 57             Ymin = pEnvFull.YMin;
 58             Xmax = pEnvFull.XMax;
 59             Ymax = pEnvFull.YMax;
 60             widthFullEnv = pEnvFull.Width;
 61             heightFullenv = pEnvFull.Height;
 62             lblLeftBottomFull.Text = Math.Round(pEnvFull.XMin, 2).ToString() + "," + Math.Round(pEnvFull.YMin, 2).ToString();
 63             lblRightTopFull.Text = Math.Round(pEnvFull.XMax, 2).ToString() + "," + Math.Round(pEnvFull.YMax, 2).ToString();
 64             lblWf.Text = pEnvFull.Width.ToString();
 65 
 66 
 67             if (Ymax > ymax && ymin > Ymin)
 68             {
 69                 vscrollMaxium = (int)(heightFullenv / 100);
 70                 Yvalue = (int)( (Ymax - ymax) / 100);
 71                 Ylarge = (int)(h / 100);
 72                 if (Yvalue + Ylarge > vscrollMaxium)
 73                 {
 74                     Yvalue = vscrollMaxium - Ylarge;
 75                 }                
 76             }
 77             else if (ymax > Ymax)
 78             {
 79                 vscrollMaxium = (int)((ymax - Ymin) / 100);
 80                 Yvalue = 0;
 81                 Ylarge = (int)(h / 100);
 82             }
 83             else if (Ymin > ymin)
 84             {
 85                 vscrollMaxium = (int)((Ymax - ymin) / 100);
 86                 Ylarge = (int)(h / 100);
 87                 Yvalue = vscrollMaxium - Ylarge + 3;
 88             }
 89             this.vScrollBar1.Maximum = vscrollMaxium;
 90             this.vScrollBar1.LargeChange = Ylarge;
 91             this.vScrollBar1.Value = Yvalue;
 92             this.vScrollBar1.SmallChange = (int)(4 * (initScale / pMapControl.MapScale));
 93 
 94 
 95             if (Xmax > xmax && xmin > Xmin)
 96             {
 97                 hscrollMaxium = (int)(widthFullEnv / 100);
 98                 Xvalue = (int)((xmin - Xmin) / 100);
 99                 Xlarge = (int)(w / 100);
100                 if (Xvalue + Xlarge > hscrollMaxium)
101                 {
102                     Xvalue = hscrollMaxium - Xlarge;
103                 }
104             }
105             else if (xmax > Xmax)
106             {
107                 hscrollMaxium = (int)((xmax - Xmin) / 100);
108                 Xlarge = (int)(w / 100);
109                 Xvalue = hscrollMaxium - Xlarge + 3;
110             }
111             else if (Xmin > xmin)
112             {
113                 hscrollMaxium = (int)((Xmax - xmin) / 100);
114                 Xvalue = 0;
115                 Xlarge = (int)(w / 100);
116             }
117             this.hScrollBar1.Maximum = hscrollMaxium;
118             this.hScrollBar1.LargeChange = Xlarge;
119             this.hScrollBar1.Value = Xvalue;
120             this.hScrollBar1.SmallChange = (int)(4 * (initScale / pMapControl.MapScale));
121 
122 
123 
124             lblYscroll.Text = "Large:" + Ylarge.ToString() + ",Value:" + Yvalue.ToString() +
125                 ",Small:" + vScrollBar1.SmallChange.ToString() + ",Max:" + vScrollBar1.Maximum.ToString();
126         }
127 
128 
129         private void btnSetDemo_Click(object sender, EventArgs e)
130         {
131             int max = 0;
132             int value = 0;
133             int smallchange = 0;
134             int largechange = 0;
135             int.TryParse(this.txtSmallChange.Text, out smallchange);
136             int.TryParse(this.txtMaxinum.Text, out max);
137             int.TryParse(this.txtValue.Text, out value);
138             int.TryParse(txtLargeChange.Text, out largechange);
139             this.vScrollBar3.Maximum = max;
140             this.vScrollBar3.SmallChange = smallchange;
141             this.vScrollBar3.LargeChange = largechange;
142             this.vScrollBar3.Value = value;
143         }
144 
145         private void vScrollBar1_Scroll(object sender, ScrollEventArgs e)
146         {
147             this.axMapControl1.OnExtentUpdated -= this.axMapControl1_OnExtentUpdated;
148             double newheight = (e.OldValue - e.NewValue) * 100;
149             pEnvMap.Offset(0, newheight);
150             this.pMapControl.Extent = pEnvMap;
151             this.axMapControl1.OnExtentUpdated += this.axMapControl1_OnExtentUpdated;
152         }
153 
154         private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
155         {
156             this.axMapControl1.OnExtentUpdated -= this.axMapControl1_OnExtentUpdated;
157             double w = (e.NewValue - e.OldValue) * 100;
158             pEnvMap.Offset(w, 0);
159             this.pMapControl.Extent = pEnvMap;
160             this.axMapControl1.OnExtentUpdated += this.axMapControl1_OnExtentUpdated;
161         }
162 
163 
164     }
165 }
backup_code

 

posted on 2016-12-30 16:24  赵长青  阅读(147)  评论(0编辑  收藏  举报