Wenn nicht kommt:
Dann machen wir so:
1. Mach ein neues Projekt
2. Füg ein Benutzersteuerelement ein.
3. Zieh RichTextBox auf ihn.
4. Und füg diese Code ein:
Dim originalText As String
Dim newText As String
Private Sub checkDictionary()
If Me.RichTextBox1.Text.Length > 0 Then
Dim cPosition As Integer = getCursorPosition()
Me.RichTextBox1.Select(Me.RichTextBox1.Text.Length - 1, 1)
Me.RichTextBox1.Select(cPosition, 0)
Me.RichTextBox1.ScrollToCaret()
'Get the starting point of word in context
Dim i As Integer = cPosition
Dim kair As Char
Do Until i < 1 Or kair = " "
kair = Mid(Me.RichTextBox1.Text, i, 1)
i -= 1
If kair = " " Then 'And (cPosition - i) > 3
i += 2
End If
Loop
Dim startCheck As Integer = i
If startCheck <= 0 Then startCheck = 1
'Get the ending point of word in context
i = startCheck
kair = ""
Do Until i > Me.RichTextBox1.Text.Length Or kair = " "
kair = Mid(Me.RichTextBox1.Text, i, 1)
i += 1
If kair = " " Then
i -= 1
End If
Loop
Dim endCheck As Integer = i - startCheck
Dim wordString As String = removePunctuation(Mid( _
Me.RichTextBox1.Text, startCheck, endCheck))
Me.ParentForm.Text = wordString
End If
End Sub
Private Function getCursorPosition() As Integer
Dim i As Integer = 1
Dim location As Integer = 1
Do Until i = Me.RichTextBox1.Text.Length Or Me.RichTextBox1.Text.Length _
<= 0
If Mid(originalText, i, 1) = Mid(newText, i, 1) Then 'if char is =
' ignore it
location += 1
Else
If Len(newText) < Len(originalText) Then 'otherwise, backup and
' stop, cursor found.
location -= 1
End If
Exit Do
End If
i += 1
Loop
Return location
End Function
Private Function removePunctuation(ByVal someString As String) As String
Dim tempValue As String
tempValue = Replace(someString, ",", "")
tempValue = Replace(tempValue, "!", "")
tempValue = Replace(tempValue, "?", "")
tempValue = Replace(tempValue, ".", "")
tempValue = Replace(tempValue, ":", "")
Return tempValue
End Function
Private Sub RichTextBox1_KeyUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyUp
If e.KeyCode > 36 And e.KeyCode < 41 Then
Exit Sub
End If
newText = Me.RichTextBox1.Text
checkDictionary()
End Sub
Private Sub RichTextBox1_KeyDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.KeyEventArgs) Handles RichTextBox1.KeyDown
If e.KeyCode > 36 And e.KeyCode < 41 Then
Exit Sub
End If
originalText = Me.RichTextBox1.Text
End Sub 5. dann Debugen.
6. Benutzerdefinierte Komponent (UserControl1) auf For1 bringen.
7 Testen. |