Пример #1
0
        /// <summary>
        ///     ''' Select ASCOM driver to use including pre-selecting one in the drop-down list
        ///     ''' </summary>
        ///     ''' <param name="DriverProgID">Driver to preselect in the chooser dialogue</param>
        ///     ''' <returns>Driver ID of chosen driver</returns>
        ///     ''' <exception cref="Exceptions.InvalidValueException">Thrown if the Chooser.DeviceType property has not been set before Choose is called.
        ///     ''' It must be set in order for Chooser to know which list of devices to display.</exception>
        ///     ''' <remarks>The supplied driver will be pre-selected in the Chooser's list when the chooser window is first opened.
        ///     ''' </remarks>
        public new string Choose(string DriverProgID)
        {
            string      selectedProgId;
            ChooserForm chooserFormInstance;

            try
            {
                if (string.IsNullOrEmpty(deviceTypeValue))
                {
                    throw new Exceptions.InvalidValueException("Unknown device type, DeviceType property has not been set");
                }
                chooserFormInstance = new ChooserForm(); // Initially hidden

                chooserFormInstance.DeviceType     = deviceTypeValue;
                chooserFormInstance.SelectedProgId = DriverProgID;
                chooserFormInstance.ShowDialog(); // Display MODAL Chooser dialogue

                selectedProgId = chooserFormInstance.SelectedProgId;

                chooserFormInstance.Dispose();
            }
            catch (DriverNotRegisteredException ex)
            {
                MsgBox("Chooser Exception: " + ex.Message);
                LogEvent("Chooser", "Exception", EventLogEntryType.Error, EventLogErrors.ChooserException, ex.ToString);
                selectedProgId = "";
            }

            catch (Exception ex)
            {
                Interaction.MsgBox("Chooser Exception: " + ex.ToString());
                LogEvent("Chooser", "Exception", EventLogEntryType.Error, EventLogErrors.ChooserException, ex.ToString());
                selectedProgId = "";
            }

            return(selectedProgId);
        }