We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How do I know which BarItem was clicked on a toolbar using mouse down point ?

Platform: WinForms |
Control: XPToolbar |
Published Date: April 30, 2011 |
Last Revised Date: July 10, 2014


For doing this, first it is necessary to get hold of the BarControlInternal object which is associated with each XPMenus.Bar and then handle the MouseDown event of that particular BarControl to get the BarItem. Please refer the below code snippet which illustrates this:


CommandBarExt cbe1 = mainFrameBarManager1.GetBarControl(bar1) as CommandBarExt;

//Retrieving BarControlInternal object for the BarControl

BarControlInternal bcint = cbe1.BarControl as BarControlInternal;

bcint.MouseDown += new MouseEventHandler(bcint_MouseDown);

void bcint_MouseDown(object sender, MouseEventArgs e)


BarControlInternal bari = sender as BarControlInternal;

//Get the MousePoint related to the BarControlInternal object

Point pt = bari.PointToScreen(new Point(e.X, e.Y));

//Using the MousePoint to retrieve the BarItem

BarItem bitem = bari.HitTest(pt.X, pt.Y) as BarItem;

MessageBox.Show("The Clicked BarItem is:"+"\t"+bitem.Text);



Dim cbe1 As CommandBarExt = CType(IIf(TypeOf mainFrameBarManager1.GetBarControl(bar1) Is CommandBarExt, mainFrameBarManager1.GetBarControl(bar1), Nothing), CommandBarExt)

'Retrieving BarControlInternal object for the BarControl

Dim bcint As BarControlInternal = CType(IIf(TypeOf cbe1.BarControl Is BarControlInternal, cbe1.BarControl, Nothing), BarControlInternal)

AddHandler bcint.MouseDown, AddressOf bcint_MouseDown

Private Sub bcint_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)

Dim bari As BarControlInternal = CType(IIf(TypeOf sender Is BarControlInternal, sender, Nothing), BarControlInternal)

'Get the MousePoint related to the BarControlInternal object

Dim pt As Point = bari.PointToScreen(New Point(e.X, e.Y))

'Using the MousePoint to retrieve the BarItem

Dim bitem As BarItem = CType(IIf(TypeOf bari.HitTest(pt.X, pt.Y) Is BarItem, bari.HitTest(pt.X, pt.Y), Nothing), BarItem)

MessageBox.Show("The Clicked BarItem is:" & Constants.vbTab & bitem.Text)

End Sub



2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon