블로그 이미지
Every unexpected event is a path to learning for you.

카테고리

분류 전체보기 (2737)
Unity3D (817)
Programming (474)
Server (33)
Unreal (4)
Gamebryo (56)
Tip & Tech (228)
협업 (58)
3DS Max (3)
Game (12)
Utility (136)
Etc (96)
Link (32)
Portfolio (19)
Subject (90)
iOS,OSX (53)
Android (14)
Linux (5)
잉여 프로젝트 (2)
게임이야기 (3)
Memories (20)
Interest (38)
Thinking (38)
한글 (30)
PaperCraft (5)
Animation (408)
Wallpaper (2)
재테크 (18)
Exercise (3)
나만의 맛집 (3)
냥이 (10)
육아 (16)
Total
Today
Yesterday
04-19 21:33

'Textbox'에 해당되는 글 2건

  1. 2010.07.22 TextBox에 엔터 이벤트 넣기
  2. 2010.06.25 TextBox에 한글, 영어, 숫자만 입력받기. 1

이 기능은 사실 마우스 이벤트에 관해 검색 하던 중 발견 하게 되었다.

사실 검색기능과 사전 기능은 어느정도 구현 하긴 했으나 텍스트 창에서 엔터키를 쳤을때

검색 기능은 구현 하지 못하고 있었다.

방법은 간단 했다. 먼저  TextBox 이벤트에셔 keydown 이벤트를 추가 시켰다.

그리고 나서

if (e.KeyCode == Keys.Enter)
         Go_click(sender, e);

       

위 2줄 코드만 추가 시키면 끝!!

출처 : http://h0wan.tistory.com/entry/TextBox에-엔터-이벤트-넣기
반응형
Posted by blueasa
, |

텍스트박스에 한글만 입력하기

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    if((Char.IsPunctuation(e.KeyChar) || Char.IsDigit(e.KeyChar) || Char.IsLetter(e.KeyChar) || Char.IsSymbol(e.KeyChar)) && e.KeyChar != 8)
    {
        e.Handled = true;
    }
}

 

텍스트박스에 영어만 입력하기

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    if(!(Char.IsLetter(e.KeyChar)) && e.KeyChar != 8)
    {
        e.Handled = true;
    }
}

 

private void textBox1_Leave(object sender, System.EventArgs e)
{
    Regex emailregex = new Regex(@"[a-zA-Z]");
    Boolean ismatch = emailregex.IsMatch(textBox1.Text);
    if (!ismatch)
    {
        MessageBox.Show("영문자만 입력해 주세요.");
    }
}

 

텍스트박스에 숫자만 입력하기

private void textBox1_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
    if(!(Char.IsDigit(e.KeyChar)) && e.KeyChar != 8)
    {
        e.Handled = true;
    }
}
private void textBox1_Leave(object sender, System.EventArgs e)
{
    Regex emailregex = new Regex(@"[0-9]");
    Boolean ismatch = emailregex.IsMatch(textBox1.Text);
    if (!ismatch)
    {
        MessageBox.Show("숫자만 입력해 주세요.");
    }
}

 

음.. 이렇게 두번에 걸쳐 체크한 이유는 한글은 ProcessKey이기 때문에 KeyPress 이벤트가 일어나지 않기 때문입니다. 그렇기 때문에 텍스트박스에서 포커스가 벗어날때 정규식을 이용해 한번더 체크해줘야 합니다. 키값 8번은 백스페이스 값입니다.

 

자료출처 : C#개발자싸이트

http://www.sky.ph/

 

 

반응형
Posted by blueasa
, |