array of objects (canvas) on the fly

I’d like to make 5 to 10 (or more) new instances of canvas1 “on the fly”
I have a canvas1 on the form.

My first line is:
dim MyNewerCanvas(10) As new canvas1

… a little confused here as sometimes I read that “new” is required and sometimes that “new” isn’t required.

The code goes on …

dim x as integer
dim x2 as integer
Dim f As FolderItem

for x = 0 to 10
MyNewerCanvas(x).top = 100 + x2
MyNewerCanvas(x).Left = 199 + x2
x2 = x2 + 100

f = GetFolderItem(“C:\Users\Philip\Desktop\Angela School\Level 0\pictures lesson 1/Im_sad.jpg”, FolderItem.PathTypeShell)
If f.Exists Then
mypic = picture.open(f)
mynewercanvas(x).invalidate
Else
MsgBox(“The FolderItem does not exist.”)
End If
next x

One error I’m getting is nilexceptionerror

another is

expected class windows1.canvas1 but got windows1.canvas1

confused on that too.

any help please?

For i As Integer = 0 To 5 Dim c As Canvas = New MyCanvas() ... Next

Use one canvas and draw multiple items on it.

Thanks Eli

But do I now call on C for each of the pictures I want to load on to it?
So c(0), c(1) etc.?

I thought I would have to call the “new canvas” as new canvas1() because that has the paint command in it.

Dim f As FolderItem
For i As Integer = 0 To 5
Dim c As Canvas = New Canvas1()
f = GetFolderItem(“C:\Users\Philip\Desktop\Angela School\Level 0\pictures lesson 1/Im_sad.jpg”, FolderItem.PathTypeShell)
If f.Exists Then
mypic = picture.open(f)

c(i).top = i * 100

Else
MsgBox(“The FolderItem does not exist.”)
End If

Next

Oh … so “canvas1(i).top = i * 100” works …

so what exactly is C

A variable pointing to a Canvas instance. It is automatically a part of the Control Set, which you created in the IDE for Canvas1.

OK - thanks much! :slight_smile:

Hello Philip,

I would suggest not to disregard Tim’s answer. It is not what you asked for, but it’s probably a pointer in the best direction.

Julen

To further add to it, if these canvas’ are going to overlap, at all, and you plan on running this on Windows you’ll be sorely disappointed at the flicker.