开发者

overrided method doesn't gets called

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.


When you call Application.Run() you are running the application without a form.


Why should it, if in the second code sample there is no real Form shown and used in the App?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