Create a control from a class

Ciao! I have a window with a canvas, first item of a set: mycanvas(0).
From an external class i want to create an other member of this canvas on my window.
If i do it from the window, all works fine but from my class i obtain an error. My code is:

[code]Dim c As New myform.mycanvas(0) ’ In the window i use only mycanvas

c.BackDrop = myimage
c.Height = 16
c.Width = 16
c.Left = 10
c.Top = 10
[/code]

How solve this problem?

Here’s a link to a good discussion about this. https://forum.xojo.com/34976-add-canvas-control-at-runtime/0

You should not point to one of the members.

This should work:

[code]Dim c As New mycanvas ’ In the window i use only mycanvas

c.BackDrop = myimage
c.Height = 16
c.Width = 16
c.Left = 10
c.Top = 10[/code]

Thanks, men! Michel, with your modification i obtain:

Can’t find a type with this name. Did you mean class myform.mycanvas?
Dim c As New mycanvas

Tanner, i tried to use the suggestions in the link but don’t works!!!

I want to create a canvas from an external class not from the same window.

From the piece of code you shared, it seemed you wanted to create a new myCanvas from a control set. I do not know any way to dynamically create a control that is not already instantiated.

You could place your myCanvas on a ContainerControl, and then, dynamically instantiate with embedwithin:
http://documentation.xojo.com/api/deprecated/containercontrol.html#containercontrol-embedwithin

Thank you, Michel, for your patience! Perhaps i lost some concept related to references.
I want to explain you only the essentials lines of my needs (my project is huge!).

I have a window with some textfields subclassed by a class (named textfieldCurrency) . In this class, i have an event, Open, where i want to create an istance of a canvas present in my window. The source canvas has a symbol of Euro as background and i want to create this effect:

From the same window of the source canvas it’s simple to do it:

[code]Dim c As New simboloValuta

c.height = 18
c.width = 18
c.left = prezzocli.left + 2
c.top = prezzocli.top + 2
[/code]

but from the textfieldCurrency class seems impossible!

prezzocli is my textfield and simboloValuta is my canvas with the Euro symbol.

You CANT create an instance of an object already created. You can add a property in textfieldCurrency of type canvas and pass the refference of the existing canvas on the open event.

But, a better way:

You’re right, Ivan, I said that badly! With my code (from the same window) i create only a member of the set of my canvas and that it’s simple! I’m not able to create a member from an external class!

Both your solutions are great! Thanks! I’ll try it now! Bye!!!