Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi frens,

i have two different forms inside two different class library

i want to open a form which has camera feature is form1 is loading

how to perform such task please help with the code

with regards bishnu
Posted
Comments
BillWoodruff 5-Nov-11 9:50am    
An interesting question ! I find that the title of your question suggests a "nesting" of Class/Libraries with Forms, but the text of your question sounds like the two Class Libraries are not "nested," but just referenced in some project (WinForms ?) that uses them.

You might want to say a bit more about the exact relationship of the two class libraries and the Form definitions they contain : are they "nested" ... or ?

1 solution

First build your Class Library and then add a reference[^] to it in the Project you want to use it in.
You can now use the Form in your Class Library as you could use any Class in .NET
C#
// Make sure you use the namespace of your Class Library.
MyClassLibrary.CameraForm camForm = new MyClassLibrary.CameraForm();
camForm.Show();
 
Share this answer
 
v3
Comments
BillWoodruff 5-Nov-11 9:46am    
Answer +=5. I realized, reading your answer, that I had never put a Form inside a Class Library project, and I wonder, if you care to comment, what the strategic value of locating a Form (or UserControl ?) inside a Class Library project would be. thanks, Bill
Sander Rossel 5-Nov-11 9:57am    
One word: Reusability :)
Imagine you are working on a big WinForm application. At some point you decide that you need an Input box, or perhaps a custom MessageBox. If you put them in your main Project you would have to reference your big WinForms application in every other Project where you also want to use your custom Input box or MessageBox. Alternatively you could copy/paste your Dialogs in every other Project you have. However, if you adjust one (better graphics maybe?) you'd have to check all your Project to make the same adjustment. When you put your cusom Dialogs in a different Class Library you can simply reference them and put them in every Project you want. Each change in your custom dialog windows is now automatically applied to all Projects using it.
You could also do this for Form Inheritance or even for re-use of complete Forms with specific functionality.
Don't forget a Form is simply a Class too (with a GUI). It can be used like any other Class.
The same goes for UserControls.
Hope that clears up your question :)
BillWoodruff 5-Nov-11 10:49am    
I'm in the habit of making my re-usable-across-projects Window-based objects from UserControls ... since they often don't need the full 'panoply' of Form functionality; you can even create a new WindowsFormsControlLibrary type project (which builds-out a UserControl template for you), and modify that to turn it into a Form, if you wish (although I'm not sure that's a best practice).

Thanks for taking your time to fully express your thoughts ! Wish I could vote-up your response :)
Sander Rossel 5-Nov-11 10:56am    
No problem. I have never heard of a WindowsFormsControlLibrary... I cannot find it in my New Project window either. UserControls are often a good idea instead of an entire Form. Just know it doesn't have to be that way ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900