By instantiating a new LineLabelPosition class, I've made the properties set correctly in label placement properties dialog now.
However, labels are not showing up automatically for my layer. I have to go to the Layer Properties dialog, simply open the Placement Properties dialog and click OK to close it, and click Apply to make the labels show up.
I've searched the forums and found that people had the same problem back in 2003. Since ESRI is so great in helping our community, I wouldn't believe that the problem has not been solved after 10 years. I must have missed something simple. Please help! my code looks like this now:
Private Sub CreateLabels(ByRef layer As IGeoFeatureLayer) Dim labelClasses As IAnnotateLayerPropertiesCollection labelClasses = layer.AnnotationProperties Dim labelClass As IAnnotateLayerProperties = Nothing labelClasses.QueryItem(0, labelClass, Nothing, Nothing) Dim label1 As ILabelEngineLayerProperties = labelClass CType(label1, IAnnotateLayerProperties).Class = "Label at start" CType(label1, IAnnotateLayerProperties).DisplayAnnotation = True label1.Expression = "[Line_Name]" Dim overposterLayerProperties As IBasicOverposterLayerProperties4 overposterLayerProperties = label1.BasicOverposterLayerProperties
Dim label1Position As ILineLabelPosition = New LineLabelPosition() label1Position.Above = False label1Position.OnTop = True label1Position.AtStart = True overposterLayerProperties.LineLabelPosition = label1Position
overposterLayerProperties.LabelWeight = 3 overposterLayerProperties.FeatureWeight = 3 End Sub