Hi MP,
Glad to hear from you!
First I want to make clear that When do you want to create instance of
that form, run-time or design-time?
If the answer is run-time, maybe here is an solution, you may create it
in you control using the the
Appomain.CurrentDomain.CreateInstanceAndUnWrap. like this:
string AssemblyName = "TestBench";
string TypeName = AssemblyName + "." + "Form1";
Form form =
AppDomain.CurrentDomain.CreateInstanceAndUnwrap(AssemblyName,TypeName) as
Form;
if(form != null)
form.ShowDialog();
I've sent you a mail with a simple demo using that solution. But it's not
very convenient, in order to identify a the form type, you must provide
both the assembly name and the full type name.
Although the assembly name is often part of the contained name but
there are exceptions, such as mscorlib. In Addition, you may not able to
get assembly name from the full type name, for your control didn't know its
type( call Type.GetType("Form1") in control returns null because it didn't
reference the coressponding assembly, sounds like a circle problem?).
You may ask users inputing the assembly name and full type name manually.
If you want to create that form in design-time or validate the property
by try to create an instance, well, as far as I know there are no
documented way to do this. So I'm afraid the validation in design-time is
not an easy task, for now, the work around maybe throw exception in
run-time and keep the state of your control consistent in exception.
In run-time, you can use the property AppDomain.CurrentDomain to get
global meta data of the whole project. But the property doesn't take effect
in design-time, beacause your control runs in the AppDomain of vS.NET in
design-time. I'm doing some research on this issue and until now, I haven't
found a way to access the assembly information of the project in
design-time, please let me know if you have a good idea.
Be free to let me know if you have any questions on this issue, thanks!
Kind regards,
Ying-Shen Yu [MSFT]
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
From: "MP" <
[email protected]>
Subject: Re: new property for control type Form
Date: Mon, 11 Aug 2003 10:56:59 -0400
Newsgroups: microsoft.public.dotnet.framework.windowsforms
Hello again and thanks for your help,
I understand your answer at run time, but how can I put the value at design
time for:
MyFormProperty
I think I need some type of "form set" for group at design time the form
contained in my control and another one.
If that way is complicated, I can change my property for string, and create
an instance of the form corresponding to that string
String optionalForm = "FormOpt";
Now my new question is:
How to create a form instance for the string (I searching for this now)
This isn't the better way, but for now it may work for me.
If you have another ideas let me know please.
Thanks for your help
MP
Ying-Shen Yu said:
Hello MP,
Do you mean you that when you pull-down the property combo-box, you get
the form instance created in your project(e.g. form2, form3....),and then
you select one, or you enter the name of the form variable and then
validate it. Unfortunately, neither methods
will work in current .NET framework, because there is no documented
interfaces or methods to enumerate the added forms, the only instance of
form you can get is the container of your control. To work around this
limitation, you may set and check your property in run-time. If you want to
know if this property has a valid reference , you can check if it is equals
to null,like the following code:
if (UserControl.MyFormProperty != null)
{
.....
UserControl.MyFormProperty.Show();
.....
}
Please Let me know if you still have questions on this issue, Thanks!
Kind regards,
Ying-Shen Yu [MSFT]
Microsoft Support Engineer
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. 2001 Microsoft Corporation. All rights
reserved.
From: "MP" <
[email protected]>
Subject: Re: new property for control type Form
Date: Sun, 10 Aug 2003 16:21:44 -0400
Newsgroups:
microsoft.public.dotnet.framework.windowsforms,microsoft.public.dotnet.framework.windowsforms.controls,microsoft.public.dotnet.framework.windowsforms.de
signtime,microsoft.public.dotnet.languages.csharp
Is another form in the same project and some time from a reference project.
I don't wave any way for now, or any preferences.
The problem I have is that at some point I want to know if this property has
a value, and if it's not empty or null, show the corresponding form.
TIA
MP
John Wood said:
Where do you expect it to get the list of forms from? All the instances in
your application? How would it know about that at design time anyway?
MP said:
Hello
I want to have a public property (and Brows able) in one control, I
use
this
code:
[Browsable(true)]
public System.Windows.Forms.Form recordForm
get { return _recordForm;}
set {_recordForm = value;}
}
But when I tried to use it at the properties window I get a combobox and
only give me options for (none), and the same Form the control is contained.
I need to put the name of a different Form, is the a way for me to get this
done?
Is this the better approach?
TIA
MP