473,405 Members | 2,421 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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
6 4107
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Kent Eilers | last post by:
I want to follow naming conventions for my controls - i usually prefix combo boxes with "cbo". When a form is in datasheet view however i do not want the user to see the 'cbo' prefix in front of...
0
by: Brian Young | last post by:
Hi all. I'm using the Property Grid control in a control to manage a windows service we have developed here. The windows service runs a set of other jobs that need to be managed. The control...
0
by: Bryce Fischer | last post by:
I've got a simple (I think) asp.net application. I've created a DataSet in App_Code/ItemDataSet.xsd. Tested connection, seemed to work fine. In my ASPX file, I first dropped an...
2
by: Benton | last post by:
Hi there, I'm creating a custom server control, inheriting from TextBox. It has this AsDateTime property that returns the textbox contents converted to the nullable DateTime data type, as...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.