private void optVertSeaTop_CheckedChanged(object eventSender, EventArgs eventArgs)
        {
            if (optVertSeaTop.Checked)
            {
                TextBoxFormDistances.Clear();
                txtHE.Text          = "";
                txtHO.Text          = "";
                txtHsDeg.Text       = "";
                txtHsMin.Text       = "";
                txtHsSec.Text       = "";
                txtIEdeg.Text       = "";
                txtIEmin.Text       = "";
                txtIESec.Text       = "";
                lblHE.Visible       = true;
                txtHE.Visible       = true;
                cboHE.Visible       = true;
                lblHO.Visible       = true;
                txtHO.Visible       = true;
                cboHO.Visible       = true;
                lblHsFormat.Visible = true;
                optHsDMm.Visible    = true;
                optHsDMS.Visible    = true;
                lblHs.Visible       = true;
                txtHsDeg.Visible    = true;
                lblHsDeg.Visible    = true;
                txtHsMin.Visible    = true;
                lblHsMin.Visible    = true;
                lblIE.Visible       = true;
                txtIEdeg.Visible    = true;
                lblIEdeg.Visible    = true;
                txtIEmin.Visible    = true;
                lblIEMin.Visible    = true;
                cboIE.Visible       = true;
                txtHsSec.Visible    = false;
                lblHsSec.Visible    = false;
                txtIESec.Visible    = false;
                lblIEsec.Visible    = false;
                if (optHsDMS.Checked == true)
                {
                    txtHsSec.Visible = true;
                    lblHsSec.Visible = true;
                    txtIESec.Visible = true;
                    lblIEsec.Visible = true;
                }
            }

            Refresh();
        }
        private void cmdCalculate_Click(object eventSender, EventArgs eventArgs)
        {
            TextBoxFormDistances.Clear();
            HeightConversion();
            if (optVertSeaTop.Checked == true & HEinFeet > HOinFeet)
            {
                ErrorMsgBox("Height of Eye cannot be greater than height of object.");
                return;
            }

            if (optDistHorizon.Checked == true)
            {
                Dist = 1.169497d * Math.Sqrt(HEinFeet);
                TextBoxFormDistances.AppendText("Distance of the Horizon: " + Strings.Format(Dist, "#0.0") + " nm = " + Strings.Format(Dist * 1.1507765d, "#0.0") + " mi" + Constants.vbCrLf);
            }

            if (optGeogRange.Checked == true)
            {
                Dist = 1.169497d * (Math.Sqrt(HEinFeet) + Math.Sqrt(HOinFeet));
                TextBoxFormDistances.AppendText("Geographical Range of Visibility: " + Strings.Format(Dist, "#0.0") + " nm = " + Strings.Format(Dist * 1.1507765d, "#0.0") + " mi" + Constants.vbCrLf);
            }

            if (optVertWaterTop.Checked == true) // Table 16 (Bowditch 2002)
            {
                Dip = 0d;
                AltitudeCorrection();
                if (hainDegrees <= 0d)
                {
                    ErrorMsgBox("Corrected altitude must be greater than zero");
                    return;
                }

                if (hainDegrees > 90d)
                {
                    ErrorMsgBox("Corrected altitude cannot exceed 90º");
                    return;
                }

                Dist = HOinFeet / Math.Tan(hainDegrees * Pi / 180d); // feet
                Dist = Dist / 6076.1154d;                            // nautical miles
                                                                     // Dist = Int(Dist * 100 + 0.5) / 100
                TextBoxFormDistances.AppendText("Distance to Object: " + Strings.Format(Dist, "#0.00") + " nm = " + Strings.Format(Dist * 1.1507765d, "#0.00") + " mi" + Constants.vbCrLf);
            }

            if (optVertWaterSea.Checked == true) // Table 17 (Bowditch 2002)
            {
                Dip = 0d;
                AltitudeCorrection();
                if (hainDegrees <= 0d)
                {
                    ErrorMsgBox("Corrected altitude must be greater than zero");
                    return;
                }

                if (hainDegrees > 90d)
                {
                    ErrorMsgBox("Corrected altitude cannot exceed 90º");
                    return;
                }

                HEinNM = HEinFeet / 6076.1154d;
                B      = Math.Sqrt(2d * 0.8279d * (HEinNM / 3440.1d));
                A      = (Math.Tan(hainDegrees * Pi / 180d) + B) * (1d - Math.Tan(hainDegrees * Pi / 180d) * B);
                Dist   = 2025.3718d * (A * 3440.1d - Math.Sqrt(Math.Pow(A * 3440.1d, 2d) - 2d * HEinNM * 3440.1d * 0.8279d)) / 0.8279d;
                TextBoxFormDistances.AppendText("Distance to Object: " + Strings.Format(Dist, "#0") + " yards = " + Strings.Format(Dist / 2025.3718d, "#0.00") + " nm = " + Strings.Format(Dist / 1760d, "#0.00") + " mi" + Constants.vbCrLf);
            }

            if (optVertSeaTop.Checked == true) // Table 15 (Bowditch 2002)
            {
                if (cboHE.Text == "ft" | cboHE.Text == "in")
                {
                    switch (HE)
                    {
                    case var @case when @case < 2f:
                    {
                        Dip = 0.7d * HE;
                        break;
                    }

                    case var case1 when case1 <= 3.9f:
                    {
                        Dip = 1.4d + (HE - 2f) * 0.25d;
                        break;
                    }

                    case var case2 when case2 <= 5.9f:
                    {
                        Dip = 1.9d + (HE - 4f) * 0.25d;
                        break;
                    }

                    case var case3 when case3 <= 7.6f:
                    {
                        Dip = 2.4d + (HE - 6f) * 0.15d;
                        break;
                    }

                    case var case4 when case4 >= 7.7f:
                    {
                        Dip = 0.970003d * Math.Sqrt(HE);
                        break;
                    }
                    }
                }

                if (cboHE.Text == "m " | cboHE.Text == "cm")
                {
                    switch (HE)
                    {
                    case var case5 when case5 < 1f:
                    {
                        Dip = 1.79d * HE;
                        break;
                    }

                    case var case6 when case6 <= 1.6f:
                    {
                        Dip = 1.79d * Math.Sqrt(HE);
                        break;
                    }

                    case var case7 when case7 >= 1.7f:
                    {
                        Dip = 1.76d * Math.Sqrt(HE);
                        break;
                    }
                    }
                }

                AltitudeCorrection();
                if (hainDegrees > 90d)
                {
                    ErrorMsgBox("Corrected altitude cannot exceed 90º");
                    return;
                }

                Dist = Math.Sqrt(Math.Pow(Math.Tan(hainDegrees * Pi / 180d) / 0.0002419d, 2d) + (HOinFeet - HEinFeet) / 0.7349d) - Math.Tan(hainDegrees * Pi / 180d) / 0.0002419d;
                TextBoxFormDistances.AppendText("Distance to Object: " + Strings.Format(Dist, "#0.0") + " nm = " + Strings.Format(Dist * 1.1507765d, "#0.0") + " mi" + Constants.vbCrLf);
            }

            if (optVertWaterTop.Checked == true | optVertWaterSea.Checked == true | optVertSeaTop.Checked == true)
            {
                TextBoxFormDistances.AppendText("Corrected Vertical Angle: " + Strings.Format(Dist, "#0.0") + " nm = " + Strings.Format(Dist * 1.1507765d, "#0.0") + " mi" + Constants.vbCrLf);
                if (hainDegrees < 0d)
                {
                    TextBoxFormDistances.AppendText("Corrected Vertical Angle: " + "-" + Strings.Format(haDegrees, "0") + '°' + Strings.Format(haMinutes, "00.0") + Constants.vbCrLf);
                }
                else if (haMinutes >= 60d)
                {
                    haMinutes = haMinutes - 60d;
                    haDegrees = (short)(haDegrees + 1);
                    TextBoxFormDistances.AppendText("Corrected Vertical Angle: " + Strings.Format(haDegrees, "0") + '°' + Strings.Format(haMinutes, "00.0") + Constants.vbCrLf);
                }
                else
                {
                    TextBoxFormDistances.AppendText("Corrected Vertical Angle: " + Strings.Format(haDegrees, "0") + '°' + Strings.Format(haMinutes, "00.0") + Constants.vbCrLf);
                }
            }

            Refresh();
        }