0

Hello Stack Overflow community,

I have taken up the project of making an installer/launcher for a game I am working on, and I have currently run into an issue, I want the installer to open in the center of the screen resolution, with the base UI, which looks like:

Base UI

The Label in the center named "MainText" is preconfigured to say "Configuring", there is also a hidden label in the corner named "label1" for debugging purposes.

The code I currently have inside of the MainForm.cs so far is below, the "programpath" refers to current directory in which the application is inside of.

public MainForm()
    {
        //Open Window
        InitializeComponent();
        //placeholder song
        System.Media.SoundPlayer player = new System.Media.SoundPlayer(programpath+"\\GTA 4 Loading Screen Normalized No intro.wav");
        player.PlayLooping();
        //newLaunch();
        }

        void newLaunch(){
        File.Create(programpath+"\\FirstLaunch.lic");

            MainText.Visible=true;
            MainText.Text="Configuring Machine....\nInstalling DirectX";    
            Process.Start(programpath+"\\dxwebsetup.exe");
            label1.Text=programpath+"\\dxwebsetup.exe";
        }

However, if I uncomment "newLaunch()", the dxwebsetup application opens, then the actual UI opens with the MainText stating "Configuring Machine....Installing DirectX", and label1 saying the location of the installer.

How do I make the UI for the application itself appear then start running the code after....similar to an actual installer, however still being completely autonomous, and installing everything on it's own.

  • Insert `newLaunch();` in the [Shown](https://msdn.microsoft.com/en-us/library/system.windows.forms.form.shown(v=vs.110).aspx) event of your Form. Not in its constructor. – Jimi Jun 13 '18 at 00:29
  • 2
    I know this isn't what you're asking, so feel free to throw this out, but I would recommend you not to build your own installer. There are a *lot* of caveats to doing this and a lot more edge cases than you might expect. There are programs and frameworks out there that create an installer for you. Using those is almost certainly a net benefit for you. Info on using these can be found here: https://stackoverflow.com/questions/49624070/how-to-create-windows-installer – Herbstein Jun 13 '18 at 00:29
  • @Jimi, where is the shown event? It is not inside of MainForm.cs or its designer, or Program.cs – NaturalistUbuntu Jun 13 '18 at 00:45
  • Designer: Form → Properties → Events. Or, in the constructor, `this.Shown += (s, e) => { newLaunch(); };` – Jimi Jun 13 '18 at 00:53
  • @Jimi, I was able to use the constructor line you gave me, thank you, but wher do I find the Event's Properties, as you stated earlier, it seems like that is a Visual Studio thing, whereas I am using SharpDevelop..... – NaturalistUbuntu Jun 13 '18 at 00:59
  • SharpDevelop's IDE is a VIsual Studio look-alike. The properties window is in the same place and has the same lightning bolt symbol for the events. I'm not sure whether the Shown event is available there. But it doesn't really matter as you have already coded it yourself. – Jimi Jun 13 '18 at 01:11
  • Does anyone happen to know how to place the window in the center of the screen? – NaturalistUbuntu Jun 13 '18 at 02:12

1 Answers1

0

If I'm understanding your problem correctly, all you need to do is add a handler for when the Form is shown. When InitializeComponent is finished calling, it doesn't mean the form has been fully opened yet.

After InitializeComponent, (or preferrably inside) you could simply add

Load += OnLoad;

Followed by

public void OnLoad(object sender, EventArgs e)
{

}

Which is where you can add or call the launch function.