Android Question Clearing a canvas


Well-Known Member
Licensed User
Longtime User
I am working on a small and simple Draw app. Project is attached as well as main code below.

I can't press the Clear button and have it clear my drawing. Obviously I'm missing something here.

Thank you for any help.

#Region  Project Attributes 
    #ApplicationLabel: ATCNotes
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: portrait
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim pnlDrawing As Panel
    Dim cvsDrawing As Canvas
    Dim rect1 As Rect
    Dim x1, x2, y1, y2, Radius, LineWidth As Float
    Dim LineColor As Int
    Dim areaRect As Rect
    Private pScreenHeight = 0 As Int
    Private pScreenWidth = 0 As Int

    Private ButtonClear As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.AddView(pnlDrawing, 0, 0, 100%x, 100%y)
    rect1.Initialize(0, 0, pnlDrawing.Width, pnlDrawing.Height)
    areaRect.Initialize(0, 0, pnlDrawing.Width, pnlDrawing.Height)
    cvsDrawing.drawRect(areaRect, Colors.Transparent, True, 0)

    LineWidth = 10
    Radius = Floor(LineWidth / 2)
    LineColor = Colors.Red

    pScreenHeight = GetDeviceLayoutValues.Height
    pScreenWidth = GetDeviceLayoutValues.Width
    ButtonClear.Top = 0.87 * pScreenHeight
    ButtonClear.Left = 0.66 * pScreenWidth
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub pnlDrawing_Touch(Action As Int, X As Float, Y As Float)
    Select Action
        Case Activity.ACTION_DOWN
            x1 = X
            y1 = Y
            cvsDrawing.DrawCircle(x1, y1, Radius, LineColor, True, 1)
            rect1.Left = x1 - Radius
            rect1.Top = y1 - Radius
            rect1.Right = rect1.Left + LineWidth
            rect1.Bottom = rect1.Top + LineWidth
        Case Activity.ACTION_MOVE
            x2 = X
            y2 = Y
            cvsDrawing.DrawCircle(x1, y1, Radius, LineColor, True, 1)
            cvsDrawing.DrawLine(x1, y1, x2, y2, LineColor, LineWidth)
            rect1.Left = Min(x1, x2) - Radius
            rect1.Top = Min(y1, y2) - Radius
            rect1.Right = Max(x1, x2) + LineWidth
            rect1.Bottom = Max(y1, y2) + LineWidth
            x1 = x2
            y1 = y2
    End Select
End Sub

Sub ButtonClear_Click
End Sub


    9.9 KB · Views: 146