private void cmdOK_Click(object sender, EventArgs e)
 {
     for (int I = 0; I < Elements.Count; I++)
     {
         Type elType = Elements[I].GetType();
         if (elType == typeof(FileElement))
         {
             FileElement fe = Elements[I] as FileElement;
             if (fe.Halt == true)
             {
                 string caption = fe.Caption;
                 string text;
                 text = "The value you entered for " + caption + " has the following error:\n" +
                        fe.LightMessage + "\n";
                 MessageBox.Show(text, "Some Parameters are invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 return;
             }
         }
         if (elType == typeof(LayerFileElement))
         {
             LayerFileElement fe = Elements[I] as LayerFileElement;
             if (fe.Halt == true)
             {
                 string caption = fe.Caption;
                 string text;
                 text = "The value you entered for " + caption + " has the following error:\n" +
                        fe.LightMessage + "\n";
                 MessageBox.Show(text, "Some Parameters are invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 return;
             }
         }
         else if (elType == typeof(TextElement))
         {
             TextElement fe = Elements[I] as TextElement;
             if (fe.Halt == true)
             {
                 string caption = fe.Caption;
                 string text;
                 text = "The value you entered for " + caption + " has the following error:\n" +
                        fe.LightMessage + "\n";
                 MessageBox.Show(text, "Some Parameters are invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 return;
             }
         }
         else if (elType == typeof(ComboBoxElement))
         {
             ComboBoxElement fe = Elements[I] as ComboBoxElement;
             if (fe.Halt == true)
             {
                 string caption = fe.Caption;
                 string text;
                 text = "The value you entered for " + caption + " has the following error:\n" +
                        fe.LightMessage + "\n";
                 MessageBox.Show(text, "Some Parameters are invalid", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 return;
             }
         }
     }
     this.DialogResult = DialogResult.OK;
     if (!this.Modal)
     {
         this.Hide();
     }
 }
        /// <summary>
        /// Adds a an element to the dialog that allows the selection of a layer or a file.
        /// The layernames must be added manually.
        /// </summary>
        /// <param name="ElementType">Specifies exactly what sort of files will work</param>
        /// <returns>A LayerFileElement object that was added to the dialog</returns>
        public LayerFileElement Add_LayerFileElement(ElementTypes ElementType)
        {
            LayerFileElement MyLayerFileELement = new LayerFileElement();

            if (ElementType == ElementTypes.OpenFile || ElementType == ElementTypes.OpenGridFile ||
                ElementType == ElementTypes.OpenImageFile || ElementType == ElementTypes.OpenShapefile)
            {
                MyLayerFileELement.FileAccess = LayerFileElement.FileAccessType.Open;
                MyLayerFileELement.HelpImage  = MyLayerFileELement.DefaultImage;
            }
            else
            {
                MyLayerFileELement.FileAccess = LayerFileElement.FileAccessType.Save;
                MyLayerFileELement.HelpImage  = MyLayerFileELement.AlternateImage;
            }
            switch (ElementType)
            {
            case ElementTypes.OpenFile:
                MyLayerFileELement.FileType = LayerFileElement.FileTypes.All;
                MyLayerFileELement.Caption  = "Input Filename";
                MyLayerFileELement.HelpText = "Retrieves a filename for an unspecified file format either through the textbox or through the browse button.  A green light indicates that the file exists.  A red light indicates that the file does not exist.";
                break;

            case ElementTypes.OpenGridFile:
                MyLayerFileELement.FileType = LayerFileElement.FileTypes.Grid;
                MyLayerFileELement.Caption  = "Input Grid Filename";
                MyLayerFileELement.HelpText = "Retrieves a filename for a grid file format either through the textbox or through the browse button.  A green light indicates that the file exists.  A red light indicates that the file does not exist.";
                break;

            case ElementTypes.OpenImageFile:
                MyLayerFileELement.FileType = LayerFileElement.FileTypes.Image;
                MyLayerFileELement.Caption  = "Input Image Filename";
                MyLayerFileELement.HelpText = "Retrieves a filename for an image file format either through the textbox or through the browse button.  A green light indicates that the file exists.  A red light indicates that the file does not exist.";
                break;

            case ElementTypes.OpenShapefile:
                MyLayerFileELement.FileType = LayerFileElement.FileTypes.Shapefile;
                MyLayerFileELement.Caption  = "Input Shapefile Filename";
                MyLayerFileELement.HelpText = "Retrieves a filename for a shapefile either through the textbox or through the browse button.  A green light indicates that the file exists.  A red light indicates that the file does not exist.";
                break;

            case ElementTypes.SaveFile:
                MyLayerFileELement.FileType = LayerFileElement.FileTypes.All;
                MyLayerFileELement.Caption  = "Output Filename";
                MyLayerFileELement.HelpText = "Retrieves a filename for an unspecified file format either through the textbox or through the browse button.  A green light indicates that a file of that name does not exist yet or permission to overwrite was given through the browse dialog.  A red light indicates that a file with that name exists.";
                break;

            case ElementTypes.SaveImageFile:
                MyLayerFileELement.FileType = LayerFileElement.FileTypes.Image;
                MyLayerFileELement.Caption  = "Output Image Filename";
                MyLayerFileELement.HelpText = "Retrieves a filename for an image file format either through the textbox or through the browse button.  A green light indicates that a file of that name does not exist yet or permission to overwrite was given through the browse dialog.  A red light indicates that a file with that name exists.";
                break;

            case ElementTypes.SaveGridFile:
                MyLayerFileELement.FileType = LayerFileElement.FileTypes.Grid;
                MyLayerFileELement.Caption  = "Output Grid Filename";
                MyLayerFileELement.HelpText = "Retrieves a filename for a grid file format either through the textbox or through the browse button.  A green light indicates that a file of that name does not exist yet or permission to overwrite was given through the browse dialog.  A red light indicates that a file with that name exists.";
                break;

            case ElementTypes.SaveShapefile:
                MyLayerFileELement.FileType = LayerFileElement.FileTypes.Shapefile;
                MyLayerFileELement.Caption  = "Output Shapefile Filename";
                MyLayerFileELement.HelpText = "Retrieves a filename for a shapefile either through the textbox or through the browse button.  A green light indicates that a file of that name does not exist yet or permission to overwrite was given through the browse dialog.  A red light indicates that a file with that name exists.";
                break;
            }
            Elements.Add(MyLayerFileELement);
            MyLayerFileELement.ResizeGripVisible = false;
            MyLayerFileELement.HaltOnEmpty       = true;
            MyLayerFileELement.HaltOnError       = true;
            MyLayerFileELement.HelpButtonVisible = true;
            MyLayerFileELement.LightVisible      = true;
            MyLayerFileELement.Location          = new System.Drawing.Point(3, 10 + ((Elements.Count - 1) * 55));
            MyLayerFileELement.Name = "Element" + Elements.Count;
            int myWidth = this.panelElementContainer.Width - MyLayerFileELement.Left - 10;

            MyLayerFileELement.Anchor              = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right | System.Windows.Forms.AnchorStyles.Top)));
            MyLayerFileELement.Size                = new System.Drawing.Size(myWidth, 45);
            MyLayerFileELement.Status              = LayerFileElement.LightStatus.Empty;
            MyLayerFileELement.HelpButtonPressed  += new LayerFileElement.HelpButtonHandler(Element_HelpButtonPressed);
            MyLayerFileELement.ResizeStarted      += new LayerFileElement.ResizeStartedHandler(Element_ResizeStarted);
            MyLayerFileELement.ResizeEnded        += new LayerFileElement.ResizeEndedHandler(Element_ResizeEnded);
            MyLayerFileELement.HelpContextChanged += new LayerFileElement.HelpButtonHandler(MyFileElement_HelpContextChanged);
            MyLayerFileELement.Clicked            += new EventHandler(panelElementContainer_Click);
            this.panelElementContainer.Controls.Add(MyLayerFileELement);
            return(MyLayerFileELement);
        }