Thank you Cor, I get the idea, and that was exactly what I needed.
You said that the code doesn´t replace too much, but yes, because I just
needed an exaple, there maney labels anda other objects in that function.
//In a module
Public Class mkc_designcre
Public Function mkf_addlabel(ByVal Text As String, ByVal X As Integer,
ByVal Y As Integer) As Label
Dim nlabel As New Label
nlabel.Text = Text
nlabel.Location = New System.Drawing.Point(X, Y)
Return nlabel
End Function
End Class
I tried this, and I´t doesn´t return any errors, but nothing is visible.
//In the form
Dim mkd_labelb As New mkc_designcre
Me.Controls.Add(mkd_labelb.mkf_addlabel("Text on the label", 25, 23))
Thank you again, it was of big help, I´m working to find the final solution
to get it visible
Marcos
"Cor Ligthert" <no************@planet.nl> escribió en el mensaje
news:OW**************@tk2msftngp13.phx.gbl...
Marcos,
You can, the only problem that you have to keep an eye on is that when an
object goes out of scope (is not needed any more) that object will be
cleanded up by the Garbage Collector (not direct however when your program
reaches idle time).
All in that object created subobjects (which have no reference anymore)
will be removed as well.
When you do what you ask, than you can use two methods the shared or non
shared because what I wrote above I would in this case avoid "shared".
When you use such a class non shared you get something in a simple way
as(you can as well create your own labelclass by inheriting)
\\\
Dim myLabelBuilder as new LabelBuilder
me.controls.Add(myLabelBuilder.AddLabel(("Text on the label", 23, 450))
///
Where the class can than be
\\\
Public Class LabelBuilder
Public function AddLabel(byval Text as String, byval X as Integer,
Byval Y as integer) as Label.
dim mylabel as new label
mylabel.Text = Text
myLabel..Location = New System.Drawing.Point(X, Y)
return mylabel
End class
////
However what you replace is
\\\
dim mylabel as new label
mylabel.Text = "Text on the label",
myLabel..Location = New System.Drawing.Point(23, 450)
me.controls.add(mylabel)
///
Not that much in my opinion
(all typed in this message so wach typos)
I hope however that this clears somethings
Cor