Exemple #1
0
        /// <summary>
        ///     Drag and drop route handler for changes in the keyboard or mouse button state during a drag-and-drop operation
        /// </summary>
        /// <param name="sender">Owener of the route event</param>
        /// <param name="e"> QueryContinueDrag data information.</param>
        private void DragSourceQueryContinueDrag(object sender, QueryContinueDragEventArgs e)
        {
            //whe keystate is non, draop is heppen
            if (e.KeyStates == DragDropKeyStates.None)
            {
                DataObject retrievedData = (DataObject)Clipboard.GetDataObject();

                if (retrievedData.GetDataPresent("DataObjectInformation"))
                {
                    var dr = retrievedData.GetData("DataObjectInformation") as DataObjectInformation;
                    MessageBox.Show(dr.InfoValue);
                }
                //unsubscribe event
                this.QueryContinueDrag -= this.queryhandler;
                e.Handled = true;
                //Unhooking on Mouse Up
                InterceptMouse.UnhookWindowsHookEx(InterceptMouse.m_hookID);

                //notifiy user about drop result
                Task.Run(
                    () =>
                {
                    //Drop hepend outside Instantly app
                    if (InterceptMouse.IsMouseOutsideApp)
                    {
                        MessageBox.Show("Dragged outside app");
                    }
                    else
                    {
                        MessageBox.Show("Dragged inside app");
                    }
                });
            }
        }
Exemple #2
0
        /// <summary>
        ///     Mouse move route event handler
        /// </summary>
        /// <param name="sender">Object that owns route eventt</param>
        /// <param name="e" M>ouse move data information</param>
        private void Window_MouseMove(object sender, MouseEventArgs e)
        {
            //Calculated distance between starting point and the current mouse position.
            var mpos = e.GetPosition(null);
            var diff = this._startPoint - mpos;

            //If the distance between is big enough  start DragDrop
            if (e.LeftButton == MouseButtonState.Pressed &&
                (Math.Abs(diff.X) > SystemParameters.MinimumHorizontalDragDistance ||
                 Math.Abs(diff.Y) > SystemParameters.MinimumVerticalDragDistance))
            {
                //hooking on Mouse Up
                InterceptMouse.m_hookID = InterceptMouse.SetHook(InterceptMouse.m_proc);

                //Attach drag and drop route handler
                this.QueryContinueDrag += this.queryhandler;

                // Create data information to de dropped
                DataObject data = new DataObject();


                // Add a DataObjectInformation object using a custom format name.
                data.SetData("DataObjectInformation",
                             new DataObjectInformation("DataObjectInformation"));


                // place object in clopboard
                Clipboard.SetDataObject(data);
                //begin drag and drop
                DragDrop.DoDragDrop(this.text1, data, DragDropEffects.Move);
            }
        }