Reputation: 47
I made a test project and added in a couple files.
Now I want the startup file to be say form2.cs
and not form1.cs
.
I'm having a devil of a time finding the setting that tells the project which file to load 1st when being executed.
Can someone point it out to me please?
Upvotes: 2
Views: 2400
Reputation: 81493
in your Program.cs
, which will look something like this
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
Change
Application.Run(new Form1());
To
Application.Run(new Form2());
To change startup window update App.xaml
by changing Application.StartupUri
Application.StartupUri Property
Gets or sets a UI that is automatically shown when an application starts
Remarks
Typically, you set the
StartupUri
property declaratively in XAML. However, you can setStartupUri
programmatically, such as from a Startup event handler, which is useful if for applications that can only load the necessary UI resources at run time. For example, an application might wait until run time to load its resources if the name of the UI resource is stored in a configuration file.
Upvotes: 7
Reputation: 121
I saw a xaml file so I assume that thi is a WPF app. In that case you need to change this in App.xaml
<Application x:Class="WpfApp1.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:WpfApp1"
StartupUri="MainWindow.xaml">
<Application.Resources>
</Application.Resources>
Change StartupUri to the one that you want.
I hope this will help.
Upvotes: 0
Reputation: 817
You are looking for way of changing startup form.
As stated here: Changing startup form in C#
Look in Program.cs in the Main function for something like this
Application.Run(new MyForm());
Change MyForm to your other form.
Upvotes: 1