public void Start_DropWatch(Control control)
        {
            String sPath = System.IO.Path.GetTempFileName() + ".DROPTARGET";

            using (StreamWriter sw = new StreamWriter(sPath))
                sw.WriteLine("Placeholder");


            StringCollection s = new StringCollection();

            s.Add(sPath);

            //DropReady = false;
            Fsw      = new FileSystemWatcher();
            Fsw.Path = "C:\\";
            Fsw.IncludeSubdirectories = true;
            Fsw.NotifyFilter          = NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.FileName | NotifyFilters.DirectoryName;
            Fsw.Filter              = "*.DROPTARGET";
            Fsw.Created            += Fsw_Created;
            Fsw.EnableRaisingEvents = true;

            // This will copy the dummy file to the destination folder. This way,
            // Once the operation finishes, we'll get the destination dir through
            // the FileSystemWatcher's event.
            DataObject obj = new DataObject(DataFormats.FileDrop, s);

            //obj.SetFileDropList(s);
            control.DoDragDrop(obj, DragDropEffects.Copy);

            // while (!DropReady)
            //      Thread.Sleep(1);

            // All good, we can do our drag operation stuff here (write
            // files to DropDir or something like that).
        }
Example #2
0
        /// <summary>
        /// Start a drag&amp;drop event for the given sord.
        /// </summary>
        /// <param name="ctrl">Control object</param>
        /// <param name="sords">Sord object</param>
        /// <param name="item">Draged control item</param>
        /// <param name="e">Effect</param>
        /// <returns>True, if a drag&amp;drop is started.</returns>
        public virtual bool DoDragDrop(Control ctrl, IEnumerable <FWSord> sords, object item, DragDropEffects e)
        {
            List <String> fileNames = new List <String>();

            if (sords != null)
            {
                // ... get the files
                using (new Hourglass())
                {
                    foreach (FWSord sord in sords)
                    {
                        if ((sord != null) && (sord is FWDocument))
                        {
                            String fname = ((FWDocument)sord).File;
                            fileNames.Add(fname);
                        }
                    }
                }
            }

            if (fileNames.Count != 0)
            {
                // put the file into a System.Windows.Forms.DataObject
                DataObject dataObject = new DataObject();
                dataObject.SetData(DataFormats.FileDrop, fileNames.ToArray());
                dataObject.SetData(item);

                // start Drag&Drop
                ctrl.DoDragDrop(dataObject, DragDropEffects.Copy);
            }

            return(fileNames.Count != 0);
        }
Example #3
0
 private void textBox_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         DragDropEffects RetEffects = StaticLinkedGUIField.DoDragDrop(this, DragDropEffects.Link);
     }
 }
        public bool ProcessDnD(Control control, object eventSender)
        {
            bool ret = false;

            _currentProceededDragSource.HandleDragStart(eventSender, _lastCreatedDragSourceEventArgs);
            _currentProceededDragSource.HandleDragSetData(eventSender, _lastCreatedDragSourceEventArgs);

            control.GiveFeedback      += HandleGiveFeedback;
            control.QueryContinueDrag += HandleQueryContinueDrag;
            try {
                DragDropEffects effect = control.DoDragDrop(
                    _lastCreatedDragSourceEventArgs.DataObject,
                    _currentProceededDragSource.AllowedEffects
                    );
                _lastCreatedDragSourceEventArgs.Effects = effect;
                ret = effect != DragDropEffects.None;
            } finally {
                control.GiveFeedback      -= HandleGiveFeedback;
                control.QueryContinueDrag -= HandleQueryContinueDrag;
            }
            _currentProceededDragSource.HandleDragFinish(eventSender, _lastCreatedDragSourceEventArgs);

            ClearDnDState();

            return(ret);
        }
