Custom drawing on the Chart Panel

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Chris.CHWU
Newbie
Newbie
Posts: 57
Joined: Wed Jan 30, 2008 12:00 am

Custom drawing on the Chart Panel

Post by Chris.CHWU » Tue Feb 03, 2009 7:38 am

Dear Sirs,

How to remove "My Text" when I click "Clear Button"?

Code: Select all

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler TChart1.AfterDraw, AddressOf After_Draw

    End Sub

    Private Sub After_Draw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        Dim Text As String = "My Text"
        Dim S As New Size(50, 50)
        Dim P As New Point(g.ChartXCenter - (S.Width / 2), g.ChartYCenter - (S.Height / 2))
        Dim R As New Rectangle(P, S)
        g.Pen.Color = Color.Blue
        g.Rectangle(R)
        g.TextOut(Convert.ToInt32(g.ChartXCenter - (g.TextWidth(Text) / 2)), Convert.ToInt32(g.ChartYCenter - (g.TextHeight(Text) / 2)), Text)
    End Sub


    Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
        'Remove "My Text"
    End Sub

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Tue Feb 03, 2009 9:55 am

Hi Chris,

The easiest way I can think is to declare your "Text" variable as global and to change the string when the button is pressed:

Code: Select all

    Dim Text As String = "My Text"

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler TChart1.AfterDraw, AddressOf After_Draw

    End Sub

    Private Sub After_Draw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        Dim S As New Size(50, 50)
        Dim P As New Point(g.ChartXCenter - (S.Width / 2), g.ChartYCenter - (S.Height / 2))
        Dim R As New Rectangle(P, S)
        g.Pen.Color = Color.Blue
        g.Rectangle(R)
        g.TextOut(Convert.ToInt32(g.ChartXCenter - (g.TextWidth(Text) / 2)), Convert.ToInt32(g.ChartYCenter - (g.TextHeight(Text) / 2)), Text)
    End Sub

    Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
        Text = ""
        TChart1.Refresh()
    End Sub
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Post by Yeray » Tue Feb 03, 2009 10:10 am

Hi again Chris,

Another possibility to have more control would be using a global boolean and change it, instead of your string, when the button is pressed:

Code: Select all

    Dim drawText As Boolean

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        AddHandler TChart1.AfterDraw, AddressOf After_Draw

        drawText = True
    End Sub

    Private Sub After_Draw(ByVal sender As Object, ByVal g As Steema.TeeChart.Drawing.Graphics3D)
        If drawText Then
            Dim Text As String = "My Text"
            Dim S As New Size(50, 50)
            Dim P As New Point(g.ChartXCenter - (S.Width / 2), g.ChartYCenter - (S.Height / 2))
            Dim R As New Rectangle(P, S)
            g.Pen.Color = Color.Blue
            g.Rectangle(R)
            g.TextOut(Convert.ToInt32(g.ChartXCenter - (g.TextWidth(Text) / 2)), Convert.ToInt32(g.ChartYCenter - (g.TextHeight(Text) / 2)), Text)
        End If
    End Sub


    Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
        drawText = False
        TChart1.Refresh()
    End Sub
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply