Page 1 of 1

Custom Text - Alignment

Posted: Wed Oct 09, 2013 9:26 pm
by 16666763
I'm using this code to add custom text to my chart:

Code: Select all

      .Tools.Add tcAnnotate
      With .Tools.Items(ctr - 1)
          .Active = True
          With .asAnnotation
            .Top = (intRecTop + 5) + (intTextHeight * (ctr - 1))
            .Left = intRecLeft
            
            
            With .Shape
              .TextAlignment = taRightJustify
              .Transparent = True
              .Transparency = 100
              .ShapeStyle = fosSquareRectangle
              .Font.Color = vbBlue
            End With
            .Text = Format(macurMoTotals(ctr), "$#,##0")
          End With
      End With
This is in a loop that adds 3 lines (each in separate shapes).

I'm trying to get them to Right Align with each other, but the above code does not do that. I also tried moving .TextAlignment = taRightJustify above the .shape block, but that doesn't work, either.

How can I fix this code -- or is there a better way, entirely, to add 3 lines of numbers to the chart and have the numbers right aligned to each other?

Re: Custom Text - Alignment

Posted: Thu Oct 10, 2013 2:37 pm
by 10050769
Hello Kaprice,

I have modified your code, because works for me and I have achieved align the Annotation tool to the Right and its text, too, repainting the Chart with method Environment.InternalRepaint. Please see next code and try to do something similar in your application.

Code: Select all

Private Sub Form_Load()
   TChart1.Aspect.View3D = False
   TChart1.AddSeries scFastLine
   TChart1.Series(0).FillSampleValues
   Dim intRectTop, intRectLeft As Integer
   Dim i As Integer
   For i = 0 To 2
        With TChart1
            .Tools.Add tcAnnotate
            .Environment.InternalRepaint
            With .Tools.Items(i)
                 .Active = True
                 With .asAnnotation
                   .Left = .Left + intRectLeft
                   .TextAlignment = ARight
                    intRectLeft = .Left + 10
                    
                    With .Shape
                        .Transparent = True
                        .ShapeStyle = fosSquareRectangle
                        .Font.Color = vbBlue
                   End With
                 End With
            End With
            .Tools.Items(i).asAnnotation.Text = Str(i)
      End With
   Next i
End Sub
I hope will helps.

Thanks,