Example #5
0
        public static void DoDragAndDrop(Control dragSource, IEnumerable <DragFileInfo> files)
        {
            var dataObject      = new DataObjectEx();
            var fileDescriptors = new List <FileDescriptor>();
            var i = 0;

            foreach (var file in files)
            {
                dataObject.SetFileContents(file.Stream, i);
                fileDescriptors.Add(new FileDescriptor
                {
                    cFileName     = file.FileName,
                    nFileSizeHigh = (uint)(file.Stream.Length >> 32),
                    nFileSizeLow  = (uint)(file.Stream.Length & 0xFFFFFFFF),
                    dwFlags       = FileDescriptorFlags.FileSize | FileDescriptorFlags.ProgressUi
                });
                ++i;
            }

            var fileGroupDescriptor = new FileGroupDescriptor(fileDescriptors.Count);
            var descriptorSize      = Marshal.SizeOf(fileGroupDescriptor) +
                                      Marshal.SizeOf <FileDescriptor>() * fileDescriptors.Count;

            using (var descriptorStream = new MemoryStream(descriptorSize))
            {
                StructToArray(fileGroupDescriptor, descriptorStream);
                foreach (var descriptor in fileDescriptors)
                {
                    StructToArray(descriptor, descriptorStream);
                }
                dataObject.SetData("FileGroupDescriptorW", descriptorStream);

                dragSource.DoDragDrop(dataObject, DragDropEffects.Copy);
            }
        }
Example #6
0
 void DoDragDrop(Control control, DataObject data)
 {
     if (useDragImage.Checked == true)
     {
         var bmp = new Bitmap(100, 100, PixelFormat.Format32bppRgba);
         using (var g = new Graphics(bmp))
         {
             g.FillEllipse(Brushes.Blue, 0, 0, 100, 100);
         }
         control.DoDragDrop(data, allowedEffectDropDown.SelectedValue, bmp, imageOffset.Value);
     }
     else
     {
         control.DoDragDrop(data, allowedEffectDropDown.SelectedValue);
     }
 }
Example #7
0
        private void OnMouseMove(object sender, MouseEventArgs args)
        {
            if (!_leftMouseDown)
            {
                return;
            }
            if (_isAttached)
            {
                return;
            }
            if (_path == null)
            {
                return;
            }
            if (Math.Abs(args.X - _startPos.X) < Threshold &&
                Math.Abs(args.Y - _startPos.Y) < Threshold)
            {
                return;
            }

            var paths = new StringCollection {
                _path
            };
            var dataObject = new DataObject();

            dataObject.SetFileDropList(paths);
            dataObject.SetText(_path);

            // Allow other classes to check if the DragDrop event was generated by this class
            dataObject.SetData(typeof(Format), new Format());

            _dragSource.DoDragDrop(dataObject, DragDropEffects.Copy);

            _isAttached = true;
        }
Example #8
0
 private void OnMouseMove(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         Control control = sender as Control;
         control.DoDragDrop(control, DragDropEffects.Move);
     }
 }
Example #9
0
        private void startDrag_MouseDown(object sender, MouseEventArgs e)
        {
            Control c = (Control)sender;

            c.Select();
            var imageName = (string)c.Tag;

            if (!string.IsNullOrEmpty(imageName))
            {
                c.DoDragDrop(imageName, DragDropEffects.Copy);
            }
            imageName = (string)previewPanel.Tag;
            if (!string.IsNullOrEmpty(imageName))
            {
                c.DoDragDrop(imageName, DragDropEffects.Copy);
            }
        }
Example #10
0
        /// <summary>
        /// The DragBlockMouseDown function starts a dragdrop operation when mouse down
        /// reference: Microsoft tutorial about drag drop
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DragBlockMouseDown(object sender, MouseEventArgs e)
        {
            Control control = sender as Control;

            moveBtn = control;
            blockMoveTimer.Enabled = true;
            control.DoDragDrop(control, DragDropEffects.Move);
            blockMoveTimer.Enabled = false;
        }
Example #11
0
        public DragAndDropDelegate(Control dragSourceControl, DataObject dataObject, DragDropEffects allowedEffects)
        {
            this.dragSourceControl = dragSourceControl;
            this.dataObject        = dataObject;

            queryContinueDragEventHandler        = new QueryContinueDragEventHandler(HandleQueryContinueDrag);
            dragSourceControl.QueryContinueDrag += queryContinueDragEventHandler;
            dragSourceControl.DoDragDrop(dataObject, allowedEffects);
        }
        //private System.Collections.IEnumerator WalkSquare(MessageBox dialog)
        //{
        //    yield return dialog.Animation.Position(new Point(10, 10), 1000);
        //    yield return dialog.Animation.Position(new Point(1000, 10), 1000);
        //    yield return dialog.Animation.Position(new Point(1000, 600), 1000);
        //    yield return dialog.Animation.Position(new Point(10, 600), 1000);
        //}

        private void label1_OnMouseDown(Control sender, MouseEventArgs args)
        {
            var btn = new Button();

            btn.Size     = new Point(157, 26);
            btn.Text     = "drag me";
            btn.Position = sender.Location;
            sender.DoDragDrop(btn);
        }
Example #13
0
 /// <summary>
 /// Start drag & drop operation on the currently selected html segment.
 /// </summary>
 /// <param name="control">the control to start the drag & drop on</param>
 private void StartDragDrop(Control control)
 {
     if (_dragDropData == null)
     {
         var html      = DomUtils.GenerateHtml(_root, HtmlGenerationStyle.Inline, true);
         var plainText = DomUtils.GetSelectedPlainText(_root);
         _dragDropData = HtmlClipboardUtils.GetDataObject(html, plainText);
     }
     control.DoDragDrop(_dragDropData, DragDropEffects.Copy);
 }
        private void entityMouseDown(object sender, MouseEventArgs e)
        {
            Control ctrl = (Control)sender;

            if (ctrl != null)
            {
                this.pbxMap.AllowDrop = true;
                ctrl.DoDragDrop(ctrl.Name, DragDropEffects.Copy | DragDropEffects.Move);
            }
        }
Example #15
0
 private void c_MouseDown(object sender, MouseEventArgs e)
 {
     if (uredi)
     {
         if (e.Button == MouseButtons.Left && e.Clicks == 1)
         {
             Control c = sender as Control;
             c.DoDragDrop(c, DragDropEffects.Move);
         }
     }
 }
Example #16
0
 private void Control_MouseDown(object sender, MouseEventArgs e)
 {
     if (e.Button == MouseButtons.Left)
     {
         Control source = (sender as Control);
         if (source != null)
         {
             DataObject data = new DataObject(DataFormatName, source);
             source.DoDragDrop(data, DragDropEffects.Move);
         }
     }
 }
Example #17
0
        private void resPic_MouseDown(object sender, MouseEventArgs e)
        {
            dragging  = true;
            dragPoint = new Point(e.X, e.Y);

            if (sender is PictureBox)
            {
                J = (int)(((PictureBox)sender).Tag);
            }
            Control c = sender as Control;

            c.DoDragDrop(c, DragDropEffects.Move);
        }
Example #18
0
        private void DragImage(Control ctrl)
        {
            if (ctrl.BackgroundImage != null)
            {
                string tmpImageName = GetBmpFileTempName();
                ctrl.BackgroundImage.Save(tmpImageName);

                StringCollection filePaths = new StringCollection();
                filePaths.Add(tmpImageName);

                DataObject data = new DataObject();
                data.SetFileDropList(filePaths);

                ctrl.DoDragDrop(data, DragDropEffects.Copy);
            }
        }
Example #19
0
        public static DragDropEffects DoDragDrop(string path, Control control)
        {
            DragDropEffects none;

            if ((path == null) || (path.Length == 0))
            {
                return(DragDropEffects.None);
            }
            IShellFolder ppv  = null;
            object       obj2 = null;
            IntPtr       zero = IntPtr.Zero;

            try {
                IntPtr ptr2;
                zero = PInvoke.ILCreateFromPath(path);
                if (((zero == IntPtr.Zero) || (PInvoke.SHBindToParent(zero, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr2) != 0)) || (ppv == null))
                {
                    return(DragDropEffects.None);
                }
                IntPtr[] apidl       = new IntPtr[] { ptr2 };
                uint     rgfReserved = 0;
                Guid     riid        = ExplorerGUIDs.IID_IDataObject;
                ppv.GetUIObjectOf(IntPtr.Zero, (uint)apidl.Length, apidl, ref riid, ref rgfReserved, out obj2);
                if (obj2 != null)
                {
                    return(control.DoDragDrop(obj2, DragDropEffects.Link | DragDropEffects.Move | DragDropEffects.Copy));
                }
                none = DragDropEffects.None;
            }
            finally {
                if (obj2 != null)
                {
                    Marshal.ReleaseComObject(obj2);
                    obj2 = null;
                }
                if (ppv != null)
                {
                    Marshal.ReleaseComObject(ppv);
                    ppv = null;
                }
                if (zero != IntPtr.Zero)
                {
                    PInvoke.CoTaskMemFree(zero);
                }
            }
            return(none);
        }
