using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; 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); this.DialogResult = DialogResult.OK; this.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) && (int)e.KeyChar != 46) { e.Handled = true; } if ((int)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.ToString(), out f); if (b2 == false) { if (b1 == true) e.Handled = true; else e.Handled = false; } } } } } }