467,117 Members | 1,048 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,117 developers. It's quick & easy.

new property for control type Form

MP
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
Nov 15 '05 #1
  • viewed: 3871
Share:
6 Replies
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" <m.******@codetel.net.do> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
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

Nov 15 '05 #2
MP
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" <jw****@spaam.optonline.net> wrote in message
news:Dn*********************@news4.srv.hcvlny.cv.n et...
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" <m.******@codetel.net.do> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
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


Nov 15 '05 #3
MP,
The default implementation for the drop down created is to list all
'components' on the current designer that matches the type given. Hence on
your current form, you only have one form type. If you drag & drop other
forms to this form, they will show up in the drop down. As they are now
instance variables on the current form.

Alternatively you can create a custom TypeConverter for this property, that
will list all the forms in this project. Do you expect the property to
create an instance of the form?

This TypeConverter can override the GetStandardValuesSupported,
GetStandardValuesExclusive, & GetStandardValues methods to provide a list of
forms to show in the drop down. You will also need to override the
CanConvertTo, ConvertTo, CanConvertFrom, and ConvertFrom methods.

The trick is going to be do you want an instance of another form to be
passed?
Or do you want the property to create an instance of another form, in which
case I would think you want the property to be a type or type name (string)
and use Activator.CreateInstance.

See System.ComponentModel.TypeConverter class and its GetStandardValues
method.

Hope this helps
Jay

"MP" <m.******@codetel.net.do> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
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

Nov 15 '05 #4

Hi MP,

If you want to retrieve the form information of your application, you can
use reflection to do this.
I wrote a sample to get all the forms in the assembly.

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Reflection ;
using System.Diagnostics ;
using System.Text ;

namespace reflectionform
{
public class Form1 : System.Windows.Forms.Form
{
private System.ComponentModel.Container components = null;

public Form1()
{
InitializeComponent();
}

protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Windows Form Designer generated code

private void InitializeComponent()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);

}
#endregion

[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void Form1_Load(object sender, System.EventArgs e)
{
Process p=Process.GetCurrentProcess();
string assemblyname=p.ProcessName+".exe";
Assembly a=Assembly.LoadFrom (assemblyname);
Module[] modules=a.GetModules();
Type formtype=typeof(System.Windows.Forms.Form);
StringBuilder sb=new StringBuilder();
foreach(Module m in modules)
{
Type []types=m.GetTypes();
foreach(Type t in types)
{
if(t.IsSubclassOf (formtype))
{
sb.AppendFormat("{0}\n",t.Name );
}
}
}
MessageBox.Show(sb.ToString());
}
}
}

Hope this help.

Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: "MP" <m.******@codetel.net.do>
| References: <eB**************@TK2MSFTNGP12.phx.gbl>
<Dn*********************@news4.srv.hcvlny.cv.net >
| Subject: Re: new property for control type Form
| Date: Sun, 10 Aug 2003 16:21:44 -0400
| Lines: 58
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <OV*************@TK2MSFTNGP12.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.framework.windowsforms,mic rosoft.public.dotnet.frame
work.windowsforms.controls,microsoft.public.dotnet .framework.windowsforms.de
signtime,microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 173stb18.codetel.net.do 64.32.88.173
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.windowsforms.con trols:10079
microsoft.public.dotnet.framework.windowsforms.des igntime:2816
microsoft.public.dotnet.languages.csharp:175486
microsoft.public.dotnet.framework.windowsforms:499 80
| X-Tomcat-NG: 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" <jw****@spaam.optonline.net> wrote in message
| news:Dn*********************@news4.srv.hcvlny.cv.n et...
| > 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" <m.******@codetel.net.do> wrote in message
| > news:eB**************@TK2MSFTNGP12.phx.gbl...
| > > 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
| > >
| > >
| >
| >
|
|
|

Nov 15 '05 #5
MP
> Or do you want the property to create an instance of another form, in
which
case I would think you want the property to be a type or type name (string) and use Activator.CreateInstance.
Yes this is my case, I use this code, is working, is correct, or there is a
better way?

Type myType = Type.GetType(newRecFormName);
ParentF0 f = (ParentF0) Activator.CreateInstance(myType);
f....
If you drag & drop other
forms to this form, they will show up in the drop down. As they are now
instance variables on the current form.
I tried to drag and drop another form over my first form but the designer
doesn't allow me to do that. (The icon change to the NOT symbol) How I do
that?

Thanks, very useful...
MP

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl... MP,
The default implementation for the drop down created is to list all
'components' on the current designer that matches the type given. Hence on
your current form, you only have one form type. If you drag & drop other
forms to this form, they will show up in the drop down. As they are now
instance variables on the current form.

Alternatively you can create a custom TypeConverter for this property, that will list all the forms in this project. Do you expect the property to
create an instance of the form?

This TypeConverter can override the GetStandardValuesSupported,
GetStandardValuesExclusive, & GetStandardValues methods to provide a list of forms to show in the drop down. You will also need to override the
CanConvertTo, ConvertTo, CanConvertFrom, and ConvertFrom methods.

The trick is going to be do you want an instance of another form to be
passed?
Or do you want the property to create an instance of another form, in which case I would think you want the property to be a type or type name (string) and use Activator.CreateInstance.

See System.ComponentModel.TypeConverter class and its GetStandardValues
method.

Hope this helps
Jay

"MP" <m.******@codetel.net.do> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
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


Nov 15 '05 #6
MP,
As Ying-Shen Yu, demonstrated there are about 5 ways to create objects from
a string at run-time.

To drag & drop a form onto another form the form you are dragging would need
to be on the toolbox. Unfortunately I do not see you can actually put a form
on the toolbox.

I should have stated "If you COULD drag & drop other forms to this form,
they will show up in the drop down."

Hope this helps
Jay
"MP" <m.******@codetel.net.do> wrote in message
news:Oc**************@TK2MSFTNGP09.phx.gbl...
Or do you want the property to create an instance of another form, in which
case I would think you want the property to be a type or type name

(string)
and use Activator.CreateInstance.


Yes this is my case, I use this code, is working, is correct, or there is

a better way?

Type myType = Type.GetType(newRecFormName);
ParentF0 f = (ParentF0) Activator.CreateInstance(myType);
f....
If you drag & drop other
forms to this form, they will show up in the drop down. As they are now
instance variables on the current form.
I tried to drag and drop another form over my first form but the designer
doesn't allow me to do that. (The icon change to the NOT symbol) How I do
that?

Thanks, very useful...
MP

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in

message news:%2****************@TK2MSFTNGP10.phx.gbl...
MP,
The default implementation for the drop down created is to list all
'components' on the current designer that matches the type given. Hence on your current form, you only have one form type. If you drag & drop other
forms to this form, they will show up in the drop down. As they are now
instance variables on the current form.

Alternatively you can create a custom TypeConverter for this property, that
will list all the forms in this project. Do you expect the property to
create an instance of the form?

This TypeConverter can override the GetStandardValuesSupported,
GetStandardValuesExclusive, & GetStandardValues methods to provide a list of
forms to show in the drop down. You will also need to override the
CanConvertTo, ConvertTo, CanConvertFrom, and ConvertFrom methods.

The trick is going to be do you want an instance of another form to be
passed?
Or do you want the property to create an instance of another form, in

which
case I would think you want the property to be a type or type name

(string)
and use Activator.CreateInstance.

See System.ComponentModel.TypeConverter class and its GetStandardValues
method.

Hope this helps
Jay

"MP" <m.******@codetel.net.do> wrote in message
news:eB**************@TK2MSFTNGP12.phx.gbl...
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



Nov 15 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Bryce Fischer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.