Example #20
0
        private void BeginDragging(object sender)
        {
            dragging = true;
            DragDropInternal data = new DragDropInternal();

            if (OnDataRequest != null)
            {
                System.Drawing.Point point = new System.Drawing.Point(mouseX, mouseY);
                //point = ((Control)sender).PointToClient(point);
                OnDataRequest(sender, new DataRequestArgs(data, point.X, point.Y));
            }

            if (!data.isEmpty())
            {
                m_parent.DoDragDrop(data,
                                    DragDropEffects.All | DragDropEffects.Link | DragDropEffects.Copy | DragDropEffects.Scroll);
            }
        }
Example #21
0
        /// <summary>
        /// Performs a default drag and drop operation for the specified drag source.
        /// </summary>
        /// <param name="control">The drag source Control.</param>
        /// <param name="dataObject">The data object associated to the drag and drop operation.</param>
        /// <param name="allowedEffects">The allowed drop effects.</param>
        /// <param name="data">The associated data.</param>
        /// <returns>The accepted drop effects from the completed operation.</returns>
        private static DragDropEffects DoDragDropInternal(Control control, IDataObject dataObject,
                                                          DragDropEffects allowedEffects, KeyValuePair <string, object>[] data)
        {
            // Set the data onto the data object.
            if (data != null)
            {
                foreach (var dataPair in data)
                {
                    dataObject.SetDataEx(dataPair.Key, dataPair.Value);
                }
            }

            try {
                return(control.DoDragDrop(dataObject, allowedEffects));
            }
            finally {
                UnregisterDefaultDragSource(control);
            }
        }
Example #22
0
        private void ThumbnailControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (!m_dragging && e.Button == MouseButtons.Left)
            {
                Size dragSize = SystemInformation.DragSize;
                if (Math.Abs(m_hitPoint.X - e.X) >= dragSize.Width ||
                    Math.Abs(m_hitPoint.Y - e.Y) >= dragSize.Height)
                {
                    m_dragging = true;
                }
            }

            if (m_dragging)
            {
                Uri hitItem = GetClickedItemUri(m_hitPoint);
                if (hitItem != null)
                {
                    List <string> paths = new List <string>();

                    foreach (Uri uri in GetSelectedItemUris())
                    {
                        paths.Add(uri.LocalPath);
                    }

                    if (paths.Count > 0)
                    {
                        CustomListView listvew = sender as CustomListView;
                        if (listvew != null)
                        {
                            listvew.MouseUpEventDisabled = true;
                        }

                        Control ctrl = (Control)sender;
                        // Create the DataObject and fill it with an array of paths
                        // of the clicked and/or selected objects
                        IDataObject dataObject = new DataObject();
                        dataObject.SetData(DataFormats.FileDrop, true, paths.ToArray());
                        ctrl.DoDragDrop(dataObject, DragDropEffects.Move);
                    }
                }
            }
        }
        void picBoxChampion_MouseMove(object sender, MouseEventArgs e)
        {
            if (pressed)
            {
                newMouseDelta = e.Location;

                diffX = (oldMouseDelta.X - newMouseDelta.X);
                diffY = (newMouseDelta.Y - oldMouseDelta.Y);

                if (Math.Abs(diffY) > 10 || Math.Abs(diffX) > 10)
                {
                    oldMouseDelta = Point.Empty;
                    pressed       = false;
                    Control control = sender as Control;

                    frm1.championsTab.dragger.StartDragging(picBoxChampion);
                    control.DoDragDrop("CHAMPION" + champ.Value.Id.ToString(), DragDropEffects.Copy | DragDropEffects.Move);
                    frm1.championsTab.dragger.StopDragging();
                }
            }
        }
Example #24
0
        private void thumbnailControl_MouseMove(object sender, MouseEventArgs e)
        {
            if (!m_dragging && e.Button == MouseButtons.Left)
            {
                Size dragSize = SystemInformation.DragSize;
                if (Math.Abs(m_hitPoint.X - e.X) >= dragSize.Width ||
                    Math.Abs(m_hitPoint.Y - e.Y) >= dragSize.Height)
                {
                    m_dragging = true;

                    // Get a list of the paths of:
                    // the item we've clicked on with the mouse
                    // and all selected items in the current view
                    // while making sure that the clicked item is not included twice
                    List <string> paths      = new List <string>();
                    Uri           clickedUri = GetClickedItemUri(ActiveItemControl, new Point(e.X, e.Y));
                    if (clickedUri != null && clickedUri.IsAbsoluteUri)
                    {
                        paths.Add(clickedUri.LocalPath);
                    }
                    foreach (Uri uri in GetSelectedItemUris(ActiveItemControl))
                    {
                        if (uri != clickedUri && uri.IsAbsoluteUri)
                        {
                            paths.Add(uri.LocalPath);
                        }
                    }

                    if (paths.Count > 0)
                    {
                        // Create the DataObject and fill it with an array of paths
                        // of the clicked and/or selected objects
                        IDataObject dataObject = new DataObject();
                        dataObject.SetData(DataFormats.FileDrop, true, paths.ToArray());
                        ActiveItemControl.DoDragDrop(dataObject, DragDropEffects.Move);
                    }
                }
            }
        }
