We set three icons for all three buttons and the ToolStrip looks like Figure 8. Figure 8 Next step is to set the button click event handler. It is easy. Just double click or use Events window and set click event handlers for all three buttons. Figure 9 Three button click event handlers look like following where we set Text property of Label. Private Sub ToolStripButton1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles ToolStripButton1.Click ToolStripLabel1.Text = "Button1 is clicked" End Sub Private Sub ToolStripButton2_Click(ByVal sender As System.Object, _ e As System.EventArgs) Handles ToolStripButton2.Click ToolStripLabel1.Text = "Button2 is clicked" End Sub Private Sub ToolStripButton3_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles ToolStripButton3.Click ToolStripLabel1.Text = "Button3 is clicked" End Sub Now if you run the project and click on Buttons, you will see something like Figure 10. Figure 10 How to: Add ToolStrip Items Dynamically Example The following code example demonstrates how to dynamically add items to a ContextMenuStrip control. The example also shows how to reuse the same ContextMenuStrip for three different controls on the form. In the example, an event handler populates the menu item collection. The event handler examines the and properties and adds a ToolStripItem describing the source control. Imports System Imports System.Collections.Generic
We set three icons for all three buttons and the ToolStrip looks like Figure 8. Figure 8 Next step is to set the button click event handler. It is easy. Just double click or use Events window and set click event handlers for all three buttons. Figure 9 Three button click event handlers look like following where we set Text property of Label. Private Sub ToolStripButton1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles ToolStripButton1.Click ToolStripLabel1.Text = "Button1 is clicked" End Sub Private Sub ToolStripButton2_Click(ByVal sender As System.Object, _ e As System.EventArgs) Handles ToolStripButton2.Click ToolStripLabel1.Text = "Button2 is clicked" End Sub Private Sub ToolStripButton3_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles ToolStripButton3.Click ToolStripLabel1.Text = "Button3 is clicked" End Sub Now if you run the project and click on Buttons, you will see something like Figure 10. Figure 10 How to: Add ToolStrip Items Dynamically Example The following code example demonstrates how to dynamically add items to a ContextMenuStrip control. The example also shows how to reuse the same ContextMenuStrip for three different controls on the form. In the example, an event handler populates the menu item collection. The event handler examines the and properties and adds a ToolStripItem describing the source control. Imports System Imports System.Collections.Generic