动态添加CONTEXTMENUstrip的子菜单后,无法响应CLICK
用PublicWithEventsmenuCopyAsContextMenuStripPublicWithEventsmenuReplaceAsContextMenuSt...
用 Public WithEvents menuCopy As ContextMenuStrip
Public WithEvents menuReplace As ContextMenuStrip
Public WithEvents menuChange As ContextMenuStrip
也测试了,用ADDHANDLER后提示错误!
代码如下
Public Class Form1
Dim menuCopy As ToolStripMenuItem
Dim menuReplace As ToolStripMenuItem
Dim menuChange As ToolStripMenuItem
Private Sub ContextMenuStrip1_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
'ContextMenuStrip1 = New ContextMenuStrip
ContextMenuStrip1.Items.Clear()
If ContextMenuStrip1.SourceControl Is textbox1 Then
ContextMenuStrip1.Items.Add("menuCopy")
ContextMenuStrip1.Items.Add("menuReplace")
ElseIf ContextMenuStrip1.SourceControl Is PictureBox1 Then
ContextMenuStrip1.Items.Add("menuChange")
End If
End Sub
END CLASS
请说详细点。
我可以添加成功,但是点击后没反映,不知道怎么响应到添加的子菜单的_click事件 展开
Public WithEvents menuReplace As ContextMenuStrip
Public WithEvents menuChange As ContextMenuStrip
也测试了,用ADDHANDLER后提示错误!
代码如下
Public Class Form1
Dim menuCopy As ToolStripMenuItem
Dim menuReplace As ToolStripMenuItem
Dim menuChange As ToolStripMenuItem
Private Sub ContextMenuStrip1_Opening(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles ContextMenuStrip1.Opening
'ContextMenuStrip1 = New ContextMenuStrip
ContextMenuStrip1.Items.Clear()
If ContextMenuStrip1.SourceControl Is textbox1 Then
ContextMenuStrip1.Items.Add("menuCopy")
ContextMenuStrip1.Items.Add("menuReplace")
ElseIf ContextMenuStrip1.SourceControl Is PictureBox1 Then
ContextMenuStrip1.Items.Add("menuChange")
End If
End Sub
END CLASS
请说详细点。
我可以添加成功,但是点击后没反映,不知道怎么响应到添加的子菜单的_click事件 展开
2个回答
展开全部
t)这个方法是不行的,用下面的这个方法增加你的子菜单
ToolStripItem item = new ToolStripMenuItem("b");
item.Click+=new EventHandler(item_Click);
this.contextMenuStrip1.Items.Add(item);
然后定义一个名为Item_Click的方法,如下
void item_Click(object sender, EventArgs e)
{
//你要做的操作
throw new NotImplementedException();
}
ToolStripItem item = new ToolStripMenuItem("b");
item.Click+=new EventHandler(item_Click);
this.contextMenuStrip1.Items.Add(item);
然后定义一个名为Item_Click的方法,如下
void item_Click(object sender, EventArgs e)
{
//你要做的操作
throw new NotImplementedException();
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
具体操作发放发至你的站内消息了,请注意查收!
又不明白的地方,我们可以相互讨教!
站内消息留了我的邮箱了!
又不明白的地方,我们可以相互讨教!
站内消息留了我的邮箱了!
参考资料: weijiexinling 原创回答
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询