public partial class Form1 : Form
{
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
}
}
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
When I ran the above code, it called the method protected override void WndProc(ref Message m)
When I changed the code like below
Form1 form1 = new Form1();
Application.Run();
it didn’t call the method protected override void WndProc(ref Message m)
Can any one explain me why is this happening?
When you call Application.Run() you are running the application without a form.
See
http://msdn.microsoft.com/en-us/library/system.windows.forms.application.run.aspx
for the difference.
The top one you are passing your form as a parameter to the Application.Run function call, which allows it to use your form, the second case it has no idea what form to use.