Remove text after drawing 2D text on canvas

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Sharkann
Newbie
Newbie
Posts: 17
Joined: Fri Apr 22, 2022 12:00 am

Remove text after drawing 2D text on canvas

Post by Sharkann » Thu Aug 11, 2022 2:16 pm

Hi,

I wanted to add some custom text on a curve, depending on the points values.
I made a rocedure called in the afterdraw event of the chart, as follows :

Code: Select all

Public Sub label_water_valves(s As Steema.TeeChart.Styles.Series, e As Steema.TeeChart.Drawing.Graphics3DGdiPlus)
        Dim X, Y, old As Double
        Dim te = ""
        Dim res As Integer
        old = -1
        For i As Integer = 0 To s.XValues.Count - 1
            If s.YValues(i) > 0 And s.YValues(i) <> old Then
                X = Main.TChart1.Axes.Bottom.CalcXPosValue(s.XValues(i))
                Y = Main.TChart1.Axes.Left.CalcYPosValue(s.YValues(i))
                res = HexStringToBinary(s.YValues(i))
                If res And 4 Then te = te & "LP"
                If res And 16 Then te = te & vbCrLf & "HP"
                If res And 64 Then te = te & vbCrLf & "RSV"
                e.TextOut(X, Y, te)
                te = ""
                old = s.YValues(i)
            End If
        Next
    End Sub
    
s is the Serie I want to track.

Problem : once the text is drawn (works well), is there any way to hide it or remove it ?
In some part of my project, the user can hide/show curves. If I hide the series "s", the text remains on the graph...

The part 13 of the tutorial explains how to draw things on the graph, but not how to erase them.

Any idea ?

Thanks

Marc
Site Admin
Site Admin
Posts: 1272
Joined: Thu Oct 16, 2003 4:00 am
Location: Girona
Contact:

Re: Remove text after drawing 2D text on canvas

Post by Marc » Fri Aug 12, 2022 7:57 am

Hello,

Everything in OnAfterDraw is called every time the Chart is rendered. If you put boolean conditions in there, like:

Code: Select all

if myCondition
  runCustomDrawCode
end if
then you can control i t being called by setting the condition to true or false ... Calling Chart.Repaint causes the chart to render and according to whether you have set the condition true/false the custom code will run or not; that way, effectively, removing any custom content if not required.

Regards,
Marc Meumann
Steema Support

Sharkann
Newbie
Newbie
Posts: 17
Joined: Fri Apr 22, 2022 12:00 am

Re: Remove text after drawing 2D text on canvas

Post by Sharkann » Tue Aug 30, 2022 7:16 am

Hi !
Working fine ! Thanks for the answer.

Sharkann

Post Reply