コード例 #1
0
        private void LoadProgram()
        {
            // Create an instance of the open file dialog box.
            OpenFileDialog fileDialog = new OpenFileDialog();

            // Set filter options and filter index.
            fileDialog.Filter      = "XML Files (.xml)|*.xml|All Files (*.*)|*.*";
            fileDialog.FilterIndex = 1;
            fileDialog.Multiselect = false;

            // Show the dialog and get result.
            DialogResult result = fileDialog.ShowDialog();

            if (result == DialogResult.OK) // Test result.
            {
                string         path     = fileDialog.FileName;
                MotionCommands commands = CommandsStore.Load(path);

                if (commands != null && commands.Count > 0)
                {
                    this.programControl.Commands = commands;

                    this.lstCommands.Items.Clear();
                    MotionCommand[] test = new MotionCommand[this.programControl.Commands.Count];
                    this.programControl.Commands.CopyTo(test, 0);
                    this.lstCommands.Items.AddRange(test);
                }

                this.programName = Path.GetFileNameWithoutExtension(path);

                this.lblProgramName.Text = String.Format("Program: {0}", this.programName);
            }
        }
コード例 #2
0
        private void SaveProgram()
        {
            // Create an instance of the open file dialog box.
            SaveFileDialog fileDialog = new SaveFileDialog();

            // Set filter options and filter index.
            fileDialog.Filter      = "XML Files (.xml)|*.xml|All Files (*.*)|*.*";
            fileDialog.FilterIndex = 1;

            if (this.programName == "")
            {
                this.programName = AppUtils.CreateProgramName();
            }

            fileDialog.FileName = this.programName;
            //fileDialog.Multiselect = false;

            // Show the dialog and get result.
            DialogResult result = fileDialog.ShowDialog();

            if (result == DialogResult.OK && this.programControl.Commands.Count > 0) // Test result.
            {
                string path = fileDialog.FileName;
                CommandsStore.Save(this.programControl.Commands, path);
            }
        }