Error loading Windows Form from console App
-
I am trying to load a window form from a console App. I inlcude System.Windows and System.Windows.Forms in my project but when I try to load the form by doing Form abc = new Form(params) abc.Show() it doesn't load i.e. it doesn't pop up. Interestingly if I add a MessageBox.Show statement the form loads. Would like to know what's going on here.
-
I am trying to load a window form from a console App. I inlcude System.Windows and System.Windows.Forms in my project but when I try to load the form by doing Form abc = new Form(params) abc.Show() it doesn't load i.e. it doesn't pop up. Interestingly if I add a MessageBox.Show statement the form loads. Would like to know what's going on here.
Gumnaam wrote: Form abc = new Form(params) abc.Show() The following works for me:
using System;
using System.Windows.Forms;public class test
{
public test(){}public class nick : System.Windows.Forms.Form { public nick(){} } public static void Main(string\[\] args) { test t= new test(); nick n = new nick(); n.ShowDialog(); }
}
- Nick Parker
My Blog | My Articles -
I am trying to load a window form from a console App. I inlcude System.Windows and System.Windows.Forms in my project but when I try to load the form by doing Form abc = new Form(params) abc.Show() it doesn't load i.e. it doesn't pop up. Interestingly if I add a MessageBox.Show statement the form loads. Would like to know what's going on here.
try something like this instead SomeForm form = new SomeForm(); form.ShowDialog(); the code above returns a DialogResult but you dont need to necessarily get that value unless you want something back from the user regardless of this - why would you be adding gui elements to a console application to begin with - you might want to create a Windows Forms Application instead.. Danny!