vb.net 动态菜单click事件先要新建一个index为0vb.net动态添加事件的菜单(设置为不可见)vb.net动态添加事件,然后把动态生产的菜单加入进来,这样就可以使用遍历菜单的方法,并判读下当前按下的菜单名称 。
参看vb.net动态添加事件:网页链接
vb.net 动态菜单如何在指定位置添加新项,并添加单击事件?常见事件有鼠的标单击、双击、移动;
有键盘的键按下、键松开、按键;
有窗体加载、窗体卸载等等 。
怎样指定一个动态增加按钮的事件(vb.net)''' summary
''' 添加多个按钮到一个容器中.
''' /summary
''' param name="StartPos"所有按钮开始点./param
''' param name="ButtonSize"按钮vb.net动态添加事件的大小./param
''' param name="ButtonSpace"按钮vb.net动态添加事件的间距/param
''' param name="ButtonCount"按钮vb.net动态添加事件的总数/param
''' param name="AddingContainer"被添加到vb.net动态添加事件的容器/param
''' remarks/remarks
Private Sub AddButtons(ByVal StartPos As Point, ByVal ButtonSize As Size, _
ByVal ButtonSpace As Size, ByVal ButtonCount As Integer, _
ByVal AddingContainer As Control)
Dim mBtnPos As Point = StartPos
For ItemTemp As Integer = 0 To ButtonCount - 1
Dim NewButton As Button = New Button() With
mBtnPos.Y= ButtonSpace.HeightButtonSize.Height
If mBtnPos.YAddingContainer.Height Then
mBtnPos.Y = StartPos.Y
mBtnPos.X= ButtonSpace.WidthButtonSize.Width
End If
NewButton.Text = String.Format(":", CStr(ItemTemp1))
AddHandler NewButton.Click, AddressOf btnzh_Click
AddingContainer.Controls.Add(NewButton)
Next
End Sub
Private Sub btnzh_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnzh.Click
Dim ItemCount As Integer = 0
Try
ItemCount = CInt(txtChoice.Text)
Catch ex As Exception
MessageBox.Show("您输入的数字无法解析为数字.")
Return
End Try
AddButtons(New Point(2, 2), New Size(60, 40), New Size(20, 30), ItemCount, Me)
End Sub
Private Sub btnzh_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
如何在 vb.net 为动态生成的控件添加事件并传递数据'把图片的声明放在外面,类里面过程外面,而且要用As,不然等会儿没法用
Dim myPicture As New System.Windows.Forms.PictureBox()
'动态生成的控件,加一行
Private Sub UserControl1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.Panel3.Controls.Add(myPicture)
myPicture.Size =New System.Drawing.Size(115, 160)
myPicture.TabStop =False
myPicture.Name ="p"
myPicture.Cursor = Cursors.Hand
AddHandler myPicture.Click, AddressOf mypic_Click '添加事件
AddHandler returnid, AddressOf idReturned '绑定事件和过程
End Sub
'再来个事件,放在声明的地方,就是类里面、过程外面
Private Event returnid(ByVal id As String) '这个事件可以传递值哦~
'普通的单击事件
Private Sub mypic_Click()
RaiseEvent returnid(myPicture.Name)
End Sub
'会传值的事件过程
Private Sub idReturned(ByVal id As String)
Dim bookInfo As New BookInfo
bookInfo.Show()
Me.Parent.Enabled = False
'用id变量做点什么吧
End Sub
如果要改事件的签名(参数一类的)的话,得重写控件 。你可以这样自己弄一个事件 。
vb.net动态菜单,如何添加事件?动态生成的控件:
Private Sub UserControl1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Dim myPicture = New System.Windows.Forms.PictureBox()
Me.Panel3.Controls.Add(myPicture)
myPicture.Size = New System.Drawing.Size(115, 160)
myPicture.TabStop = False
myPicture.Name = "p"
myPicture.Cursor = Cursors.Hand
AddHandler myPicture.Click, AddressOf mypic_Click '添加事件
End Sub
处理事件的过程:
Private Sub mypic_Click() 'ByVal id As String
Dim bookInfo As New BookInfo
bookInfo.Show()
Me.Parent.Enabled = False
【关于vb.net动态添加事件的信息】vb.net动态添加事件的介绍就聊到这里吧 , 感谢你花时间阅读本站内容,更多关于、vb.net动态添加事件的信息别忘了在本站进行查找喔 。
推荐阅读
- c语言推箱子地图代码,c语言推箱子设计报告总结
- 电脑如何截图到ppt,电脑如何截图到微信聊天记录
- 明星的手机密保都是什么,明星的手机号码怎么保密
- c语言程序设计函数素数 c语言写素数的函数
- 海北企业erp管理系统,海北公司董事长是谁
- redis随时间递减,redis 时序
- 用linux命令压缩文件 linux 命令压缩
- 两个路由器两个wife怎么弄,两个路由器两个wifi怎么设置
- 益智休闲小游戏app安卓,益智休闲游戏大全排名