Dialog boxes with .NET

I'm trying to show up a dialog box in a .NET app.I read at www.functionx.com but I haven't found anything related to this.
I have a form with the dialog(Form) and the main window(Form1)
I have a button called button2
I tryed to use:
1
2
3
4
			void Dialog1Run(Object ^Sender, EventArgs ^Args)
			{
				Application::Run(gcnew Form());
			}

at the using of button2
It gives me an error when debugging:cannot run two message loops....
can somene tell me what shall I do?
Last edited on
Application::Run(gcnew Form()); is for getting the main form running only.
From there, to launch a new form call the Show() or ShowDialog() method of the new form - ShowDialog() makes the new form 'Modal' - IE it takes focus and the calling form doe not continue until the new form closes.
So if your new form is Form, you want
1
2
formInstance = gcnew Form();
formInstance->ShowDialog();


I tried with this,but it cannot compile...This code is in the Form1.h:
1
2
3
4
5
			void Dialog1Run(Object ^Sender, EventArgs ^Args)
			{
				formInstance = gcnew Form();
				formInstance->ShowDialog();
			}

It says that formInstance is an undeclered identifier
Last edited on
I tried
ShowDialog(gcnew Form());
but at debugging says:
An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll

Additional information: Form that is already visible cannot be displayed as a modal dialog box. Set the form's visible property to false before calling showDialog.
As I understand it you have 2 headers, Form1.h which contains the class Form1, and Form.h which contains the class Form.
In Form1.h you have the Dialog1Run() event handler.
Form1.h needs to have #include "Form.h" so it knows what the definition of Form is.
Note: I would advise in future you try to give better names to forms (VS defualts the first one when you create the project, but any subequent forms take the name from the file you add, so add 'OptionsEditor' as the name of the file for a dialog to edit options for example to get 'OptionsEditor.h' containing class 'OptionsEditor' - it will make it easier to keep track of what things are as your projects grow.
Topic archived. No new replies allowed.