Example #25
0
 public override void DoDragDropCopy(object dragDropData)
 {
     _control.DoDragDrop((DataObject)dragDropData, DragEffects.Copy);
 }
        public bool DoBeginDrag(object[] components, SelectionRules rules, int initialX, int initialY)
        {
            // if we're in a sizing operation, or the mouse isn't down, don't do this!
            if ((rules & SelectionRules.AllSizeable) != SelectionRules.None || Control.MouseButtons == MouseButtons.None)
            {
                return(true);
            }

            Control c = client.GetDesignerControl();

            localDrag       = true;
            localDragInside = false;

            dragComps       = components;
            dragBase        = new Point(initialX, initialY);
            localDragOffset = Point.Empty;
            c.PointToClient(new Point(initialX, initialY));

            DragDropEffects allowedEffects = DragDropEffects.Copy | DragDropEffects.None | DragDropEffects.Move;

            // check to see if any of the components are inherhited. if so, don't allow them to be moved.
            // We replace DragDropEffects.Move with a local bit called AllowLocalMoveOnly which means it
            // can be moved around on the current dropsource/target, but not to another target.  Since only
            // we understand this bit, other drop targets will not allow the move to occur
            //
            for (int i = 0; i < components.Length; i++)
            {
                InheritanceAttribute attr = (InheritanceAttribute)TypeDescriptor.GetAttributes(components[i])[typeof(InheritanceAttribute)];

                if (!attr.Equals(InheritanceAttribute.NotInherited) && !attr.Equals(InheritanceAttribute.InheritedReadOnly))
                {
                    allowedEffects &= ~DragDropEffects.Move;
                    allowedEffects |= (DragDropEffects)AllowLocalMoveOnly;
                }
            }

            DataObject data = new ComponentDataObjectWrapper(new ComponentDataObject(client, serviceProvider, components, initialX, initialY));

            // We make sure we're painted before we start the drag.  Then, we disable window painting to
            // ensure that the drag can proceed without leaving artifacts lying around.  We should be caling LockWindowUpdate,
            // but that causes a horrible flashing because GDI+ uses direct draw.
            //
            User32.MSG msg = default;
            while (User32.PeekMessageW(ref msg, IntPtr.Zero, User32.WM.PAINT, User32.WM.PAINT, User32.PM.REMOVE).IsTrue())
            {
                User32.TranslateMessage(ref msg);
                User32.DispatchMessageW(ref msg);
            }

            // don't do any new painting...
            bool oldFreezePainting = freezePainting;

            // asurt 90345 -- this causes some subtle bugs, so i'm turning it off to see if we really need it, and if we do
            // if we can find a better way.
            //
            //freezePainting = true;

            AddCurrentDrag(data, client.Component);

            // Walk through all the children recursively and disable drag-drop
            // for each of them. This way, we will not accidentally try to drop
            // ourselves into our own children.
            //
            ArrayList allowDropChanged = new ArrayList();

            foreach (object comp in components)
            {
                Control ctl = comp as Control;
                if (ctl != null && ctl.HasChildren)
                {
                    DisableDragDropChildren(ctl.Controls, allowDropChanged);
                }
            }

            DragDropEffects     effect = DragDropEffects.None;
            IDesignerHost       host   = GetService(typeof(IDesignerHost)) as IDesignerHost;
            DesignerTransaction trans  = null;

            if (host != null)
            {
                trans = host.CreateTransaction(string.Format(SR.DragDropDragComponents, components.Length));
            }

            try
            {
                effect = c.DoDragDrop(data, allowedEffects);
                if (trans != null)
                {
                    trans.Commit();
                }
            }
            finally
            {
                RemoveCurrentDrag(data);

                // Reset the AllowDrop for the components being dragged.
                //
                foreach (Control ctl in allowDropChanged)
                {
                    ctl.AllowDrop = true;
                }

                freezePainting = oldFreezePainting;

                if (trans != null)
                {
                    ((IDisposable)trans).Dispose();
                }
            }

            bool isMove = (effect & DragDropEffects.Move) != 0 || ((int)effect & AllowLocalMoveOnly) != 0;

            // since the EndDrag will clear this
            bool isLocalMove = isMove && localDragInside;

            ISelectionUIService selectionUISvc = (ISelectionUIService)GetService(typeof(ISelectionUIService));

            Debug.Assert(selectionUISvc != null, "Unable to get selection ui service when adding child control");

            if (selectionUISvc != null)
            {
                // We must check to ensure that UI service is still in drag mode.  It is
                // possible that the user hit escape, which will cancel drag mode.
                //
                if (selectionUISvc.Dragging)
                {
                    // cancel the drag if we aren't doing a local move
                    selectionUISvc.EndDrag(!isLocalMove);
                }
            }

            if (!localDragOffset.IsEmpty && effect != DragDropEffects.None)
            {
                DrawDragFrames(dragComps, localDragOffset, localDragEffect,
                               Point.Empty, DragDropEffects.None, false);
            }

            localDragOffset = Point.Empty;
            dragComps       = null;
            localDrag       = localDragInside = false;
            dragBase        = Point.Empty;

            /*if (!isLocalMove && isMove){
             *  IDesignerHost host = (IDesignerHost)GetService(typeof(IDesignerHost));
             *  IUndoService  undoService = (IUndoService)GetService(typeof(IUndoService));
             *  IActionUnit unit = null;
             *
             *  if (host != null) {
             *      DesignerTransaction trans = host.CreateTransaction("Drag/drop");
             *      try{
             *          // delete the components
             *          try{
             *              for (int i = 0; i < components.Length; i++){
             *                 if (components[i] is IComponent){
             *                    if (undoService != null){
             *                        unit = new CreateControlActionUnit(host, (IComponent)components[i], true);
             *                    }
             *                    host.DestroyComponent((IComponent)components[i]);
             *                    if (undoService != null){
             *                         undoService.AddAction(unit, false);
             *                    }
             *                 }
             *              }
             *          }catch(CheckoutException ex){
             *              if (ex != CheckoutException.Canceled){
             *                  throw ex;
             *              }
             *          }
             *      }
             *      finally{
             *          trans.Commit();
             *      }
             *  }
             * }*/

            return(false);
        }
