1
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

上面的代码产生错误:它在(capitalise_first_letter 是一个字符串列表)Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.KeyPressEventArgs'. 抛出错误。capitalise_first_letter.Add(h)

为什么?既然 h 是 e.KeyChar 进行了转换?

4

1 回答 1

3

这是因为您还尝试使用相同的例程来处理RichTextView.TextChanged,但没有通过KeyPressEventArg

TextChanged如果你想允许它,你需要一个单独的事件处理程序KeyPressEventArgs

于 2012-06-11T17:25:39.660 回答