implementing dragdrop whilst allowing click

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David J Rose

    #1

    implementing dragdrop whilst allowing click

    I am having trouble allowing a user to drag an item, whilst also allowing
    them to click the item. I am using mousedown, mousemove and mouseup. It
    works if I click the button carefully, but if there is any mouse movement,
    then it is interpreted as a drag, and the click does not work. What I want
    is a way to only do the drag if the mouse movement is above a threshold. Is
    this possible?

    Here is the basic code:

    private void ItemToolStripBu tton_MouseDown( object sender, MouseEventArgs e)
    {
    ToolStripButton btn = ((ToolStripButt on)sender);
    if (e.Button == MouseButtons.Ri ght)
    {
    //show contextmenu
    }
    else
    {
    bMouseDown = true;
    }
    }

    private void ItemToolStripBu tton_MouseMove( object sender, MouseEventArgs e)
    {
    if ((bMouseDown) && (e.Button == MouseButtons.Le ft))
    {
    ToolStripButton btn = ((ToolStripButt on)sender);
    btn.DoDragDrop( btn.Tag, DragDropEffects .Copy);
    }
    }
    }

    private void ItemToolStripBu tton_MouseUp(ob ject sender, MouseEventArgs e)
    {
    ToolStripButton btn = ((ToolStripButt on)sender);
    if (e.Button != MouseButtons.Ri ght)
    {
    //perform the onclick code here
    bMouseDown = false;
    }

    Much Thanks



    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
  • Alan Pretre

    #2
    Re: implementing dragdrop whilst allowing click

    "David J Rose" <david.rose@new sgroup.reply.on ly.com> wrote in message
    news:4282122b$1 _1@spool9-west.superfeed. net...[color=blue]
    >I am having trouble allowing a user to drag an item, whilst also allowing
    >them to click the item. I am using mousedown, mousemove and mouseup. It
    >works if I click the button carefully, but if there is any mouse movement,
    >then it is interpreted as a drag, and the click does not work. What I want
    >is a way to only do the drag if the mouse movement is above a threshold. Is
    >this possible?[/color]

    There's a whole bunch of events, such as

    DragDrop
    DragEnter
    DragLeave
    DragOver
    ItemDrag

    that you need to set up. In addition, there is a property called AllowDrop
    that needs to be turned on. Using these things the system will initiate and
    do the drag and drop operation for you.

    -- Alan


    Comment

    • David J Rose

      #3
      Re: implementing dragdrop whilst allowing click

      I believe that all the events mentioned are for accepting a dragged item. I
      am talking about starting the drag-drop operation using the DoDragDrop
      method.

      Any more ideas?


      "Alan Pretre" <alanpretre@new sgroup.nospam> wrote in message
      news:uszmasjVFH A.2172@tk2msftn gp13.phx.gbl...[color=blue]
      > "David J Rose" <david.rose@new sgroup.reply.on ly.com> wrote in message
      > news:4282122b$1 _1@spool9-west.superfeed. net...[color=green]
      >>I am having trouble allowing a user to drag an item, whilst also allowing
      >>them to click the item. I am using mousedown, mousemove and mouseup. It
      >>works if I click the button carefully, but if there is any mouse movement,
      >>then it is interpreted as a drag, and the click does not work. What I want
      >>is a way to only do the drag if the mouse movement is above a threshold.
      >>Is this possible?[/color]
      >
      > There's a whole bunch of events, such as
      >
      > DragDrop
      > DragEnter
      > DragLeave
      > DragOver
      > ItemDrag
      >
      > that you need to set up. In addition, there is a property called
      > AllowDrop that needs to be turned on. Using these things the system will
      > initiate and do the drag and drop operation for you.
      >
      > -- Alan
      >
      >[/color]



      ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
      http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
      ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

      Comment

      • Alan Pretre

        #4
        Re: implementing dragdrop whilst allowing click

        "David J Rose" <david.rose@new sgroup.reply.on ly.com> wrote in message
        news:42822201$1 _2@spool9-west.superfeed. net...[color=blue]
        >I believe that all the events mentioned are for accepting a dragged item. I
        >am talking about starting the drag-drop operation using the DoDragDrop
        >method.[/color]

        Sorry, I guess I should have asked you where you are dragging from. If you
        are dragging from a listview or a treeview, you do the DoDragDrop() call in
        the ItemDrag event, not MouseDown.

        -- Alan


        Comment

        • John B

          #5
          Re: implementing dragdrop whilst allowing click

          David J Rose wrote:[color=blue]
          > I am having trouble allowing a user to drag an item, whilst also allowing
          > them to click the item. I am using mousedown, mousemove and mouseup. It
          > works if I click the button carefully, but if there is any mouse movement,
          > then it is interpreted as a drag, and the click does not work. What I want
          > is a way to only do the drag if the mouse movement is above a threshold. Is
          > this possible?[/color]

          Its sort of kludgy but you could define your threshhold (say 200ms) and
          start a timer in the mousedown event which when fired would do the
          dragdrop only if the mouse is still down.

          Havent tried though, I have had the same sort of problem with other tree
          views, spec. infragistics activetree in vb6.

          JB
          [color=blue]
          >
          > Here is the basic code:
          >
          > private void ItemToolStripBu tton_MouseDown( object sender, MouseEventArgs e)
          > {
          > ToolStripButton btn = ((ToolStripButt on)sender);
          > if (e.Button == MouseButtons.Ri ght)
          > {
          > //show contextmenu
          > }
          > else
          > {
          > bMouseDown = true;
          > }
          > }
          >
          > private void ItemToolStripBu tton_MouseMove( object sender, MouseEventArgs e)
          > {
          > if ((bMouseDown) && (e.Button == MouseButtons.Le ft))
          > {
          > ToolStripButton btn = ((ToolStripButt on)sender);
          > btn.DoDragDrop( btn.Tag, DragDropEffects .Copy);
          > }
          > }
          > }
          >
          > private void ItemToolStripBu tton_MouseUp(ob ject sender, MouseEventArgs e)
          > {
          > ToolStripButton btn = ((ToolStripButt on)sender);
          > if (e.Button != MouseButtons.Ri ght)
          > {
          > //perform the onclick code here
          > bMouseDown = false;
          > }
          >
          > Much Thanks
          >
          >
          >
          > ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
          > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
          > ----= East and West-Coast Server Farms - Total Privacy via Encryption =----[/color]

          Comment

          • Robert W.

            #6
            Re: implementing dragdrop whilst allowing click

            I'm facing the same problem as David is. I have a series of radio buttons
            that look like regular buttons. Originally they were just designed to select
            a different option. But now I want to add Drag & Drop capability so that
            their order can be changed.

            My first thought was to immediately back out of the MouseDown event (which
            initiates Drag & Drop) if the radioButton wasn't already checked. That works
            okay but isn't exactly the effect I'd ideally like.

            So I'd love to get more feedback on here if the timer suggestion is the
            preferred approach to resolve this issue ... or are there other approaches?

            --
            Robert W.
            Vancouver, BC




            "John B" wrote:
            [color=blue]
            > David J Rose wrote:[color=green]
            > > I am having trouble allowing a user to drag an item, whilst also allowing
            > > them to click the item. I am using mousedown, mousemove and mouseup. It
            > > works if I click the button carefully, but if there is any mouse movement,
            > > then it is interpreted as a drag, and the click does not work. What I want
            > > is a way to only do the drag if the mouse movement is above a threshold. Is
            > > this possible?[/color]
            >
            > Its sort of kludgy but you could define your threshhold (say 200ms) and
            > start a timer in the mousedown event which when fired would do the
            > dragdrop only if the mouse is still down.
            >
            > Havent tried though, I have had the same sort of problem with other tree
            > views, spec. infragistics activetree in vb6.
            >
            > JB
            >[color=green]
            > >
            > > Here is the basic code:
            > >
            > > private void ItemToolStripBu tton_MouseDown( object sender, MouseEventArgs e)
            > > {
            > > ToolStripButton btn = ((ToolStripButt on)sender);
            > > if (e.Button == MouseButtons.Ri ght)
            > > {
            > > //show contextmenu
            > > }
            > > else
            > > {
            > > bMouseDown = true;
            > > }
            > > }
            > >
            > > private void ItemToolStripBu tton_MouseMove( object sender, MouseEventArgs e)
            > > {
            > > if ((bMouseDown) && (e.Button == MouseButtons.Le ft))
            > > {
            > > ToolStripButton btn = ((ToolStripButt on)sender);
            > > btn.DoDragDrop( btn.Tag, DragDropEffects .Copy);
            > > }
            > > }
            > > }
            > >
            > > private void ItemToolStripBu tton_MouseUp(ob ject sender, MouseEventArgs e)
            > > {
            > > ToolStripButton btn = ((ToolStripButt on)sender);
            > > if (e.Button != MouseButtons.Ri ght)
            > > {
            > > //perform the onclick code here
            > > bMouseDown = false;
            > > }
            > >
            > > Much Thanks
            > >
            > >
            > >
            > > ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
            > > http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
            > > ----= East and West-Coast Server Farms - Total Privacy via Encryption =----[/color]
            >[/color]

            Comment

            • Robert W.

              #7
              Re: implementing dragdrop whilst allowing click

              I want to follow up with what John B wrote (and thank him!) for quickly
              finding me a solution to this problem.

              First, I googled for: c# timer mousedown
              and found this article:


              I quickly grasped the leapfrogging the author was suggesting, along with
              stopping the timer if the mouse button is released quickly enough. Here's
              the code I wrote for my application, which are a series of Question buttons.
              Hopefully this code can help others too:


              // Initiate a dedicated timer. If the user holds down the mouse long
              enough then we'll assume he wants to drag & drop.
              private void QuestionButton_ MouseDown(objec t sender, MouseEventArgs e)
              {
              ClickedQuestion Button = sender; // Store a reference to this
              button because 'QuestionButton Timer_Tick' can't access it otherwise
              questionButtonT imer.Enabled = true;
              }

              // ... Otherwise if he lets go quickly then we'll assume he just wants
              to click the question button instead.
              private void QuestionButton_ MouseUp(object sender, MouseEventArgs e)
              {
              questionButtonT imer.Enabled = false;
              ClickedQuestion Button = null; // Just cleaning up
              }

              // Initiates drag & drop visual effects
              private void QuestionButtonT imer_Tick(objec t sender, EventArgs e)
              {
              questionButtonT imer.Enabled = false;

              QuestionButton qBut = ClickedQuestion Button as QuestionButton;
              ClickedQuestion Button = null; // Just cleaning up
              qBut.DoDragDrop (qBut, DragDropEffects .All);
              }


              In my case, it's imperative to know which QuestionButton (of several) is
              being dragged, so that's why I created a module-level private variable to
              temporarily store it. I don't think it's necessary to set this variable to
              null but I thought it was cleaner this way.

              For now I'm going to take John B's advice and use 200ms as the delay time.
              I suppose that it might be prudent to allow this value to be shortened or
              lengthened depending on a user's preference.

              --
              Robert W.
              Vancouver, BC




              "Robert W." wrote:
              [color=blue]
              > I'm facing the same problem as David is. I have a series of radio buttons
              > that look like regular buttons. Originally they were just designed to select
              > a different option. But now I want to add Drag & Drop capability so that
              > their order can be changed.
              >
              > My first thought was to immediately back out of the MouseDown event (which
              > initiates Drag & Drop) if the radioButton wasn't already checked. That works
              > okay but isn't exactly the effect I'd ideally like.
              >
              > So I'd love to get more feedback on here if the timer suggestion is the
              > preferred approach to resolve this issue ... or are there other approaches?
              >
              > --
              > Robert W.
              > Vancouver, BC
              > www.mwtech.com[/color]

              Comment

              Working...