Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
370 views
in Technique[技术] by (71.8m points)

.net - How to find the main() entry point in a VB.Net winforms app?

When I create a WinForms app in C#, the output type is Windows Application and I get a program.cs with a static void Main() which I can use to handle command-line parameters, etc...

However, when I create an equivalent project for VB, the application type is Windows Forms Application and I'm forced to pick a startup form.

Is there an equivalent mechanism to run my own code before I decide which form to display in VB.Net? I'm assuming the same code exists but is auto-generated and hidden somewhere? If so, where?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In VB you'll need to create your sub main by hand as it were so what I generally do is create a new Module named Program.

Within that as a very basic setup you'll need to add the following code.

Public Sub Main()

    Application.EnableVisualStyles()
    Application.SetCompatibleTextRenderingDefault(False)
    Application.Run(New Form1)

End Sub

Once you've done that go to the application tab of the project's settings and uncheck the 'Enable Application framework' setting and then from the drop down under Startup object select your new Sub Main procedure.

You can then put any start-up code that you want to run before your program opens its main form before the Application.Run line.

Hope that helps


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...