Null reference exception while using try cast on rich text box
I am trying to cast the sender which is menu item to rich text box. but it throws a null reference exception. Can anyone please point me in the direction where am I doing wrong? Thank you.
Here is the code.
Private Sub mnuItemCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuItemCopy.ClickDim c As RichTextBox = TryCast(sender, RichTextBox) If c.SelectedText <> Nothing Then c.Copy() End If