วันจันทร์ที่ 14 ตุลาคม พ.ศ. 2556

Method Check input Data in Textbox only numeric(0-9) and dot(.) (C#)

ทำการตรวจสอบ การ Input ค่าลงบน Textbox ต้องเป็น ตัวเลข หรือ . เท่านั้น โดยดักโดนใช้ ACSSII
  
1.ดัก Event   
        private void Textbox1_Keyprass(object sender, KeyPressEventArgs e)
        {
            e.Handled = CheckKeycode(e.KeyChar);
        }


2.Check Input
 public bool CheckKeycode(char CurrentChar)
        {
            int cInt = Convert.ToInt32(CurrentChar);
            if ((int)CurrentChar >= 48 && (int)CurrentChar <= 57 || cInt == 8) // ตรวจตัวเลข
            {
                return false;
            }
            else
            {
                if ((int)CurrentChar == 46) // ตรวจจุด
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
        }

ไม่มีความคิดเห็น:

แสดงความคิดเห็น