Assume that I have a project that contains two buttons on it. Each buttons generate a custom form. I wrote both forms manually. But I wonder, is there a way that I can make these forms by using toolbox in different projects and combine them in one solution. I mean, when I press a button I want to call another project.
And finally if such a solution exists, is it proper way to make programs like this , or is it better to create forms manually ?
You can call a form from another project (if we are talking about VS project) if it is public. You need to add reference to the project where this form is "placed" to the project where the call is made.
Of course, you can create forms manually, but you can as well create new windows form and add controls to it via designer.
And about the proper way. If you need the same form to be called from different projects, then, yes, keeping in in some third project is alright.
Yes you can invoke the forms even if they are in different projects. But you need to have references to that projects and to have defined a proper using statements.
Related
I have a program were creating at school in c# and I need to create multiple pages which display information on certain things but I'm not quite sure how to do this without creating over 50 new forms in my program. I know parameters have to be used but I'm not quite sure how to go about doing it.
Try to use TabControl
You can add pages and name them how you want.
Controls, you are adding to a tab, are still active, even if you move to another tab.
I have 2 projects in one solution.
The main is a VB.net project and the secondary is a C# project. I want to call a form from the C# project from the VB.net project at the click of a button but I am unsure how.
I have read it is possible if I create the C# .dll and reference it but I cannot find a guide for this. Would anybody give me a step by step on how one would accomplish this please?
It's a fairly simple and easy thing to do, and also common. Saves duplicating code across projects if you have multiple projects which all have a function which does the same thing.
Right Click the VB project and click Add -> Reference...
Press the Projects node on the left.
Now hover over the C# project and click the checkbox that appears.
You've now added the reference. Beware that you cannot then reference the Vb project from the C# as Visual Studio will not allow this because you're creating a circular reference.
To call a form to show up, you can do the following.
First, you'll need to make a reference somewhere of the new form. For example; (OtherProject being the name of the other project, and FormName being the name of the form in the project. Depending on what you're doing, you might want to do this when you start your VB app, or you might only need it once. It entirely depends on your setup.
Dim OtherProjectForm as New OtherProject.FormName
When you've done that, just go ahead and do
OtherProjectForm.Show()
or of course, again, depending what you're doing,
OtherProjectForm.ShowDialog()
You'll also be able to access and public members of the form. By default, every control on the form's access mode is "Friend", which means just objects which are part of the same assembly can access them, but if you need to, you can make them public. Or you can just make methods to interact with them.
In my project I have implemented this plugin manager:
https://code.msdn.microsoft.com/windowsdesktop/Creating-a-simple-plugin-b6174b62
In this way I can add .DLL file and make my project more modular.
I wanna know if in one of these .DLL plugin I can add a .xaml with user interface, and use it inside my main project to visualize the content of that xaml in my main GUI.
In this way I can make my app more modular not only by code library but also with user interface.
Thanks
If you create a project that contains WPF UserControl items, then as long as you expose those items through the DLL interface then you can utilise them in another project.
You should be able to verify this very easily by doing something like the following:
1) Within your 'DLL' project make a public class SquareControl, which is simply a UserControl under the hood, and specifically a canvas containing a red square of a fixed size.
2) Within your utilising project, reference the DLL.
3) Within your utilising project, in C# code somewhere create an instance of SquareControl, and check in the debugger that its properties are as you expect.
4) Then create a UserControl within your utilising project, and open VS Designer for that control. Within the empty Grid that has been created for you drop an instance of SquareControl, and you should be able to see this within Designer. Getting your xaml namespace definitions can be awkward the first time around but there's plenty of help available for that. Then fire up the application and see it there.
In my soloution I have created some projects and one of them is the main project so it gets fired up when application starts.
I want to use only this main project's Properties file to store all Properties (string, objects and etc..) so for this case I have to reference this main form project in other form projects (Hope I am making sense!)
Now the problem is when I want to call one of those forms inside my main form projects, because I can not reference to them (I get this circular dependency warning), I am unable to do so! What can be the workearound in this case?
You can only link in one direction. You must think of a project as a upside down tree. You can reference a parent class, but the parent class can't reference the children class. So if you need a feature that is needed in both, move it to the parent of the two classes, or move it to a 3rd class, and both reference it.
you pass main form instance as constructor argument when you call one of those forms in the main. In that way you access properties of main project. main form has to be precedent to others. the other way wouldnt work unless you put all properties as independent class or construct
I have a forms application and I do want a separate project for my one custom control that I need to use in 2 different places in my app.
I have have created a user control in the same project but I do not know how to use it in the program. It does not show up in the toolbox even if I drag it, it shows the drop cursor but then nothing happens. Will I have to use it manually ? or is there a better way.
Please help.
THanks,
In Tools -> Options, under the section for "Windows Forms Designer", ensure that AutoToolboxPopulate is True - then the toolbox should automatically populate with all user controls from all projects in the current solution.