Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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...
Posted
Updated 13-Feb-12 20:20pm
v2
Comments
RDBurmon 14-Feb-12 2:19am    
Let me know syntax of override function
Sergey Alexandrovich Kryukov 14-Feb-12 2:20am    
Excuse me?!...
--SA
Sergey Alexandrovich Kryukov 14-Feb-12 2:30am    
Why? why?!
--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
 
Share this answer
 
Comments
Member 11338532 16-Sep-17 6:48am    
The guy is just learning, give him a break.
If you simply wish to change the initial form from TrialNew to a new form type then:

C#
Application.Run(new MyForm());


if you wish you can make Myform inherit from TrialNew.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900