当前位置:
文档之家› 【035】自建符号Symbol选择对话框
【035】自建符号Symbol选择对话框
btColor.BackColor = Color.FromArgb(pColor.Red, pColor.Green, pColor.Blue); //赋值线的颜色
nudWidth.Value = Convert.ToDecimal(((ILineSymbol)pStyleGalleryItem.Item).Width 赋值线的宽度
{ IRgbColor pColor =
((IMarkerSymbol)pStyleGalleryItem.Item).Color as IRgbColor;
btColor.BackColor = Color.FromArgb(pColor.Red, pColor.Green, pColor.Blue); //赋值颜色
pSymbologyStyleClass.AddItem(pCurrentStyleGalleryItem, 0);
pSymbologyStyleClass.SelectItem(0); //同时 选中 }
5. 选择项的时候触发:
private void axSymbologyControl1_OnItemSelected(object sender, ISymbologyControlEvents_OnItemSelectedEvent e) {
4. 窗体加载事件:
private void SymbologyFrm_Load(object sender, EventArgs e) {
switch(((IFeatureLayer)pLayer).FeatureClass.ShapeType) // 判断图层中要素类的图形类型,不同类型显示的调节值的控件不同
axSymbologyControl1.LoadStyleFile(stylePath); //加 载此文件
axSymbologyControl1.StyleClass = pStyleClass; //将上面获得的 pStyleClass 赋值过去,显示 点、线还是面,由此决定!
IStyleGalleryItem pCurrentStyleGalleryItem = new StyleGalleryItem(); //新建当前符号的实例
} }
6. 将 pStyleGalleryItem 反映到 picture 上的方法:
private void PreviewPicture() {
ISymbologyStyleClass pSymbologyStyle = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleCl 因为其有方法 PreviewStyle
lbWidth.Visible = true; lbWidth.Text = "框线宽度"; lbOutlineColor.Visible = true; btColor.Visible = true; btOutlineColor.Visible = true; nudWidth.Visible = true; cbColor.Visible = true; cbOutlineColor.Visible = true; break; default: this.Close(); break; } string strInstall = @"C:\Program Files (x86)\ArcGIS"; //安装目录,10中可以用函数获得 RuntimeManager 可以获取! //ESRI.ArcGIS. 可以获得 Engine 的安装目录 string stylePath = strInstall + @"\Styles\ESRI.ServerStyle"; //获取 ESRI.ServerStyle 文件
【035】自建符号Symbol选择对话框
第一步:建立独立的 Windows 窗体: 命名为:SymbologyFrmLee
1. 运行效果如下所示:
2. 全局参数: esriSymbologyStyleClass pStyleClass; //获取显示的为 点类、线类还是填充类等的,赋值给 symbologyControl 控件,然 后就显示这一类符号 public IStyleGalleryItem pStyleGalleryItem; //获取 选择的项 ILegendClass pLegendClass; //获取传递进来的图例 ILayer pLayer; bool contextMenuMoreSymbolInitiated = false; //判断右键菜 单是否已经初始化了
stdole.IPictureDisp picture = pSymbologyStyle.PreviewItem(pStyleGalleryItem, pictureBox1.Width, pictureBox1.Height); //建立实例
Image image = Image.FromHbitmap(new IntPtr(picture.Handle)); //转成 C# 支持的 Image 实例
pColor = ((IFillSymbol)pStyleGalleryItem.Item).Outline.Color as IRgbColor;
btOutlineColor.BackColor = Color.FromArgb(pColor.Red, pColor.Green, pColor.Blue); //赋值边框颜色
{ case
esriGeometryType.esriGeometryPoint: //点 pStyleClass =
esriSymbologyStyleClass.esriStyleClassMarkerSymbols;
lbColor.Visible = true; lbWidth.Visible = true; lbWidth.Text = "符号大小"; lbAngle.Visible = true; btColor.Visible = true; nudWidth.Visible = true; cbColor.Visible = true; nudAngle.Visible = true; break; case esriGeometryType.esriGeometryPolyline: //线 pStyleClass = esriSymbologyStyleClass.esriStyleClassLineSymbols; lbColor.Visible = true; lbColor.Location = System.Drawing.Point.Add(lbColor.Location, new Size(0, 12)); lbWidth.Visible = true; lbWidth.Location = System.Drawing.Point.Add(lbWidth.Location, new Size(0, 24)); lbWidth.Text = "线符号粗细"; btColor.Visible = true; cbColor.Visible = true; btColor.Location = System.Drawing.Point.Add(btColor.Location, new Size(0, 12)); cbColor.Location = System.Drawing.Point.Add(cbColor.Location, new Size(0, 12)); nudWidth.Visible = true; nudWidth.Location = System.Drawing.Point.Add(nudWidth.Location, new Size(0, 24)); break; case esriGeometryType.esriGeometryPolygon: //面 pStyleClass = esriSymbologyStyleClass.esriStyleClassFillSymbols; lbColor.Visible = true;
= "当前符号"; pCurrentStyleGalleryItem.Item = pLegendClass.Symbol; //将当前的图例 symbol 赋值过去 ISymbologyStyleClass pSymbologyStyleClass = axSymbologyControl1.GetStyleClass(axSymbologyControl1.StyleCl 加入这个新建项
pStyleGalleryItem = e.styleGalleryItem as IStyleGalleryItem; //获取选择项
PreviewPicture(); //在图片框中显示
if (((IFeatureLayer)pLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPoint) //点,将属性传递 到调节的控件上
}
if (((IFeatureLayer)pLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolygon) //面
{ IRgbColor pColor =
((IFillSymbol)pStyleGalleryItem.Item).Color as IRgbColor; btColor.BackColor =
}
if (((IFeatureLayer)pLayer).FeatureClass.ShapeType == esriGeometryType.esriGeometryPolyline) //线
{ IRgbColor pColor =
((ILineSymbol)pStyleGalleryItem.Item).Color as IRgbColor;