1

我收到了标题中所述的错误,并且作为 vb.net 的新用户试图理解它。如果有人能解释解决此错误的正确方法,我将不胜感激,因为我没有足够的经验知道从哪里开始处理此类错误。

如果有帮助,这就是我想要做的。我在列表框中有一个上下文菜单,当我右键单击一个条目时,会显示该单元格中成员的值。消息框显示正确的值,但是当我单击关闭该框时,会出现此错误。非常感谢

Unable to cast object of type 'System.EventArgs' to type 'System.Windows.Forms.ToolStripItemClickedEventArgs'.

这是我认为我应该展示的代码。

Private Sub HideToolStripMenuItem_Click(ByVal sender As Object, ByVal e As ToolStripItemClickedEventArgs) Handles pnlContextMenuStrip1.ItemClicked, HideToolStripMenuItem.Click
        'Get the text of the item that was clicked on.
        Try
            MessageBox.Show(txtCustomerActive.Text)
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

Private Sub ContextMenuStrip1_Opening_1(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles pnlContextMenuStrip1.Opening

    End Sub

更新:我在我的项目中启用了 Stirct On,在对代码进行了一些小的更改后,我留下了这个我认为是指错误的代码。

Error   1   Method 'Private Sub HideToolStripMenuItem_Click(sender As Object, e As System.Windows.Forms.ToolStripItemClickedEventArgs)' cannot handle event 'Public Event Click(sender As Object, e As System.EventArgs)' because they do not have a compatible signature.  C:\Users\domain\Documents\Visual Studio 2010\Projects\Login\btLogin\vb\Form2.vb 153 175 Login
4

1 回答 1

4

-event具有ToolStripItem.Click以下参数:

(object sender, EventArgs e)

ToolStripItemClickedEventArgs继承自System.EventArgs,所以它是隐含的 type EventArgs。孩子具有其父母的所有能力,但反之则不然。

我假设您只需将该签名更改为:

Private Sub HideToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles pnlContextMenuStrip1.ItemClicked, HideToolStripMenuItem.Click

所以只需更改ToolStripItemClickedEventArgsEventArgs.

于 2013-11-07T10:59:34.443 回答