VB VB 2008 텍스트 박스 엔터키 처리 예제
페이지 정보
작성자
본문
If e.KeyChar = Microsoft.VisualBasic.ChrW(13) Then
If 자재코드조회(txt출고_자재번호.Text, "출고") = False Then
Exit Sub
End If
Call 출고등록()
Exit Sub
End If
End Sub
출처 : 데브피아
댓글목록
오원장님의 댓글

<P>마이크로 소프트사 예제 <BR><BR>다음 예제에서는 TextBox 컨트롤을 만듭니다. keypressed 메서드는 KeyChar 속성을 사용하여 Enter 키를 눌렀는지 여부를 확인합니다. ENTER 키를 눌렀으면 Handled 속성이 true로 설정되어 이벤트가 처리됨을 나타냅니다.</P>
<DIV style="BORDER-BOTTOM: #ff80c2 1px solid; BORDER-LEFT: #ff80c2 1px solid; PADDING-BOTTOM: 5px; BACKGROUND-COLOR: #ffdaed; PADDING-LEFT: 5px; PADDING-RIGHT: 5px; BORDER-TOP: #ff80c2 1px solid; BORDER-RIGHT: #ff80c2 1px solid; PADDING-TOP: 5px"><SPAN style="COLOR: blue">Imports</SPAN> System
<SPAN style="COLOR: blue">Imports</SPAN> System.Windows.Forms<BR><BR><SPAN style="COLOR: blue">Public</SPAN> <SPAN style="COLOR: blue">Class</SPAN> Form1<BR> <SPAN style="COLOR: blue">Inherits</SPAN> Form<BR><BR> <SPAN style="COLOR: blue">Public</SPAN> <SPAN style="COLOR: blue">Sub</SPAN> <SPAN style="COLOR: blue">New</SPAN>()<BR> <SPAN style="COLOR: green">' Create a TextBox control.</SPAN><BR> <SPAN style="COLOR: blue">Dim</SPAN> tb <SPAN style="COLOR: blue">As</SPAN> <SPAN style="COLOR: blue">New</SPAN> TextBox()<BR> <SPAN style="COLOR: blue">Me</SPAN>.Controls.Add(tb)<BR> <SPAN style="COLOR: blue">AddHandler</SPAN> tb.KeyPress, <SPAN style="COLOR: blue">AddressOf</SPAN> keypressed<BR> <SPAN style="COLOR: blue">End</SPAN> <SPAN style="COLOR: blue">Sub</SPAN> <SPAN style="COLOR: green">'New</SPAN><BR><BR> <SPAN style="COLOR: blue">Private</SPAN> <SPAN style="COLOR: blue">Sub</SPAN> keypressed(<SPAN style="COLOR: blue">ByVal</SPAN> o <SPAN style="COLOR: blue">As</SPAN> [<SPAN style="COLOR: blue">Object</SPAN>], <SPAN style="COLOR: blue">ByVal</SPAN> e <SPAN style="COLOR: blue">As</SPAN> KeyPressEventArgs)
<SPAN style="COLOR: green">' The keypressed method uses the KeyChar property to check </SPAN><BR> <SPAN style="COLOR: green">' whether the ENTER key is pressed. </SPAN><BR><BR> <SPAN style="COLOR: green">' If the ENTER key is pressed, the Handled property is set to true, </SPAN><BR> <SPAN style="COLOR: green">' to indicate the event is handled.</SPAN><BR><BR> <SPAN style="COLOR: blue">If</SPAN> e.KeyChar = Microsoft.VisualBasic.ChrW(Keys.<SPAN style="COLOR: blue">Return</SPAN>) <SPAN style="COLOR: blue">Then</SPAN><BR> e.Handled = <SPAN style="COLOR: blue">True</SPAN><BR> <SPAN style="COLOR: blue">End</SPAN> <SPAN style="COLOR: blue">If</SPAN><BR> <SPAN style="COLOR: blue">End</SPAN> <SPAN style="COLOR: blue">Sub</SPAN> <SPAN style="COLOR: green">'keypressed</SPAN><BR><BR> <SPAN style="COLOR: blue">Public</SPAN> <SPAN style="COLOR: blue">Shared</SPAN> <SPAN style="COLOR: blue">Sub</SPAN> Main()<BR> Application.Run(<SPAN style="COLOR: blue">New</SPAN> Form1())<BR> <SPAN style="COLOR: blue">End</SPAN> <SPAN style="COLOR: blue">Sub</SPAN> <SPAN style="COLOR: green">'Main</SPAN><BR><SPAN style="COLOR: blue">End</SPAN> <SPAN style="COLOR: blue">Class</SPAN> <SPAN style="COLOR: green">'Form1</SPAN><BR></DIV>
<P><BR> </P>