Newer
Older
EMS_REFACTOR / FrmTackPolygonDlg.cs
nn-203 on 26 Jul 2017 1 KB first commit
using System;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace Cyberpipe
{
    public partial class FrmTackPolygonDlg : Office2007Form
    {
        public double depth;
        public FrmTackPolygonDlg()
        {
            InitializeComponent();
            
        }
        /// <summary>
        /// 确定按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            depth = Convert.ToDouble(txtDepth.Text);
            DialogResult = DialogResult.OK;
            Close();
        }
        /// <summary>
        /// 键盘按键按下事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void txtDepth_KeyPress(object sender, KeyPressEventArgs e)
        {
            TextBox text = sender as TextBox;
            if ((e.KeyChar < 48 || e.KeyChar > 57) && (e.KeyChar != 8) && e.KeyChar != 46)
            {
                e.Handled = true;
            }
            if (e.KeyChar == 46)                           //小数点
            {
                if (text.Text.Length <= 0)
                    e.Handled = true;   //小数点不能在第一位
                else                                             //处理不规则的小数点
                {
                    float f;
                    float oldf;
                    bool b1 = false, b2 = false;
                    b1 = float.TryParse(text.Text, out oldf);
                    b2 = float.TryParse(text.Text + e.KeyChar, out f);
                    if (b2 == false)
                    {
                        if (b1)
                            e.Handled = true;
                        else
                            e.Handled = false;
                    }
                }
            }
        }
    }
}