I want to get a list of all the forms in the project i am running a form from .
Suppose i am running a project which has 4 forms 1.Form1 2.Form2 3.Form3 4.Form4
and i want to retrieve the list of them for further direction which form to direct to
Writing C# Code to Display a Modal FormPress F5 once again to build and run the application. After pressing the button in the main form to display the sub form you will find that the main form is inactive as long as the sub form is displayed. Until the sub form is dismissed this will remain the case.
The trick is to use Application. Run() without parameters and Application. Exit() at the point where you want to exit the application. Now when you run the application, Form1 opens up.
Do you mean:
If run-time, do you mean:
If at Design-time, then I don't know.
If you mean at run-time, and you want all forms declared, you need to resort to reflection. Iterate through all types in your assembly(/ies) and find all types inheriting from the Form
class.
Something like this would do:
Type formType = typeof(Form);
foreach (Type type in Assembly.GetExecutingAssembly().GetTypes())
if (formType.IsAssignableFrom(type))
{
// type is a Form
}
If you mean at run-time, and you want all open forms, you can use Application.OpenForms.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With