ArcEngine想要不依靠按钮完成矢量图层的简单渲染
主窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
namespace GIS软件
{
public partial class FormGIS : Form
{
public FormGIS(/*string Form_name*/)
{
InitializeComponent();
//this.Text = Form_name;
//this.StartPosition = FormStartPosition.CenterScreen;
}
private void FormGIS_Load(object sender, EventArgs e)
{
}
private void 输入矢量文件ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ofDShp.ShowDialog() == DialogResult.OK)
{
//string sFile = ofDShp.FileName;
//string sFile_path = sFile.Substring(0, sFile.LastIndexOf('\\'));
//string sFile_name = sFile.Substring(sFile.LastIndexOf('\\') + 1);
FileInfo sFile = new FileInfo(ofDShp.FileName);
//string sFile_path = sFile.Directory.ToString();
string sFile_path = sFile.DirectoryName;
string sFile_name = sFile.Name;
axMapControl1.AddShapeFile(sFile_path, sFile_name);
}
axMapControl1.Refresh();
}
private void 简单渲染HSVToolStripMenuItem_Click(object sender, EventArgs e)
{
FormHSV hsvFsimpleRender = new FormHSV(this.axMapControl1);
//hsvFsimpleRender.Show();
if (hsvFsimpleRender.ShowDialog() == DialogResult.OK)
{
IHsvColor hsvFeature = new HsvColor();
hsvFeature.Hue = hsvFsimpleRender.H;
hsvFeature.Saturation = hsvFsimpleRender.S;
hsvFeature.Value = hsvFsimpleRender.V;
ISimpleFillSymbol sfsFeature = new SimpleFillSymbol();
sfsFeature.Style = esriSimpleFillStyle.esriSFSSolid;
sfsFeature.Outline.Width = 1;
sfsFeature.Color = hsvFeature as IColor;
ISimpleRenderer srFeature = new SimpleRenderer();
srFeature.Symbol = sfsFeature as ISymbol;
IFeatureLayer flWord = null; /*axMapControl1.get_Layer(0) as IFeatureLayer;*/
int IlayerCount = axMapControl1.LayerCount;
for (int i = 0; i < IlayerCount; i++)
{
ILayer iLayerTemp = axMapControl1.get_Layer(i);
if (hsvFsimpleRender.Strlayername == iLayerTemp.Name)
{
flWord = iLayerTemp as IFeatureLayer;
}
}
//if (flWord == null)
//{
// MessageBox.Show("您当前选择的图层不是矢量图层,请重新选择后,在进行渲染!");
// return;
//}
IGeoFeatureLayer gflWord = flWord as IGeoFeatureLayer;
gflWord.Renderer = srFeature as IFeatureRenderer;
axMapControl1.Refresh();
}
}
}
}
调用的简单渲染HSV窗体
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
namespace GIS软件
{
public partial class FormHSV : Form
{
AxMapControl axMapControl1;
string m_StrlayerName;
int m_iundH;
int m_iundS;
int m_iundV;
public string Strlayername
{
get
{
return m_StrlayerName = CBlayers.Text;
}
set
{
m_StrlayerName = value;
}
}
public int H
{
get
{
return m_iundH = tbH.Value;
}
set
{
m_iundH = value;
}
}
public int S
{
get
{
return m_iundS = tbS.Value;
}
set
{
m_iundS = value;
}
}
public int V
{
get
{
return m_iundV = tbV.Value;
}
set
{
m_iundV = value;
}
}
public FormHSV()
{
InitializeComponent();
}
public FormHSV(AxMapControl mapForRender)
{
InitializeComponent();
axMapControl1 = mapForRender;
}
private void FormHSV_Load(object sender, EventArgs e)
{
int IlayerCount = axMapControl1.LayerCount;
for (int i = 0; i < IlayerCount; i++)
{
string sLayerName = axMapControl1.get_Layer(i).Name;
CBlayers.Items.Add(sLayerName as object);
}
}
private void btOK_Click(object sender, EventArgs e)
{
m_StrlayerName = CBlayers.Text;
m_iundH = tbH.Value;
m_iundS = tbS.Value;
m_iundV = tbV.Value;
this.DialogResult = DialogResult.OK;
}
private void btNO_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
}
private void tbH_Scroll(object sender, EventArgs e)
{
//MessageBox.Show(tbH.Value.ToString());
m_StrlayerName = CBlayers.Text;
m_iundH = tbH.Value;
m_iundS = tbS.Value;
m_iundV = tbV.Value;
}
}
}
不利用按钮直接滑动trackbar的滑块就可以实时改变图层颜色