Example #27
0
 public static void DoDrop(Control control, string[] files, DragDropEffects DropMode)
 {
     control.DoDragDrop(GetDataObject(files),
                        DropMode);
 }
Example #28
0
        ///yla ext
        public static DragDropEffects DoDragDrop(Control control, Bitmap dragImage, Point cursorOffset,
            DragDropEffects allowedEffects,
            Runtime.InteropServices.ComTypes.IDataObject data)
        {
            AllowDropDescription(true);

            DataObject d =  new DataObject(data);
            ((IDataObject) d).SetDragImage(dragImage, cursorOffset);
            RegisterDefaultDragSource(control, d);
            try
            {
                return control.DoDragDrop(d, allowedEffects);
            }
            finally
            {
                UnregisterDefaultDragSource(control);
            }
        }
Example #29
0
        public static DragDropEffects DoDragDrop(List <string> lstPaths, Control control, bool fSameDirecotry)
        {
            DragDropEffects none;

            if ((lstPaths == null) || (lstPaths.Count == 0))
            {
                return(DragDropEffects.None);
            }
            IShellFolder  ppv  = null;
            object        obj2 = null;
            List <IntPtr> list = new List <IntPtr>();

            try {
                IntPtr[] ptrArray;
                if (fSameDirecotry)
                {
                    IntPtr ptr2;
                    IntPtr item = PInvoke.ILCreateFromPath(lstPaths[0]);
                    list.Add(item);
                    if ((PInvoke.SHBindToParent(item, ExplorerGUIDs.IID_IShellFolder, out ppv, out ptr2) != 0) || (ppv == null))
                    {
                        return(DragDropEffects.None);
                    }
                    List <IntPtr> list2 = new List <IntPtr>();
                    if (ptr2 != IntPtr.Zero)
                    {
                        list2.Add(ptr2);
                    }
                    for (int i = 1; i < lstPaths.Count; i++)
                    {
                        IntPtr ptr3 = PInvoke.ILCreateFromPath(lstPaths[i]);
                        if (ptr3 != IntPtr.Zero)
                        {
                            list.Add(ptr3);
                            IntPtr ptr4 = PInvoke.ILFindLastID(ptr3);
                            if (ptr4 != IntPtr.Zero)
                            {
                                list2.Add(ptr4);
                            }
                        }
                    }
                    if (list2.Count == 0)
                    {
                        return(DragDropEffects.None);
                    }
                    ptrArray = list2.ToArray();
                }
                else
                {
                    list.AddRange(lstPaths.Select(PInvoke.ILCreateFromPath).Where(ptr5 => ptr5 != IntPtr.Zero));
                    PInvoke.SHGetDesktopFolder(out ppv);
                    if ((list.Count == 0) || (ppv == null))
                    {
                        return(DragDropEffects.None);
                    }
                    ptrArray = list.ToArray();
                }
                uint rgfReserved = 0;
                Guid riid        = ExplorerGUIDs.IID_IDataObject;
                ppv.GetUIObjectOf(IntPtr.Zero, (uint)ptrArray.Length, ptrArray, ref riid, ref rgfReserved, out obj2);
                if (obj2 != null)
                {
                    return(control.DoDragDrop(obj2, DragDropEffects.Link | DragDropEffects.Move | DragDropEffects.Copy));
                }
                none = DragDropEffects.None;
            }
            finally {
                if (obj2 != null)
                {
                    Marshal.ReleaseComObject(obj2);
                }
                if (ppv != null)
                {
                    Marshal.ReleaseComObject(ppv);
                }
                foreach (IntPtr ptr6 in list)
                {
                    if (ptr6 != IntPtr.Zero)
                    {
                        PInvoke.CoTaskMemFree(ptr6);
                    }
                }
            }
            return(none);
        }
