)
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: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to drag and drop baritems from a WinForms XPToolBar to another XPToolBar?

Platform: WinForms |
Control: XPToolbar |
Published Date: April 30, 2011 |
Last Revised Date: February 7, 2020

Drag and drop baritems

It is possible to drag and drop bar items from a XPToolBar to another XPToolBar using DragDrop and DragEnter events.

C#

private void xpToolBar2_DragEnter(object sender, DragEventArgs e)
{
   Console.WriteLine("XPToolBar Drag Enter");
   if (e.Data.GetDataPresent(typeof(BarItem)))
      e.Effect = DragDropEffects.Copy;
   else
      e.Effect = DragDropEffects.None;
}
private void xpToolBar2_DragDrop(object sender, DragEventArgs e)
{
   Console.WriteLine("XPToolBar Drag Drop");
   if (e.Data.GetDataPresent(typeof(BarItem)))
   {
      BarItem bitem = e.Data.GetData(typeof(BarItem)) as BarItem;
      this.xpToolBar2.Items.Add(bitem);
   }
}
private void XPToolBar_BarControlInternal_MouseDown(object sender, MouseEventArgs e)
{
   if (e.Button == MouseButtons.Left)
   {
      BarControlInternal bcint = sender as BarControlInternal;
      Point pt = bcint.PointToScreen(new Point (e.X,e.Y));
      BarItem bitem = bcint.HitTest(pt.X, pt.Y) as BarItem;
      DoDragDrop(bitem, DragDropEffects.Copy);
   }
}

VB

Private Sub xpToolBar2_DragEnter(ByVal sender As Object, ByVal e As DragEventArgs) Handles xpToolBar2.DragEnter
   Console.WriteLine("XPToolBar Drag Enter")
   If e.Data.GetDataPresent(GetType(BarItem)) Then
      e.Effect = DragDropEffects.Copy
   Else
      e.Effect = DragDropEffects.None
End If
End Sub
Private Sub xpToolBar2_DragDrop(ByVal sender As Object, ByVal e As DragEventArgs) Handles xpToolBar2.DragDrop
   Console.WriteLine("XPToolBar Drag Drop")
   If e.Data.GetDataPresent(GetType(BarItem)) Then
      Dim bitem As BarItem = TryCast(e.Data.GetData(GetType(BarItem)), BarItem)
      Me.xpToolBar2.Items.Add(bitem)
   End If
End Sub
Private Sub XPToolBar_BarControlInternal_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs)
   If e.Button = MouseButtons.Left Then
      Dim bcint As BarControlInternal = TryCast(sender, BarControlInternal)
      Dim pt As Point = bcint.PointToScreen(New Point (e.X,e.Y))
      Dim bitem As BarItem = TryCast(bcint.HitTest(pt.X, pt.Y), BarItem)
      DoDragDrop(bitem, DragDropEffects.Copy)
   End If
End Sub

 

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
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.

Up arrow icon

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

Live Chat Icon For mobile
Live Chat Icon