Showing drawings on a canvas

wdegler

Active Member
Licensed User
Longtime User
I have something like the following in a loop (containing much activity):

Canvas1.DrawPath(Path1,Colors.Yellow,False,1).

None of the paths appear until the loop is finished. I have tried using DoEvents although this does not seem to involve an event. I don't know what I would apply "Invalidate" to in case that is what is needed.

How can I make the paths appear immediately after the DrawPath calls during each pass?
 

stevel05

Expert
Licensed User
Longtime User
You need to invalidate the object that you attached the canvas to.
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
I have tried it but ...

Thank you, Steve, for your response.

I attached Cnv (the canvas) to Activity and then passed Cnv to the code module where the drawing takes place. However, I am not able to invalidate Activity from there. I have tried attaching Cnv to a panel and even to a label and passing these along with Cnv to the code module. The only time I see ANY drawing is when I use Activity and then, only AFTER the loop is finished.
I could put all this code into the Activity module but it is large already.

Suggestions?
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
You should be able to pass the activity to the sub module in the same way. Then invalidate that in the module.

Steve
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
This suggestion helped ...

Thank you. Your suggestion helped:

I passed something like
Act as Activity
to my code module and then used Act.Invalidate there to force drawing. This works!

Now, all I need is to later remove all drawing. I have tried the following to no avail:

1) Redrawing in the background color (works for DrawPath but not DrawText).

2)
For I = 0 To Activity.NumberOfViews - 1
Dim V As View
V = Activity.GetView(I)
V.Visible = False
Next

3)
For I = 0 To Activity.NumberOfViews - 1
Activity.RemoveViewAt(I)
next

4)
I even tried calling Activity_Create(False) but that involves some
ugly additional steps.

Can you help with this?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
What do you want to do, remove the drawings or remove the views ?
Remove the drawings:
B4X:
Dim rect1 As Rect
rect1.Initialize(0, 0, 100%x, 100%y)
Canvas1.DrawRect(rect1, BackgroundColor, True , 1)
Remove all views:
B4X:
For I = Activity.NumberOfViews - 1 To 0 Step -1 
  Activity.RemoveViewAt(I)
Next
 
Last edited:
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
Your first method works! Thanks for your help

Your first suggestion, to blot out the drawings, works well so I am using it. I forgot that rectangles are easily filled.

I had already tried your second suggestion but that didn't work for DrawText and it would only work for DrawPath when I had a breakpoint set between drawing and erasing with the background color; neither delays nor timers helped.

Thanks for your help; I'm moving forward again!
 
Upvote 0
Top