Private Sub RichTextView_TextChanged(ByVal sender As Object, ByVal e As
KeyPressEventArgs) Handles RichTextView.KeyPress, RichTextView.TextChanged
Dim c As Char = e.KeyChar
Dim i As Integer = Asc(c)
Dim h As Char = Chr(i)
capitalise_first_letter.Add(h)
End Sub
The above code produces the error: Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.KeyPressEventArgs'. It throws the error at capitalise_first_letter.Add(h) (capitalise_first_letter is a List of String).
Why? Since h is e.KeyChar put through transformations?
This is because you’re also trying to use the same routine to handle
RichTextView.TextChanged, which does not passKeyPressEventArg.You need a separate event handler for the
TextChangedevent if you want to allow this to beKeyPressEventArgs.