如何在C#中覆盖Application.Run() [英] how to override Application.Run() in c#

查看:67
本文介绍了如何在C#中覆盖Application.Run()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在我的program.cs中,我以初始形式打开TrialNew
Application.Run(new TrialNew());

我需要将TrialNew作为新表单覆盖.
如何覆盖此问题...
并且如果在我再次打开应用程序时完成重写,则新表单应该是我的初始表单...怎么做...

Hi,
in my program.cs i am opening TrialNew as initial form
Application.Run(new TrialNew());

i need to override the TrialNew as New form.
how to override this...
and if my override is done when i open the application again New form should be my initial form... how to do...

推荐答案

MSDN文档中,所有System.Windows.Forms.Application.Run方法都是静态的,而不是虚拟的.

您不能覆盖非虚拟函数,并且在.NET中,静态函数不能是虚拟函数(与某些其他平台/语言不同).

好像还不够,类System.Windows.Forms.Application被标记为密封的,因此,不仅不能覆盖所需的方法,甚至不能基于Application定义类.

请参阅 http://msdn.microsoft.com/en-us/library/system.windows.forms.application.aspx [ ^ ].

您没有理由提出这个毫无意义的问题,因为每个人都可以查看文档.如果答案对您而言不明显,则意味着在学习OOP的最简单基础之前,您不应该进行任何UI开发.

即使这几乎没有用,我仍然可以解释您可以做些什么来再次运行应用程序.您可以简单地以不同的形式运行Application,然后成为新的主要形式.有时会使用此技巧,但我不推荐使用.

也就是说,您以某种方式将覆盖与简单的非OOP调用混合在一起,这意味着,您还需要学习一些OOP之前的知识:函数,参数,函数返回,实际参数,形式参数,类型,实例……几乎所有内容…

当您感到舒适时,请再次返回UI开发.如果您遇到问题,请再次询问.我们很乐意为您提供帮助.

—SA
As you can see from MSDN documentation, all System.Windows.Forms.Application.Run methods are static, not virtual.

You cannot override non-virtual function, and in .NET a static function cannot be virtual (unlike some other platforms/languages).

As if it wasn''t enough, the class System.Windows.Forms.Application is marked sealed, so, not only you cannot override the method you want, you cannot even define a class based on Application.

Please see http://msdn.microsoft.com/en-us/library/system.windows.forms.application.aspx[^].

You had no reason to ask this pointless question, because every one can look at documentation. If the answer was not apparent to you, it means that you should not do any UI development before you lean the simplest basics of OOP.

Even though this is pretty much useless, I nevertheless can explain what could you do to run application again. You could simply run Application with a different form, which then becomes a new main form. This trick is used sometimes, but I don''t recommend it.

That said, you somehow mix up overrides with a simple non-OOP call, which means, you also need to learn some pre-OOP stuff: functions, parameters, function return, actual parameters, formal parameters, types, instances… pretty much everything…

When you feel comfortable, come back to UI development again. If you face a problem ask again; we will gladly help you.

—SA


如果您只是希望将初始表单从TrialNew更改为新表单类型,则:

If you simply wish to change the initial form from TrialNew to a new form type then:

Application.Run(new MyForm());



如果愿意,可以使Myform从TrialNew继承.



if you wish you can make Myform inherit from TrialNew.


这篇关于如何在C#中覆盖Application.Run()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