473,242 Members | 1,483 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,242 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 4098
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: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

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.