Live Chat Icon For mobile
Live Chat Icon

How do I determine which button in a Toolbar is clicked?

Platform: WinForms| Category: Controls

When you click on a button on a Toolbar the click is sent to the Toolbar, so you need to check the ToolBarButtonClickEventArgs’s button property to determine the button on the Toolbar that was clicked.

[C#]
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			//check if toolBarButton1 was clicked
			if (e.Button == toolBarButton1)
			{
				MessageBox.Show('Button 1 clicked');
			}
		}

[VB.NET]
Private  Sub toolBar1_ButtonClick(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs)
			’check if toolBarButton1 was clicked
			If e.Button = toolBarButton1 Then
				MessageBox.Show('Button 1 clicked')
			End If
		End Sub

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.