Exemplo n.º 1
0
        private void Rename_Click(object sender, EventArgs e)
        {
            // Test that we have a selected item
            int index = ListBoxEnvironments.SelectedIndex;

            if (index == -1)
            {
                MessageBox.Show("Please select an environment to rename");
            }
            else
            {
                AddEnvironment fa = new AddEnvironment();   // Note: this form class should have been named FormAddEnvironment

                // Set the public environment variable to selected item
                fa.EnvironmentName = ListBoxEnvironments.SelectedItem.ToString();

                DialogResult dr = fa.ShowDialog();

                // Test for OK pressed
                if (dr == DialogResult.OK)
                {
                    // Get the environment name
                    string environment = fa.EnvironmentName;

                    // Update the list of environments in Document Properties and this settings dialog
                    // Replace the selected item in list at same index position
                    ListBoxEnvironments.Items.RemoveAt(index);
                    ListBoxEnvironments.Items.Insert(index, environment);

                    // Update public class
                    // Only want to preserve the original name for matching
                    if ((EnvironmentList[index].Oldname == null) || (EnvironmentList[index].Oldname == ""))
                    {
                        EnvironmentList[index].Oldname = EnvironmentList[index].Name;
                    }
                    EnvironmentList[index].Name = environment;

                    // Dispose of the child form object
                    fa.Dispose();
                }
            }
        }
Exemplo n.º 2
0
        private void ButtonAdd_Click(object sender, EventArgs e)
        {
            AddEnvironment fa = new AddEnvironment();   // Note: this form class should have been named FormAddEnvironment
            DialogResult   dr = fa.ShowDialog();

            // Test for OK pressed
            if (dr == DialogResult.OK)
            {
                // Get the environment name
                string environment = fa.EnvironmentName;

                // Update the list of environments in Document Properties and this settings dialog
                ListBoxEnvironments.Items.Add(environment);

                // Update the public class
                CalculonEnvironment env = new CalculonEnvironment();
                env.Name = environment;
                EnvironmentList.Add(env);

                // Dispose of the child form object
                fa.Dispose();
            }
        }