Example #30
0
        private void button1_MouseDown(object sender, MouseEventArgs e)
        {
            Control ctrl1 = sender as Control;

            ctrl1.DoDragDrop(ctrl1, DragDropEffects.Copy);
        }
Example #31
0
        public void ControlMouseUp(object sender, MouseEventArgs e)
        {
            Control control = sender as Control;

            MousePositionUp = Cursor.Position;
            if (MousePositionUp == MousePositionDown)
            {
                if (IsCtrlPressed == false)
                {
                    foreach (Control cnt in ParentForMouseActivity.Controls)
                    {
                        Button tb = cnt as Button;
                        if (tb != null)
                        {
                            tb.FlatStyle = System.Windows.Forms.FlatStyle.Standard;
                        }
                        Label label1 = cnt as Label;
                        if (label1 != null)
                        {
                            label1.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        CheckBox ckb1 = cnt as CheckBox;
                        if (ckb1 != null)
                        {
                            ckb1.BackColor = System.Drawing.Color.Transparent;
                        }
                        PictureBox pic1 = cnt as PictureBox;
                        if (pic1 != null)
                        {
                            pic1.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        UserSwitcher usersw = cnt as UserSwitcher;
                        if (usersw != null)
                        {
                            usersw.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        CheckButton usercb = cnt as CheckButton;
                        if (usercb != null)
                        {
                            usercb.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        UsersButton userbtn = cnt as UsersButton;
                        if (userbtn != null)
                        {
                            userbtn.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        ValueBox valueBox = cnt as ValueBox;
                        if (valueBox != null)
                        {
                            valueBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        UserText textBox = cnt as UserText;
                        if (textBox != null)
                        {
                            textBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                        UserImage userImage = cnt as UserImage;
                        if (userImage != null)
                        {
                            userImage.BorderStyle = System.Windows.Forms.BorderStyle.None;
                        }
                    }
                    view.SelectControl(sender, null, true);
                    if (sender as Button != null)
                    {
                        Button button = sender as Button; button.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
                    }
                    if (sender as Label != null)
                    {
                        Label label = sender as Label; label.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as CheckBox != null)
                    {
                        CheckBox checkbox = sender as CheckBox; checkbox.BackColor = System.Drawing.Color.LightGray;
                    }
                    if (sender as PictureBox != null)
                    {
                        PictureBox picturebox = sender as PictureBox; picturebox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as UserSwitcher != null)
                    {
                        UserSwitcher userSwitcher = sender as UserSwitcher; userSwitcher.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as CheckButton != null)
                    {
                        CheckButton checkButton = sender as CheckButton; checkButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as UsersButton != null)
                    {
                        UsersButton usersButton = sender as UsersButton; usersButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as ValueBox != null)
                    {
                        ValueBox valueBox = sender as ValueBox; valueBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as UserText != null)
                    {
                        UserText userText = sender as UserText; userText.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (sender as UserImage != null)
                    {
                        UserImage userImage = sender as UserImage; userImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    view.AddToListOfControl(ParentForMouseActivity.Controls[ParentForMouseActivity.Controls.IndexOf(control)].Name, true);
                }
                else
                {
                    if (control.GetType() == typeof(Button))
                    {
                        Button controlbutton = control as Button;
                        controlbutton.FlatStyle = System.Windows.Forms.FlatStyle.Popup;
                    }
                    if (control.GetType() == typeof(Label))
                    {
                        Label controllabel = control as Label;
                        controllabel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(CheckBox))
                    {
                        CheckBox controlcheckbox = control as CheckBox;
                        controlcheckbox.BackColor = System.Drawing.Color.LightGray;
                    }
                    if (control.GetType() == typeof(PictureBox))
                    {
                        PictureBox controlpicturebox = control as PictureBox;
                        controlpicturebox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(UserSwitcher))
                    {
                        UserSwitcher userSwitcher = control as UserSwitcher;
                        userSwitcher.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(CheckButton))
                    {
                        CheckButton checkButton = control as CheckButton;
                        checkButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(UsersButton))
                    {
                        UsersButton usersButton = control as UsersButton;
                        usersButton.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(ValueBox))
                    {
                        ValueBox valueBox = control as ValueBox;
                        valueBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(UserText))
                    {
                        UserText textBox = control as UserText;
                        textBox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    if (control.GetType() == typeof(UserImage))
                    {
                        UserImage userImage = control as UserImage;
                        userImage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
                    }
                    controls.Add(control);
                    object[] arrayControls = controls.ToArray();
                    view.SelectControl(sender, arrayControls, false);
                    foreach (Control ind in arrayControls)
                    {
                        int inde = ParentForMouseActivity.Controls.IndexOf(ind);
                        if (inde >= 0)
                        {
                            view.AddToListOfControl(ParentForMouseActivity.Controls[inde].Name, false);
                        }
                    }
                }
            }
            else
            {
                if (resize)
                {
                    if (east && (MousePositionUp.X - MousePositionDown.X) > -control.Width)
                    {
                        control.Width = control.Width + (MousePositionUp.X - MousePositionDown.X);
                    }
                    if (south && (MousePositionUp.Y - MousePositionDown.Y) > -control.Height)
                    {
                        control.Height = control.Height + (MousePositionUp.Y - MousePositionDown.Y);
                    }
                    if (north && (MousePositionUp.Y - MousePositionDown.Y) < control.Height)
                    {
                        control.Location = new Point(control.Location.X, control.Location.Y + (MousePositionUp.Y - MousePositionDown.Y));
                        control.Height   = control.Height - (MousePositionUp.Y - MousePositionDown.Y);
                    }
                    if (west && (MousePositionUp.X - MousePositionDown.X) < control.Width)
                    {
                        control.Location = new Point(control.Location.X + (MousePositionUp.X - MousePositionDown.X), control.Location.Y);
                        control.Width    = control.Width - (MousePositionUp.X - MousePositionDown.X);
                    }
                    east   = false;
                    south  = false;
                    north  = false;
                    west   = false;
                    resize = false;
                }
                else
                {
                    control.DoDragDrop(sender, DragDropEffects.Move);
                }
            }
        }
Example #32
0
        /// <summary>
        /// Performs a default drag and drop operation for the specified drag source.
        /// </summary>
        /// <param name="control">The drag source Control.</param>
        /// <param name="dataObject">The data object associated to the drag and drop operation.</param>
        /// <param name="allowedEffects">The allowed drop effects.</param>
        /// <param name="data">The associated data.</param>
        /// <returns>The accepted drop effects from the completed operation.</returns>
        private static DragDropEffects DoDragDropInternal(Control control, IDataObject dataObject,
            DragDropEffects allowedEffects,
            KeyValuePair<string, object>[] data)
        {
            // Set the data onto the data object.
            if (data != null)
            {
                foreach (KeyValuePair<string, object> dataPair in data)
                    dataObject.SetDataEx(dataPair.Key, dataPair.Value);

            }

            try
            {
                return control.DoDragDrop(dataObject, allowedEffects);
            }
            finally
            {
                UnregisterDefaultDragSource(control);
            }
        }