Well, thanks.
Your design pattern example of using Activator, is exactly what I need too.
I have tried this for some other simpler controls, such as button.
Some new problems :
--------------------
1. I want to make a class that is inherited from a form,
and use it, add it to project, etc. at the same way I add new windows'
form.
How can I do that?
Here is a decent writeup on the topic. Look about half way through the
artical and see a section called "Exporting our class to a new template".
2. Also, I need to exposed a property, but I should need a type.
When I do :
public property newForm() as Type
...
on the property I cannot choose a type,
but also I want that I can choose only types that are inherits the
MyNewForm.
How can I do that ?
Thanks
Interesting. I've not tried that before, but I see where the property
is grayed out in the properties list. Aside from that, your question
about limiting the types is going to be a problem for a property. I'm
not sure how you could do that.
It sounds more and more like you could potentially use "generics". The
following class shows how to create a form using generics where the
parameter type is constrained to classes derived from type MyNewForm,
and that can be called to create a new instance.
Public Class MySpecialForm(Of T As {MyNewForm, New})
Inherits System.Windows.Forms.Form
Public Property NewForm As T
End Class
So now when you create an instance of this, you would do the following:
Dim x as new MySpecialForm(of Class1)
This assumes Class1 inherits from MyNewForm. You now can only set the
property x.NewForm to an object of type Class1 (or something derived
from class1). Within MySpecialForm, you can create an instance of the
sent in type (class1 in the example), as follows:
Sub foo()
Dim x As New T
x.ShowDialog()
End Sub