[VB.NET写法]
Private Sub LabelFeature(ByVal pFeaturelayer As IFeatureLayer, ByVal pServerContext As IServerContext)
Dim pGeoFeatureLayer As IGeoFeatureLayer
pGeoFeatureLayer = pFeaturelayer
pGeoFeatureLayer .AnnotationProperties.Clear()
Dim pAnnoLayerProColl As IAnnotateLayerPropertiesCollection
Dim pLabelEngine As ILabelEngineLayerProperties
pAnnoLayerProColl = pGeoFeatureLayer .AnnotationProperties
Dim pAnnoLayerProps As IAnnotateLayerProperties
pLabelEngine = pServerContext.CreateObject("esriCarto.LabelEngineLayerProperties")
pLabelEngine .Expression = "[Filed]"
pAnnoLayerProps = pLabelEngine
'pAnnoLayerProps.LabelWhichFeatures = esriSelectedFeatures '转换Graphic时可以利用
pAnnoLayerProColl .Add(pAnnoLayerProps)
pGeoFeatureLayer.DisplayAnnotation = True
End Sub
[C#写法]
private void LabelField(IFeatureLayer pFeatureLayer,IServerContext pServerContext)
{
IGeoFeatureLayer pGeoFeatureLayer = pFeatureLayer as IGeoFeatureLayer;
pGeoFeatureLayer.AnnotationProperties.Clear();
IAnnotateLayerPropertiesCollection pAnnoLayerPropsColl = pGeoFeatureLayer.AnnotationProperties;
ILabelEngineLayerProperties pLabelEngine;
pLabelEngine = pServerContext.CreateObject("esriCarto.LabelEngineLayerProperties") as ILabelEngineLayerProperties;
pLabelEngine.Expression = "[Field]";
IAnnotateLayerProperties pAnnoLayerProps = pLabelEngine as IAnnotateLayerProperties;
pAnnoLayerPropsColl.Add(pAnnoLayerProps);
pGeoFeatureLayer.DisplayAnnotation = true;
}