2013-07-02 4 views
1

나는 가상의 영숫자 키패드 (Screenshot :)를 만들고 그 코드에 대한 도움이 필요합니다. 이 연습의 전체 목적은 vb.net (visual studio 2010에서)을 사용하여이 응용 프로그램을 만들고 핸드폰처럼 텍스트 상자에 텍스트를 입력하는 것입니다. 이 응용 프로그램은 터치 스크린이있는 컴퓨터에서 실행됩니다. 이 키패드가 다음과 같은 방식으로 작동하도록 코드를 성공적으로 작성할 수있었습니다.vb.net을 사용하여 영숫자 키패드 만들기

1) 사용자가 먼저 입력 할 3 개의 영문자 중 하나와 관련된 번호를 선택하면 EG 사용자는 입력해야 할 경우 1을 선택합니다 A, B 또는 C를 선택합니다. 3 "숫자"버튼 왼쪽에 각 숫자와 관련된 값이있는 상자가 나타납니다.

2) 사용자가 알파벳 중 하나를 선택하면 텍스트 상자에 추가되고 1의 과정이 반복됩니다. 1 개 버튼

코드 샘플 : 따라 값을 채우는 3 개 빈 박스

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click 
    Dim cursorPos As Integer = _SourceControl.SelectionStart 
    If numlock = False Then 
     btnAlpha1.Visible = True 
     btnAlpha1.Text = "A" 
     btnAlpha2.Visible = True 
     btnAlpha2.Text = "B" 
     btnAlpha3.Visible = True 
     btnAlpha3.Text = "C" 
    ElseIf numlock = True Then 
     _sourceForm.ActiveControl = _SourceControl 
     _SourceControl.SelectedText += "1" 
     _SourceControl.Select(cursorPos + 1, 0) 
    End If 

End Sub 

코드 샘플 :

Private Sub btnAlpha3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlpha3.Click 
    Dim cursorPos As Integer = _SourceControl.SelectionStart 
    _sourceForm.ActiveControl = _SourceControl 

    _SourceControl.SelectedText += btnAlpha3.Text 
    _SourceControl.Select(cursorPos + 1, 0) 
End Sub 

Private Sub btnAlpha2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlpha2.Click 
    Dim cursorPos As Integer = _SourceControl.SelectionStart 
    _sourceForm.ActiveControl = _SourceControl 

    _SourceControl.SelectedText += btnAlpha2.Text 
    _SourceControl.Select(cursorPos + 1, 0) 
End Sub 

Private Sub btnAlpha1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAlpha1.Click 
    Dim cursorPos As Integer = _SourceControl.SelectionStart 
    _sourceForm.ActiveControl = _SourceControl 

    _SourceControl.SelectedText += btnAlpha1.Text 
    _SourceControl.Select(cursorPos + 1, 0) 
End Sub 

는하지만이의 지루한 방법의 약간의 것으로 판명 , 확인 수정 텍스트 입력의 매우 지루한 방법 그래서 나는 핸드폰과 비슷한 키패드를 만들고 싶습니다.

나는 단 하나의 버튼 (ABC/1)에 대한 코드 샘플 만 있으면 나머지는 해결할 것이다. 협조 해 주셔서 미리 감사드립니다.

(이것은 윈도우 폼 응용 프로그램)

감사합니다,

카비르 마하.

+0

3 개의 팝업 상자에 대한 코드는 정확히 같으며 ** 전송 매개 변수 **를 캐스팅하는 한 가지 방법으로 통합 될 수 있습니다. 초기 부분에서는 Dictionary()를 사용하여 각 버튼을 팝업의 세 글자와 연결할 수 있습니다. 코드가 길지 않아도됩니다 ... –

답변

0

안녕 얘들 아 :) 먼저 제 질문을 보았고 특히 Idle_Mind에게 제안을 주심 감사합니다. 솔루션을 찾고 필요한 것을 얻을 수있었습니다. 여전히 매우 "버그가 많은"것이 었습니다. 정리해야 할 것이 많았지 만 핵심 개념이 실현되었습니다. 다음과 같이 솔루션의 코드는 (내가 정상적으로 작업 모두를 얻기 후에 정리를하는 것처럼 코드의 주석을 용서하시기 바랍니다)입니다 :

Public Class Form1 
Dim WithEvents intTimer As New System.Timers.Timer 
Dim hitCounter As Integer = 1 
Dim value As String = "" 

Public Sub startTimer() 
    intTimer.Interval = 1500 
    intTimer.Start() 
End Sub 

Public Sub setText_1() 
    If Me.txtInput.InvokeRequired Then 
     Me.txtInput.Invoke(New MethodInvoker(AddressOf setText_1)) 
    Else 
     Dim cursorPos As Integer = txtInput.SelectionStart 
     txtInput.Select(cursorPos + 1, 0) 
     Me.ActiveControl = txtInput 
     hitCounter = 1 
     value = "" 
    End If 
End Sub 

Public Sub timer_Elapsed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles intTimer.Elapsed 
    setText_1() 
    intTimer.Stop() 
End Sub 

Public Sub BtnLoseFocus(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Leave, btn2.Leave, btn3.Leave, btn4.Leave, btn5.Leave, btn6.Leave, btn7.Leave, btn8.Leave, btn9.Leave 
    txtInput.SelectedText += value 
    hitCounter = 1 
End Sub 

Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click 
    If btn1.Focused Then 
     startTimer() 
     If hitCounter <= 3 Then 
      Select Case hitCounter 
       Case 1 
        'txtInput.Text += "A" 
        value = "A" 
       Case 2 
        'txtInput.Text = "B" 
        value = "B" 
       Case 3 
        'txtInput.Text += "C" 
        value = "C" 
       Case Else 
        'txtInput.SelectedText += "1" 
        value = "1" 
      End Select 
      hitCounter += 1 
     End If 
    Else 
     hitCounter = 1 
    End If 
End Sub 

Private Sub btn2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click 
    'hitCounter = 1 
    If btn2.Focused Then 
     startTimer() 
     If hitCounter <= 3 Then 
      Select Case hitCounter 
       Case 1 
        'txtInput.Text += "A" 
        value = "D" 
       Case 2 
        'txtInput.Text = "B" 
        value = "E" 
       Case 3 
        'txtInput.Text += "C" 
        value = "F" 
       Case Else 
        'txtInput.SelectedText += "1" 
        value = "2" 
      End Select 
      hitCounter += 1 
     End If 
    End If 
End Sub 

Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click 
    'hitCounter = 1 
    startTimer() 
    If hitCounter <= 3 Then 
     Select Case hitCounter 
      Case 1 
       'txtInput.Text += "A" 
       value = "G" 
      Case 2 
       'txtInput.Text = "B" 
       value = "H" 
      Case 3 
       'txtInput.Text += "C" 
       value = "I" 
      Case Else 
       'txtInput.SelectedText += "1" 
       value = "3" 
     End Select 
     hitCounter += 1 
    End If 
End Sub 

Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click 
    'hitCounter = 1 
    startTimer() 
    If hitCounter <= 3 Then 
     Select Case hitCounter 
      Case 1 
       'txtInput.Text += "A" 
       value = "J" 
      Case 2 
       'txtInput.Text = "B" 
       value = "K" 
      Case 3 
       'txtInput.Text += "C" 
       value = "L" 
      Case Else 
       'txtInput.SelectedText += "1" 
       value = "4" 
     End Select 
     hitCounter += 1 
    End If 
End Sub 

Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click 
    'hitCounter = 1 
    startTimer() 
    If hitCounter <= 3 Then 
     Select Case hitCounter 
      Case 1 
       'txtInput.Text += "A" 
       value = "M" 
      Case 2 
       'txtInput.Text = "B" 
       value = "N" 
      Case 3 
       'txtInput.Text += "C" 
       value = "O" 
      Case Else 
       'txtInput.SelectedText += "1" 
       value = "5" 
     End Select 
     hitCounter += 1 
    End If 
End Sub 

Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click 
    'hitCounter = 1 
    startTimer() 
    If hitCounter <= 3 Then 
     Select Case hitCounter 
      Case 1 
       'txtInput.Text += "A" 
       value = "P" 
      Case 2 
       'txtInput.Text = "B" 
       value = "Q" 
      Case 3 
       'txtInput.Text += "C" 
       value = "R" 
      Case Else 
       'txtInput.SelectedText += "1" 
       value = "6" 
     End Select 
     hitCounter += 1 
    End If 
End Sub 

Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click 
    'hitCounter = 1 
    startTimer() 
    If hitCounter <= 3 Then 
     Select Case hitCounter 
      Case 1 
       'txtInput.Text += "A" 
       value = "S" 
      Case 2 
       'txtInput.Text = "B" 
       value = "T" 
      Case 3 
       'txtInput.Text += "C" 
       value = "U" 
      Case Else 
       'txtInput.SelectedText += "1" 
       value = "7" 
     End Select 
     hitCounter += 1 
    End If 
End Sub 

Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click 
    'hitCounter = 1 
    startTimer() 
    If hitCounter <= 3 Then 
     Select Case hitCounter 
      Case 1 
       'txtInput.Text += "A" 
       value = "V" 
      Case 2 
       'txtInput.Text = "B" 
       value = "W" 
      Case 3 
       'txtInput.Text += "C" 
       value = "X" 
      Case Else 
       'txtInput.SelectedText += "1" 
       value = "8" 
     End Select 
     hitCounter += 1 
    End If 
End Sub 

Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click 
    'hitCounter = 1 
    startTimer() 
    If hitCounter <= 2 Then 
     Select Case hitCounter 
      Case 1 
       'txtInput.Text += "A" 
       value = "Y" 
      Case 2 
       'txtInput.Text = "B" 
       value = "Z" 
      Case Else 
       'txtInput.SelectedText += "1" 
       value = "9" 
     End Select 
     hitCounter += 1 
    End If 
End Sub 

Private Sub btnBackSpace_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackSpace.Click 
    Dim cursorPos As Integer = txtInput.SelectionStart 
    If txtInput.Text.Length > 0 Then 
     Me.ActiveControl = txtInput 
     txtInput.Text = txtInput.Text.Remove(cursorPos - 1, 1) 
     txtInput.Select(cursorPos - 1, 0) 
    Else 
     'Do nothing 
     Me.ActiveControl = txtInput 
    End If 
End Sub 

Private Sub btn0_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn0.Click 
    'spacebar 
    Dim cursorPos As Integer = txtInput.SelectionStart 
    Me.ActiveControl = txtInput 
    txtInput.SelectedText += " " 
    txtInput.Select(cursorPos + 1, 0) 
End Sub 

최종 클래스

테스트에 사용 된 GUI의 스크린 샷 : https://www.dropbox.com/s/8s26po807v6kkoj/keypad-test%20Interface.png

감사합니다,

카비르.