1

So I have a program which is itself a console application, but which manages a few forms. The primary form has the ability to launch a secondary form, and I want it to be able to launch more than one of it's secondary forms.

The trouble is when I use the modal command Form.ShowDialog(), I can't navigate away from the secondary form and access the primary one, therefore I can't launch a second secondary.

The trouble I'm running into with Form.Show(), is as soon as the form is launched it closes again. Sure, it runs the initial function, but then it immediately vanishes. What is the best way to approach this modeless display, but keep the forms around?

EDIT: Here is a bit of the format I'm working in. I have a self-defined Process class which handles the forms, each process stored in a list in the console app, and each with it's own myFORM

public class Process
{
    /*The process class is used to track all running processes related to GeFoss(any forms or consol apps, etc)
     * Methods:
     *      -initialize: This has two overloads, one for a form, and one for general objects. Basically this just starts the main part of the app
     *      -ShowDialog: This simply calls the Form.ShowDialog method if the process controls a Form
     *      -_NewThread: Begins a new thread centered on Leo
     *      -Leo: simply launches another copy of the same Object
     */


    public Form myFORM;
    public Type mytype;
.
.
.
.
.
.    .
.
.
 public void ShowDialog()
    {
        //This should only be called when the type of Process is a form. If it isn't a form though, the try-catch will prevent a crash
        try
        {

            myFORM.Show();
        }
        catch (Exception ex)
        {
            MessageBox.Show(Convert.ToString(ex));
        }
    }\

\

EDIT: I was able to find a work-around. As the project I'm working on is sort of like a simulated OS, I told it to launch the main GUI Form using Form.ShowDialog(), and all the following forms using Form.Show(), and this seems to be working for me

  • isn't this common? when you launch a dialog, you shouldn't be navigating to another form of the same solution anyway? Sorry if I misinterpret your question :/ – sora0419 Mar 18 '14 at 20:22
  • Bit of context: I have a project to simulate an OS GUI. The secondary forms are "programs" in the OS (so far just a text editor). I'd like to be able to open more than one "program" at a time – jluetzenberg Mar 18 '14 at 20:30

1 Answers1

0

you need to create another form. Form form = new Form(); Right now, you declare your object but you never create it. Form myForm is like int a; it doesnt have any variables. For each object, you will be able to do the same as the class Form : form.Show(); You are referencing to the same object. That's why it is closing.

popojargo
  • 11
  • 6
  • I mentioned in a comment to an answer which got deleted that the class does create the Form later on, before the ShowDialog() void is called – jluetzenberg Mar 18 '14 at 20:45
  • just to be sure, you are creating a object from Process then proccess.ShowDialog(); or you use the method ShowDialog() from Form? – popojargo Mar 18 '14 at 20:58
  • There is another function called initialize, which the main program calls before the Process.ShowDialog(), and Process.initialize() creates the Form – jluetzenberg Mar 18 '14 at 21:10