3、实现MapView和MapLayout切换:
在tabControl1_SelectedIndexChanged事件中添加如下代码:
private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) {
if (tabControl1.SelectedIndex == 1) //Map Layout {
layersLegend1.IsLayoutView = true;
mapLayout1.PaintGraphics(); mapLayout1.Refresh(); }
else if (tabControl1.SelectedIndex == 0) //Map view {
layersLegend1.IsLayoutView = false;
mapView1.IsLayoutMap = false;
mapView1.ZoomToExtent(mapView1.ViewExtent); } }
4、添加图层:
在工具栏中加一个添加图层按钮,并在其Click事件中添加如下代码: private void TSB_AddLayer_Click(object sender, EventArgs e) {
OpenFileDialog aDlg = new OpenFileDialog(); aDlg.Filter = \Formats|*.shp;*.wmp;*.bln;*.bmp;*.gif;*.jpg;*.tif;*.png|Shape File (*.shp)|*.shp|WMP File (*.wmp)|*.wmp|BLN File (*.bln)|*.bln|\
\Image (*.bmp)|*.bmp|Gif Image (*.gif)|*.gif|Jpeg Image (*.jpg)|*.jpg|Tif Image (*.tif)|*.tif|Png Iamge (*.png)|*.png|All Files (*.*)|*.*\
if (aDlg.ShowDialog() == DialogResult.OK) {
string aFile = aDlg.FileName;
MapLayer aLayer = MapDataManage.OpenLayer(aFile); layersLegend1.ActiveMapFrame.AddLayer(aLayer); layersLegend1.Refresh(); } }
5、设置MapView和MapLayout的初始鼠标工具:
在主窗体的创建函数中在InitializeComponent()后加入如下代码: mapView1.MouseTool = MouseTools.Pan;
mapLayout1.MouseMode = MouseMode.Select;