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
Related
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.
The plans on the project I am working on have changed now they ask for a main menu. Normally that is not a problem I just go to startup list. My startup object list does not contain any of the forms. Here is a screen shot. All the sites I have referenced stated that you can change it in a program.cs file, I don't have a file named. Any suggestions?
The Startup Object isn't a Form - it's which Main routine you want to use as your program's entry point.
You have one listed - LabelManagement_2010_Program has a compatible Main routine. That method is the one you would need to edit in order to change the form that's opened on startup.
I found this post and I would like to do the second option in the first answer
2) If the app is only useful within the context of the parent apps,
say by being given objects or other arguments from the other apps,
consider refactoring the small app to allow the form's project to be
referenced by the parent apps. Then, your parent apps can simply
create a new instance of the form and display it:
var childForm = new SmallAppForm();
childForm.Owner = this; //the child window will close when its owner does.
childForm.Show();
I have some questions about what steps I would have to do in order to accomplish it.
The app that I trying to call can be found here.
To change it so that I have a main (parent) form that creates and calls this application like a class, would I add a new project that would be the "parent", add the Main to my new parent form so that it is the application. Then have a menu choice to start the wizard in the parent form in order to create and call my wizard like this?
CreateUserContext context = new CreateUserContext();
CreateUserWizard wizard = new CreateUserWizard(context);
Thanks for any guidance,
Leslie
Add a class library and put the classes of your SmallFormApp in it. This class library will be under the same solution. Then go ahead and reference this in your ParentForm and use the functions in it.
What I would do is to tranform the small aplication into a Class Library instead of a Winforms application. (It can also be a project within the solution, referenced by the main project)
Then, the parent application just references the small application and calls the new SmallAppForm()
Of course the SmallAppForm must be public.
Class Library is the project type. When you create a project, it can be console application, windows form application, class library and many others. So you should create a new project as class library type.
Copy all your forms of the small applications to this project, make the classes public.
(There's no program class in a class library, just the forms and other classes you created)
I just finished adding and removing different database models (I was trying to figure out which one I should be using for this project) then after playing around for a while I noticed one of my classes's icon changed from what is shows beside my Calculations.cs class in the first image to the Balance.cs icon.
The Balance.cs now has this Designer component so when I double click on it I see my second screen shot. This seems to be allowing me to add components from the toolbox to my class. There are actually two classes within my Balance.cs. This Designer thing is only affecting/interacting with one of them (it inherits from SerialPort).
I don't really know what changed or what I did to make this happen and ctrl+z is not being my friend here. How do I change Balance.cs back to a regular class with no designer component?
Thanks
If any of the classes in a source file inherit - either directly or indirectly - from System.ComponentModel.Component (such as SerialPort), Visual Studio will provide design-time support to you. This is sometimes unwanted behaviour, and you can safely ignore it in most cases.
If it really bothers you, you can decorate your class with the [DesignerCategory] attribute (set the category to an empty string).
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.