Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. What am I missing here??? [modified]

What am I missing here??? [modified]

Scheduled Pinned Locked Moved C#
helpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    new_phoenix
    wrote on last edited by
    #1

    I am working on an application that implements a drag and drop interface, but when I drag the control with the mouse the control's position does not actually change until the cursor touches the form. That is, if I have a control that is 200 pixels tall by 150 pixels wide and I click the cursor and hold it at pixel 100 and 50, the control does not move until the cursor touches the form, but then the cursor is again positioned at the drag point again. This causes the control to move in jumps. I would like the cursor to remain at the drag position where the cursor was clicked and to drag from that point smoothly without the cursor needing to touch the form. Do I need to somehow resample the control's position so that it moves using the drag point without needing to touch the form? Here is the code

    private static void _ctrlParent_DragOver(object sender, DragEventArgs e)
    {
    try
    {
    if (DragDropHandler.CanDropHere((Control)sender, e.Data))
    {
    Control cthis = (Control)sender;
    Control cthisParent = ((Control)sender);

    		e.Effect = DragDropEffects.Move;
    		Control ctrl = DragDropHandler.GetControl(e.Data, true, true);
    			
    		if (!(ctrl is IDragDropEnabled))
    		{
    			return;
    		}
    		if (cthis.Name != ctrl.Name)
    		{
    			ctrl.Parent.Controls.Remove(ctrl);
    			ctrl.Parent = cthis;
    			cthis.Controls.Add(ctrl);
    			ctrl.BringToFront();
    		}
    		else
    		{
    			return;
    		}
    		Point NewLocation = cthis.PointToClient(new Point(e.X, e.Y));
    		ctrl.Left = NewLocation.X - dragPoint.X;
    		ctrl.Top = NewLocation.Y - dragPoint.Y;  // Do I need to resample the control's position here?
    	}
    	else
    	{
    		e.Effect = DragDropEffects.None;
    	}
    }
    catch (System.Exception ex)
    {
    	MessageBox.Show("Error is " + ex.GetBaseException());
    }
    

    }

    -- modified at 14:26 Monday 28th May, 2007

    G 1 Reply Last reply
    0
    • N new_phoenix

      I am working on an application that implements a drag and drop interface, but when I drag the control with the mouse the control's position does not actually change until the cursor touches the form. That is, if I have a control that is 200 pixels tall by 150 pixels wide and I click the cursor and hold it at pixel 100 and 50, the control does not move until the cursor touches the form, but then the cursor is again positioned at the drag point again. This causes the control to move in jumps. I would like the cursor to remain at the drag position where the cursor was clicked and to drag from that point smoothly without the cursor needing to touch the form. Do I need to somehow resample the control's position so that it moves using the drag point without needing to touch the form? Here is the code

      private static void _ctrlParent_DragOver(object sender, DragEventArgs e)
      {
      try
      {
      if (DragDropHandler.CanDropHere((Control)sender, e.Data))
      {
      Control cthis = (Control)sender;
      Control cthisParent = ((Control)sender);

      		e.Effect = DragDropEffects.Move;
      		Control ctrl = DragDropHandler.GetControl(e.Data, true, true);
      			
      		if (!(ctrl is IDragDropEnabled))
      		{
      			return;
      		}
      		if (cthis.Name != ctrl.Name)
      		{
      			ctrl.Parent.Controls.Remove(ctrl);
      			ctrl.Parent = cthis;
      			cthis.Controls.Add(ctrl);
      			ctrl.BringToFront();
      		}
      		else
      		{
      			return;
      		}
      		Point NewLocation = cthis.PointToClient(new Point(e.X, e.Y));
      		ctrl.Left = NewLocation.X - dragPoint.X;
      		ctrl.Top = NewLocation.Y - dragPoint.Y;  // Do I need to resample the control's position here?
      	}
      	else
      	{
      		e.Effect = DragDropEffects.None;
      	}
      }
      catch (System.Exception ex)
      {
      	MessageBox.Show("Error is " + ex.GetBaseException());
      }
      

      }

      -- modified at 14:26 Monday 28th May, 2007

      G Offline
      G Offline
      Guffa
      wrote on last edited by
      #2

      Drag-and-drop isn't used to move controls around, it's used for grabbings something (more or less) imaginary (like the representation of some files in an explorer window), and drag them to a control of some kind. If you want to move a control around, you should just capture the mouse on MouseDown, move the control on MouseMove and release the mouse on MouseUp. (Actually, I'm not sure if that is the best way of doing it, but it will get you far closer than using drag-and-drop.)

      --- single minded; short sighted; long gone;

      N 1 Reply Last reply
      0
      • G Guffa

        Drag-and-drop isn't used to move controls around, it's used for grabbings something (more or less) imaginary (like the representation of some files in an explorer window), and drag them to a control of some kind. If you want to move a control around, you should just capture the mouse on MouseDown, move the control on MouseMove and release the mouse on MouseUp. (Actually, I'm not sure if that is the best way of doing it, but it will get you far closer than using drag-and-drop.)

        --- single minded; short sighted; long gone;

        N Offline
        N Offline
        new_phoenix
        wrote on last edited by
        #3

        Guffa: The problem is that I need to be able to drag a control and to drop it onto another control, but in the meantime I need to be able to drag each control from the place where the mouse down click occurs. This drag point is currently retained by the Mouse Down event handler, but the control only moves when the cursor touches the form. This makes the control movement jumpy. I would instead like to be able to move the control from the drag point without the curor touching the form. Do you have any advice? Should I somehow capture the movement of the mouse in the MouseMove event handler? :confused::confused::confused: New_Phoenix

        G 1 Reply Last reply
        0
        • N new_phoenix

          Guffa: The problem is that I need to be able to drag a control and to drop it onto another control, but in the meantime I need to be able to drag each control from the place where the mouse down click occurs. This drag point is currently retained by the Mouse Down event handler, but the control only moves when the cursor touches the form. This makes the control movement jumpy. I would instead like to be able to move the control from the drag point without the curor touching the form. Do you have any advice? Should I somehow capture the movement of the mouse in the MouseMove event handler? :confused::confused::confused: New_Phoenix

          G Offline
          G Offline
          Guffa
          wrote on last edited by
          #4

          Read my previous post again. If you don't understand it, explain what it is that you don't understand, instead of just repeating the contents of your original post.

          --- single minded; short sighted; long gone;

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups