如何解决如何以实用的方式访问工具条也以编程方式定义的点击事件
我在表单编码中定义了工具条和工具条按钮。它的工作正常。我想知道如何访问每个按钮的点击事件。
当我运行表单时,ToolStrip 也会启用。但是当我点击 TooStripButtons 时它没有访问。
变量声明
Dim tsToolStrip As ToolStrip
Dim tsbNew,_
tsbedit,_
tsbDelete,_
tsbSave,_
tsbPrint,_
tsbCancel As ToolStripButton
Dim tssSepe01,_
tssSepe02,_
tssSepe03 As ToolStripSeparator
工具条设置
Sub ToolStripSetup()
' ToolStrip Inizializing
tsToolStrip = New ToolStrip
' ToolStrip Seperators Inizializing
tssSepe01 = New ToolStripSeparator
tssSepe02 = New ToolStripSeparator
tssSepe03 = New ToolStripSeparator
' ToolStrip Buttons Inizializing
tsbNew = New ToolStripButton
tsbedit = New ToolStripButton
tsbDelete = New ToolStripButton
tsbSave = New ToolStripButton
tsbPrint = New ToolStripButton
tsbCancel = New ToolStripButton
With tsbNew
.Name = "tsbNew"
.Image = My.Resources.NewFile_16x
.Text = "&New"
.displayStyle = ToolStripItemdisplayStyle.ImageAndText
.TextimageRelation = TextimageRelation.ImageBeforeText
.Enabled = False
End With
With tsbedit
.Name = "tsbedit"
.Image = My.Resources.Edit_16x
.Text = "&Edit"
.displayStyle = ToolStripItemdisplayStyle.ImageAndText
.TextimageRelation = TextimageRelation.ImageBeforeText
.Enabled = False
End With
With tsbDelete
.Name = "tsbDelete"
.Image = My.Resources.DeleteDatabase_16x
.Text = "&Delete"
.displayStyle = ToolStripItemdisplayStyle.ImageAndText
.TextimageRelation = TextimageRelation.ImageBeforeText
.Enabled = False
End With
With tsbSave
.Name = "tsbSave"
.Image = My.Resources.Save_16x
.Text = "&Save"
.displayStyle = ToolStripItemdisplayStyle.ImageAndText
.TextimageRelation = TextimageRelation.ImageBeforeText
.Enabled = False
End With
With tsbPrint
.Name = "tsbPrint"
.Image = My.Resources.Print_16x
.Text = "&Print"
.displayStyle = ToolStripItemdisplayStyle.ImageAndText
.TextimageRelation = TextimageRelation.ImageBeforeText
.Enabled = False
End With
With tsbCancel
.Name = "tsbCancel"
.Image = My.Resources.action_Cancel_16xLG
.Text = "&Cancel"
.displayStyle = ToolStripItemdisplayStyle.ImageAndText
.TextimageRelation = TextimageRelation.ImageBeforeText
End With
' Adding Buttons To ToolStrip
With tsToolStrip
.Name = "tsToolStrip"
.gripStyle = ToolStripgripStyle.Hidden
.RenderMode = ToolStripRenderMode.System
With .Items
.Add(tsbNew) ' New Button
.Add(tsbedit) ' Edit Button
.Add(tsbDelete) ' Delete Button
.Add(tssSepe01)
.Add(tsbSave) ' Save Button
.Add(tssSepe02)
.Add(tsbPrint) ' Print Button
.Add(tssSepe03)
.Add(tsbCancel) ' Cancel Button
End With
End With
Controls.Add(tsToolStrip)
End Sub
我在上面发布了我的示例代码。任何人都可以帮助我如何做到这一点
解决方法
感谢回答
这就是我完成编码的方式
Dim WithEvents tsbNew,_
tsbEdit,_
tsbDelete,_
tsbSave,_
tsbPrint,_
tsbCancel As ToolStripButton
Private Sub tsbCancel_Click(sender As Object,e As EventArgs) Handles tsbCancel.Click
FormInizalization()
End Sub
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。