条款3 如何设定启动对象
启动对象就是当加载应用程序时所要调用的进入点(Entry Point)。一般来说,我们会将启动对象设定成应用程序的主窗体,或是当应用程序激活时所会执行的Main程序。值得注意的是,类库项目与ASP.NET Web应用程序项目都没有进入点,因此没有启动对象。
第1章应用程序的基础设置技巧要给一个Visual C# 2005的Windows应用程序项目设定启动对象,您必须修改Programcs文件,基本的程序代码如下所示:using System;
using SystemCollectionsGeneric;
using SystemWindowsForms;
namespace CH1
{
static class Program
{
/// <summary>
/// 应用程序的主要进入点。
/// </summary>
[STAThread]
static void Main()
{
ApplicationEnableVisualStyles();
ApplicationSetCompatibleTextRenderingDefault(false);
ApplicationRun(new StartUpForm());
}
}
}
using SystemWindowsForms;
namespace CH1
{
static class Program
{
/// <summary>
/// 应用程序的主要进入点。
/// </summary>
[STAThread]
static void Main()
{
ApplicationEnableVisualStyles();
ApplicationSetCompatibleTextRenderingDefault(false);
ApplicationRun(new StartUpForm());
}
}
}
上述写法是一种常见的写法,那就是把启动窗体传递给ApplicationRun方法。当然,您也可以将项目中其他已有的窗体名称传递给ApplicationRun方法,以便使用该窗体作为启动窗体。
图书导读






