/// <summary>
        /// Notifies the DragDropHelper that the current Control received
        /// a Drop event.
        /// </summary>
        /// <param name="dropHelper">The DragDropHelper instance to notify.</param>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void Drop(this IDropTargetHelper dropHelper, System.Windows.Forms.IDataObject data, Point cursorOffset,
                                DragDropEffects effect)
        {
            Win32Point pt = cursorOffset.ToWin32Point();

            dropHelper.Drop((ComIDataObject)data, ref pt, (int)effect);
        }
Esempio n. 2
0
        private void dataGridView1_DragDrop(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
            Point      p = Cursor.Position;
            Win32Point wp;

            wp.x = p.X;
            wp.y = p.Y;
            IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();

            dropHelper.Drop((ComIDataObject)e.Data, ref wp, (int)e.Effect);

            if (e.Data.GetData(DataFormats.FileDrop) is string[] files && files.Any())
            {
                using (var stream = File.Open(files.First(), FileMode.Open, FileAccess.Read))
                {
                    using (var reader = ExcelReaderFactory.CreateReader(stream))
                    {
                        ds = reader.AsDataSet();
                        dataGridView1.DataSource = ds.Tables[0];
                        DisableSorting();
                        lblDrop.Visible = false;
                        SetComponentsEnabled(true);
                        SelectDate();
                    }
                }
            }
        }
Esempio n. 3
0
        protected virtual void OnDrop(DragEventArgs e, FrameworkElement element)
        {
            Win32Point wp;

            System.Windows.Point p = e.GetPosition(element);
            wp.x = (int)p.X;
            wp.y = (int)p.Y;
            _DropTargetHelper.Drop((ComIDataObject)e.Data, ref wp, (int)e.Effects);
        }
    public static void ProcessDragDrop(DragEventArgs e)
    {
        Point        point = Cursor.Position;
        WindowsPoint winpoint;

        winpoint.X = point.X;
        winpoint.Y = point.Y;
        IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();

        dropHelper.Drop((ComIDataObject)e.Data, ref winpoint, (int)e.Effect);
    }
        protected void control_OnDragDrop(object sender, DragEventArgs e)
        {
            e.Effect = DragDropEffects.Copy;
            Point      p = Cursor.Position;
            Win32Point wp;

            wp.x = p.X;
            wp.y = p.Y;
            IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();

            dropHelper.Drop((ComIDataObject)e.Data, ref wp, (int)e.Effect);
        }
Esempio n. 6
0
        protected override void OnDrop(DragEventArgs e)
        {
            Win32Point wp;

            e.Effects = DragDropEffects.Copy;
            Point p = e.GetPosition(this);

            wp.x = (int)p.X;
            wp.y = (int)p.Y;
            IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();

            dropHelper.Drop((ComIDataObject)e.Data, ref wp, (int)e.Effects);
            if (e.Data.GetDataPresent(DataFormats.FileDrop))
            {
                string[] files = e.Data.GetData(DataFormats.FileDrop) as string[];
                this.OpenImage(files[0]);
            }

            System.Windows.IDataObject data = e.Data;
            string[] formats = data.GetFormats();
            if (formats.Contains("text/html"))
            {
                var    obj  = data.GetData("text/html");
                string html = string.Empty;
                if (obj is string)
                {
                    html = (string)obj;
                }
                else if (obj is MemoryStream)
                {
                    MemoryStream ms     = (MemoryStream)obj;
                    byte[]       buffer = new byte[ms.Length];
                    ms.Read(buffer, 0, (int)ms.Length);
                    if (buffer[1] == (byte)0)  // Detecting unicode
                    {
                        html = System.Text.Encoding.Unicode.GetString(buffer);
                    }
                    else
                    {
                        html = System.Text.Encoding.ASCII.GetString(buffer);
                    }
                }
                // Using a regex to parse HTML, but JUST FOR THIS EXAMPLE :-)
                var match = new Regex(@"<img[^>]+src=""([^""]*)""").Match(html);
                if (match.Success)
                {
                    Uri uri = new Uri(match.Groups[1].Value);
                    SetImageFromUri(uri);
                }
            }
        }
        /// <summary>
        /// Notifies the DragDropHelper that the current Control received
        /// a DragOver event.
        /// </summary>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void Drop(IDataObject data, Point cursorOffset, DragDropEffects effect)
        {
            // No need to clear the drop description, but don't keep it stored to avoid memory leaks
            foreach (KeyValuePair <Control, IDataObject> pair in s_dataContext)
            {
                if (ReferenceEquals(pair.Value, data))
                {
                    s_dataContext.Remove(pair);
                    break;
                }
            }

            s_instance.Drop(data, cursorOffset, effect);
        }
        public int DragDrop(IntPtr pDataObj, ShellAPI.MK grfKeyState, ShellAPI.POINT pt, ref DragDropEffects pdwEffect)
        {
            OnDrop(new DropEventArgs(mouseButtons, br.FileView));

            if (!((mouseButtons & ShellAPI.MK.RBUTTON) != 0 ||
                  grfKeyState == ShellAPI.MK.CONTROL ||
                  grfKeyState == ShellAPI.MK.ALT ||
                  grfKeyState == (ShellAPI.MK.CONTROL | ShellAPI.MK.SHIFT)) && ShellItem.Equals(parentDragItem, parentDropItem))
            {
                ResetDrop();
                ReleaseCom();
                pdwEffect = DragDropEffects.None;

                if (dropHelper != null)
                {
                    dropHelper.Drop(pDataObj, ref pt, pdwEffect);
                }

                return(ShellAPI.S_OK);
            }

            ResetDrop();
            if (dropTarget != null)
            {
                dropTarget.DragDrop(pDataObj, grfKeyState, pt, ref pdwEffect);

                ReleaseCom();
                dropDataObject = IntPtr.Zero;
            }

            if (dropHelper != null)
            {
                dropHelper.Drop(pDataObj, ref pt, pdwEffect);
            }

            return(ShellAPI.S_OK);
        }
        protected override void OnDrop(DragEventArgs e)
        {
            e.Effects = DragDropEffects.Copy;

            System.Windows.Point p = e.GetPosition(this);

            Win32Point pt;

            pt.x = (int)p.X;
            pt.y = (int)p.Y;

            IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();

            dropHelper.Drop((ComIDataObject)e.Data, ref pt, (int)e.Effects);
        }
