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.
Unfortunately, activation email could not send to your email. Please try again.

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

 

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:

C#

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);

}

VB

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

Sample:

http://websamples.syncfusion.com/samples/KB/Tools.Windows/TMdown/main.htm

Article ID: Published Date: Last Revised Date: Platform: Control:
1239 04/30/2011 07/10/2014 Windows Forms XPToolbar
Tags:
Did you find this information helpful?
Add Comment
You must log in to leave a comment

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.