Advertisement
Guest User

Untitled

a guest
Apr 21st, 2014
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. Private Sub IPAtext_KeyPress(sender As Object, e As KeyEventArgs) Handles IPAtext.KeyDown
  2. Dim AChars() As Char = {"æ", "ɑ"}
  3. Dim Counter As Integer = 0
  4. Select Case e.Modifiers
  5. Case Keys.Control
  6. Select Case e.KeyCode
  7. Case Keys.A
  8. While e.Modifiers = Keys.Control And e.KeyCode = Keys.A
  9. IPAtext.AppendText(AChars(Counter))
  10. '-- Pause for keypress. If keypress =/= A then complete loop, if keypress is A again then increase counter. --
  11. Counter = (Counter + 1) Mod AChars.Count 'Increments the counter so that it cycles back to 0 when it goes past the count of AChars.
  12. '-- Only execute the line below if keypress is A. --
  13. IPAtext.Text = IPAtext.Text.Remove(IPAtext.TextLength - 1) 'Remove the last character from the textbox.
  14. End While
  15. End Select
  16. End Select
  17. End Sub
  18.  
  19. Private Sub RichTextBox1_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
  20. e.SuppressKeyPress = True
  21. e.Handled = True
  22.  
  23. Select Case e.KeyCode
  24. Case Keys.A And e.Modifiers = Keys.Control
  25. RichTextBox1.SelectedText = GetCharacterToPrint(RichTextBox1.SelectedText, New Char() {"æ", "ɑ"})
  26. RichTextBox1.Select(RichTextBox1.SelectionStart - 1, 1)
  27. Case Else
  28. e.Handled = False
  29. e.SuppressKeyPress = False
  30. End Select
  31. End Sub
  32.  
  33. Private Function GetCharacterToPrint(ByVal SelectedText As String, ByVal Characters As Char()) As Char
  34. If SelectedText.Length <> 1 Then
  35. Return Characters(0)
  36. End If
  37. Dim c As Char = SelectedText(0)
  38. Dim index As Integer = String.Join("", Characters).IndexOf(c)
  39. If index = Characters.Length - 1 Then
  40. Return Characters(0)
  41. Else
  42. Return Characters(index + 1)
  43. End If
  44. End Function
  45.  
  46. Private Sub RichTextBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyUp
  47. If e.KeyValue = Keys.ControlKey Then
  48. RichTextBox1.SelectionStart += 1
  49. End If
  50. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement