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

上記のコードはエラーを生成します:Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.KeyPressEventArgs'. エラーをスローしますcapitalise_first_letter.Add(h)(capitalise_first_letter は文字列のリストです)。

なんで?h は e.KeyChar であるため、変換が行われますか?

4

1 に答える 1

3

これは、同じルーチンを使用して を処理しようとしているがRichTextView.TextChanged、 を渡さないためKeyPressEventArgです。

TextChangedこれを許可する場合は、イベント用に別のイベント ハンドラーが必要ですKeyPressEventArgs

于 2012-06-11T17:25:39.660 に答える