Click to See Complete Forum and Search --> : Start windows application without a form?


grignard
October 19th, 2008, 08:34 AM
I am trying to start a Windows Application with a non form class Class1. The object of Class1 should insatiate the form Form1 like this:


namespace WindowsApplication2
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Class1 someobject=new Class1();
Application.Run();
}
}
}



namespace WindowsApplication2
{
class Class1
{
private Form1 myform;

public Class1()
{
myform=new Form1();
}
}
}



namespace WindowsApplication2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
}
}


The code is really simple and I can not understand why this is not working
could anyone please give me an advice what is wrong and how to do?

Arjay
October 19th, 2008, 12:18 PM
You'll at least need to call Show on the form.

class Class1
{
private Form1 myform;

public Class1()
{
myform=new Form1();
myform.Show( );
}
}

grignard
October 19th, 2008, 03:16 PM
Ok. thank you very much for your anwer it really helped me. Why dont I have to do the show-method if I instaniate the form from the main method? I normaly create other forms from objects without using show. Is there a special need for show-method for the first form created?

dglienna
October 19th, 2008, 03:23 PM
The form is loaded into memory, (Form Load) then it activates (Form Activated) and then it's fianlly displayed.

You are loading it into memory and intiializeing it, but not mapping it to the sceen namespace