部分代码:
public static void LayersofLabelSymol(IFeatureLayer mIFeatureLayer,string SymbolFileName ,string strCategory,string SymbolName,string lableFieldsName,int symbol_size,int symbol_offset, System.Drawing.Font LableFont, IRgbColor FontColor, IActiveView mIActiveView)
{
IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)mIFeatureLayer;
IAnnotateLayerPropertiesCollection pCollection;
pCollection = pGeoFeatureLayer.AnnotationProperties;
pGeoFeatureLayer.AnnotationProperties.Clear();
ILabelEngineLayerProperties pEngine = new LabelEngineLayerPropertiesClass();
int i = pGeoFeatureLayer.FeatureClass.Fields.FindField(lableFieldsName);
string lableFields = pGeoFeatureLayer.FeatureClass.Fields.get_Field(i).Name;
if (lableFields == "SHAPE.len")
{
pEngine.Expression = "round(" + "[" + lableFields + "]" + ")";
}
else
{
pEngine.Expression = "[" + lableFields + "]";
}
//string SymbolFileName = "底图符号.ServerStyle";
//string SymbolName = "国道";
//string strCategory = "Text Symbols";
pEngine.Symbol = (ITextSymbol)Get_Symbol(SymbolFileName, SymbolName, strCategory);//根据符号库名、符号名称获取符号
pEngine.Symbol.Size = symbol_size;
//pEngine.Symbol.HorizontalAlignment = esriTextHorizontalAlignment.esriTHACenter;
//pEngine.Symbol.VerticalAlignment = esriTextVerticalAlignment.esriTVACenter;
IAnnotateLayerProperties pLabelEngine = (IAnnotateLayerProperties)pEngine;
pLabelEngine.FeatureLayer = pGeoFeatureLayer;
ITextSymbol pTextSymbol = pEngine.Symbol;
ISimpleTextSymbol simpleTextSymbol = (ISimpleTextSymbol) pTextSymbol;
simpleTextSymbol.YOffset = symbol_offset;//设置符号Y轴偏移量
simpleTextSymbol.VerticalAlignment=esriTextVerticalAlignment.esriTVACenter;//没多大用
IFontDisp pFont = (IFontDisp)ESRI.ArcGIS.ADF.COMSupport.OLE.GetIFontDispFromFont(LableFont);
pTextSymbol.Font = pFont;
pTextSymbol.Color = (IColor)FontColor;
pEngine.Symbol = pTextSymbol;
pLabelEngine.DisplayAnnotation = true;
pLabelEngine.LabelWhichFeatures = esriLabelWhichFeatures.esriVisibleFeatures;
pCollection.Add(pLabelEngine);
pGeoFeatureLayer.DisplayAnnotation = true;
ITrackCancel pCon = new CancelTrackerClass();
pCon.Continue();
pGeoFeatureLayer.Draw(esriDrawPhase.esriDPAnnotation, mIActiveView.ScreenDisplay, pCon);
}