Category / Section
Sometimes labels are drawn outside my symbol. Why?
2 mins read
Sometimes labels are drawn outside my symbol. Why?
When you add a label to your symbol and specify its anchor using the BoxPosition Enumeration, you need to remember that the label's anchor point will be its center. Therefore, by specifying BoxPosition.TopLeft, you are setting the center/anchor point of the label to be the top left of your symbol. To ensure that the label text is within the symbol, you should set appropriate offsets, such as if you want the label to begin at the top left of your symbol:
[C#]
//Add new label to MySymbol Label lbl = AddLabel("My Symbol", BoxPosition.TopLeft); //Offsets for the label lbl.OffsetX = this.lbl.Width/2; lbl.OffsetY = this.lbl.Height/2;
[VB.NET]
'Add new label to MySymbol Dim lbl As Label = AddLabel("My Symbol",BoxPosition.TopLeft) 'Offsets for the label lbl.OffsetX = Me.lbl.Width/2 lbl.OffsetY = Me.lbl.Height/2