How to make a form of main application reuseable by others?

G

Guest

Hi, I'm using vs2005, .net 2.0, Win2k server for a Windows applcaiton. I
have a main application where there is a a form and the codes that I would
like to make it reuseable by other applications.
1. I already have a classlibray project but I don't think I can include a
"form" in it, right?
2. So, do I make this form into a dll so other application can include it
as a reference?
3. To do the item 2, does that mean that I would create a new project and
add the form and the code in it. But how to specify to generate a dll
instead of a project that produce .exe file after it's compiled?
Thank you.
 
N

Nicholas Paldino [.NET/C# MVP]

Pucca,

You can definitely include a form in a class library. A form is nothing
more than a class. All you have to do is make sure the form is public. You
might want to consider whether or not there are menus on the form, if it is
used as a child form, then it will not take to nicely, depending on how
menus on the parent form are used.

All you have to do is create a "Class Library" project and then you can
add your form code to it, and then reference it from other applications.

Hope this helps.
 
F

Freiddie

Yes a form is simply a class that has derived from the "Form" class.
This form can be duplicated as many times as you want by creating
multiple instances of the class. Once your form is declared "public"
then your other applications can link to the DLL as a reference and
use it in:

MyForm myForm = new MyForm();
MyForm.ShowDialog();

or

Application.Run(new MyForm());

both of which work well. But the latter is used for initiating the
MAIN form only while the former may be used to show an independent
form.

Remember that to change from "exe" to "dll" simply change the
application type from Windows Application to Class Library in the
project properties part.

Freiddie
http://fei.yuanbw.googlepages.com/
http://freiddy.blogspot.com/
http://crazibe.blogspot.com/
 
G

Guest

Thank you both for the help. I will now try to do that.
--
Thanks.


Nicholas Paldino said:
Pucca,

You can definitely include a form in a class library. A form is nothing
more than a class. All you have to do is make sure the form is public. You
might want to consider whether or not there are menus on the form, if it is
used as a child form, then it will not take to nicely, depending on how
menus on the parent form are used.

All you have to do is create a "Class Library" project and then you can
add your form code to it, and then reference it from other applications.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)


Pucca said:
Hi, I'm using vs2005, .net 2.0, Win2k server for a Windows applcaiton. I
have a main application where there is a a form and the codes that I would
like to make it reuseable by other applications.
1. I already have a classlibray project but I don't think I can include
a
"form" in it, right?
2. So, do I make this form into a dll so other application can include it
as a reference?
3. To do the item 2, does that mean that I would create a new project and
add the form and the code in it. But how to specify to generate a dll
instead of a project that produce .exe file after it's compiled?
Thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top