Esempio n. 10
0
        /// <summary>
        /// Notifies the DragDropHelper that the current Control received
        /// a DragOver event.
        /// </summary>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void Drop(IDataObject data, System.Drawing.Point cursorOffset, DragDropEffects effect)
        {
            // No need to clear the drop description, but don't keep it stored to avoid memory leaks
            foreach (KeyValuePair <Control, IDataObject> pair in s_dataContext)
            {
                if (object.ReferenceEquals(pair.Value, data))
                {
                    s_dataContext.Remove(pair);
                    break;
                }
            }

            Win32Point pt = SwfDragDropLibExtensions.ToWin32Point(cursorOffset);

            s_instance.Drop((ComIDataObject)data, ref pt, (int)effect);
        }
Esempio n. 11
0
        private void ClipsDragDrop(object sender, DragEventArgs e)
        {
            if (e.Data.GetDataPresent(DataFormats.StringFormat))
            {
                if (!fMainForm.fFromClips && !fMainForm.fFromFavorites && !fMainForm.fFromMFU)
                {
                    ClipItem Clip = new ClipItem((string)(e.Data.GetData(DataFormats.Text)), true);
                    // add the selected string to bottom of list
                    fClips.Add(Clip);
                    Items.Add(e.Data.GetData(DataFormats.Text));
                }

                if (fMainForm.fFromFavorites)
                {
                    int IndexItem = fMainForm.fIndexToDragFromFavorites;
                    if (IndexItem >= 0 && IndexItem < fMainForm.listBoxFavorites.Items.Count)
                    {
                        int Index = 0;
                        try
                        {
                            Index = int.Parse((string)e.Data.GetData(DataFormats.Text));
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Erreur de parsing");
                        }

                        ClipItem Clip = fMainForm.listBoxFavorites.fFavorites[Index];
                        fClips.Add(Clip);
                        Items.Add(fClips.Count.ToString());
                    }
                    fMainForm.fFromFavorites = false;
                }

                //Refresh
                Refresh();
            }

#if ADVANCED_DRAG_AND_DROP
            Point      p = Cursor.Position;
            Win32Point wp;
            wp.x = p.X;
            wp.y = p.Y;
            IDropTargetHelper dropHelper = (IDropTargetHelper) new DragDropHelper();
            dropHelper.Drop((ComIDataObject)e.Data, ref wp, (int)e.Effect);
#endif
        }
Esempio n. 12
0
        public void Drag_Drop(DragEventArgs e)
        {
            FlashWindow.Stop(Main.Current);

            try
            {
                Point      _p = Cursor.Position;
                Win32Point _wp;
                _wp.x = _p.X;
                _wp.y = _p.Y;
                IDropTargetHelper _dropHelper = (IDropTargetHelper) new DragDropHelper();
                _dropHelper.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref _wp, (int)e.Effect);
            }
            catch
            {
            }

            DoDataPaste(e.Data);
        }
Esempio n. 13
0
        /// <summary>
        /// Notifies the DragDropHelper that the current Control received
        /// a Drop event.
        /// </summary>
        /// <param name="dropHelper">The DragDropHelper instance to notify.</param>
        /// <param name="data">The DataObject containing a drag image.</param>
        /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
        /// <param name="effect">The accepted drag drop effect.</param>
        public static void Drop(this IDropTargetHelper dropHelper, IDataObject data, Point cursorOffset, DragDropEffects effect)
        {
            Win32Point pt = SwfDragDropLibExtensions.ToWin32Point(cursorOffset);

            dropHelper.Drop((ComIDataObject)data, ref pt, (int)effect);
        }
 /// <summary>
 /// Notifies the DragDropHelper that the current Window received
 /// a DragOver event.
 /// </summary>
 /// <param name="data">The DataObject containing a drag image.</param>
 /// <param name="cursorOffset">The current cursor's offset relative to the window.</param>
 /// <param name="effect">The accepted drag drop effect.</param>
 public static void Drop(IDataObject data, Point cursorOffset, DragDropEffects effect)
 {
     SInstance.Drop(data, cursorOffset, effect);
 }