From: Family Tree Mike on 24 Apr 2010 16:09 On 4/24/2010 3:55 PM, Mr. X. wrote: > There is a derived "form" control of mine. > Any of the derived form has additional functionality (some methods ... > working with DB, etc ...) > > There may be many forms of the derived form. > Each time I need to do : newForm.ShowDialog. > Only need to pass the type, and no need to create the form on the > calling program > (Each form has it's own elements, buttons, etc. and look different from > other forms). > > Thanks :) > This may be what you are looking for: Sub Bla(ByRef t As Type) Dim f As System.Windows.Forms.Form = Activator.CreateInstance(t) f.ShowDialog() End Sub Sub Main() Bla(GetType(Form1)) End Sub Main is calling Bla() with a type that is derived from Form, Called Form1. Bla() creates an instance of a Form1 object and shows it. Bla() does not need to know that it is a Form1, only that it can be shown as it is derived from Form. Is this what you wanted to do? -- Mike
From: Armin Zingler on 24 Apr 2010 18:18 Am 24.04.2010 22:09, schrieb Family Tree Mike: > On 4/24/2010 3:55 PM, Mr. X. wrote: >> There is a derived "form" control of mine. >> Any of the derived form has additional functionality (some methods ... >> working with DB, etc ...) >> >> There may be many forms of the derived form. >> Each time I need to do : newForm.ShowDialog. >> Only need to pass the type, and no need to create the form on the >> calling program >> (Each form has it's own elements, buttons, etc. and look different from >> other forms). >> >> Thanks :) >> > > This may be what you are looking for: Option Strict On? :) > Sub Bla(ByRef t As Type) > Dim f As System.Windows.Forms.Form = Activator.CreateInstance(t) > f.ShowDialog() > End Sub > Sub Main() > Bla(GetType(Form1)) > End Sub > > Main is calling Bla() with a type that is derived from Form, Called > Form1. Bla() creates an instance of a Form1 object and shows it. > > Bla() does not need to know that it is a Form1, only that it can be > shown as it is derived from Form. > > Is this what you wanted to do? I'm curious too. If it is, I wonder what would by the purpose of Sub Bla because it could be put in Sub Main: dim f as form f = new form1 f.showdialog Even if it can be different Form classes it wouldn't make sense (til now): dim f as form select case whatever case ThisOne f=new form1 case ThatOne f=new form2 end select f = new form1 f.showdialog With Sub Bla it's also a Select Case but instead it's GetType(Form1), GetType(Form2), etc. So we will have to wait for Mr.X' answer. :-) -- Armin
From: Family Tree Mike on 24 Apr 2010 19:34 On 4/24/2010 6:18 PM, Armin Zingler wrote: > Am 24.04.2010 22:09, schrieb Family Tree Mike: >> On 4/24/2010 3:55 PM, Mr. X. wrote: >>> There is a derived "form" control of mine. >>> Any of the derived form has additional functionality (some methods ... >>> working with DB, etc ...) >>> >>> There may be many forms of the derived form. >>> Each time I need to do : newForm.ShowDialog. >>> Only need to pass the type, and no need to create the form on the >>> calling program >>> (Each form has it's own elements, buttons, etc. and look different from >>> other forms). >>> >>> Thanks :) >>> >> >> This may be what you are looking for: > > Option Strict On? :) Unfortunately, I'm not sure _yet_ if Mr. X can do what he wants with Option Strict On... -- Mike
From: Cor Ligthert[MVP] on 25 Apr 2010 05:16 Mr. X, A kind of variable type programming is tried endless times by persons who want to use Managed code as a kind of VBA. Managed code is designed to remove all that unpredictable in those at run time interpreting code, to be stable. VB6 had it in the variant, and it is now back in a way in C# in the Dynamic keyword (in fact a kind of Variant) to be more available for scripting coders (or more concrete PHP coders). So if you want to do things like this, then a language like PHP, VBA or JavaScript is probably a much better choice for you. In VB for Net we have this option already for years with the name of Option Strict Of by passing a string, which than can act like a variant. However, I'm not the one which will advice this Option which makes programs less stable. (If the string is not well format there is direct a break at user time) I assume Armin does too. :-) Cor "Mr. X." <nospam(a)nospam_please.com> wrote in message news:#fHFqU54KHA.3184(a)TK2MSFTNGP05.phx.gbl... > Hello > I have a function, that I want to pass it via parameter a classType > (object type, or whatever it is called). > I.e I want to send a type : Button, Form, radioButton, etc. > > Thanks :) >
From: Mr. X. on 25 Apr 2010 17:15 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? 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 :)
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: simmulate real rowEnter on DataGridView object. Next: Add inner control event. |