Exemplo n.º 1
0
        // Triggers when the Add button is clicked.
        private void AddButton_Click(object sender, EventArgs e)
        {
            // Opens up a new instance of the ObjectForm.
            var form   = new ObjectForm(Simulation);
            var result = form.ShowDialog();

            // Waits until the form has closed, and then checks the outcome of it. If DialogResult.OK is returned,
            // the ObjectForm has returned a SolarObject successfully.
            if (result == DialogResult.OK)
            {
                int last = 1;
                if (ObjectList.Items.Count != 0)
                {
                    last = ObjectList.Items.Count + 1;
                }
                form.SolarObject.ID = last;
                // Adds the new SolarObject to the Simulation Object list
                Simulation.PlanetarySystem.Objects.Add(form.SolarObject);
                // Adds the new SolarObject's name to the ControlForm object list
                ObjectList.Items.Add(form.SolarObject.ID + ": " + form.SolarObject.Name);
                // Enables the Run button if it wasn't already enabled, as there are now objects in the Simulation
                RunButton.Enabled = true;
                // Sets the "Changed" flag to true, to indicate to the Simulation Window that a new object has been added to the Simulation.
                if (Window != null)
                {
                    Simulation.Changed = true;
                }
            }
        }
Exemplo n.º 2
0
        // Triggers when the Edit button is clicked.
        private void EditButton_Click(object sender, EventArgs e)
        {
            // Opens up a new instance of the ObjectForm. The selected object is passed into the instance.
            var form   = new ObjectForm(Simulation, Simulation.PlanetarySystem.Objects.First(x => x.ID + ": " + x.Name == ObjectList.SelectedItems[0].Text));
            var result = form.ShowDialog();

            // Waits until the form has closed, and then checks the outcome of it. If DialogResult.OK is returned,
            // the ObjectForm has returned the modified successfully.
            if (result == DialogResult.OK)
            {
                // The relevant SolarObject is updated from the form's returned SolarObject.
                Simulation.PlanetarySystem.Objects[Simulation.PlanetarySystem.Objects.IndexOf(form.SolarObject)] = form.SolarObject;
                // The relevant SolarObject's name is updated from the form's returned SolarObject's name.
                ObjectList.SelectedItems[0].Text = form.SolarObject.ID + ": " + form.SolarObject.Name;
                // Sets the "Changed" flag to true, to indicate to the Simulation Window that an object in the Simulation has been changed.
                if (Window != null)
                {
                    Simulation.Changed = true;
                }
            }
        }