Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Dropping boxes on other boxes (Read 11380 times)
Jon Merrifield
Guest


Dropping boxes on other boxes
Oct 5th, 2005 at 1:51pm
Print Post  
Hi,

I need to implement this feature, I wonder if anyone could give me any pointers?  The requirement is to be able to drag a box (or group of boxes) onto another box, be able to provide a visual cue that the drop will have some effect, and then perform some action when the drop is complete.  The effect should be much the same as in windows explorer when you drag a file onto a folder to move it into that folder (i.e. the folder is highlighted when the item is dragged over it). 

At a first glance I can't see any events exposed by the flowchart to do this easily, I imagine I need to intercept and manipulate the box moving process somehow?  Any advice much appreciated, thanks

Jon
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dropping boxes on other boxes
Reply #1 - Oct 5th, 2005 at 4:17pm
Print Post  
Hi Jon,

Try something like this:

[code]Box prevFolderBox = null;

private void fc_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e)
{
  PointF mousePos = fc.ClientToDoc(new Point(e.X, e.Y));
  if (prevFolderBox != null)
    prevFolderBox.PenWidth = 0;

  // get the box under the mouse cursor
  Box folderBox = fc.GetNodeObjectAt(mousePos, true, true) as Box;
  if (folderBox != null && e.Button == MouseButtons.Left)
    folderBox.PenWidth = 2;
  prevFolderBox = folderBox;
}[/code]

Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dropping boxes on other boxes
Reply #2 - Oct 5th, 2005 at 4:19pm
Print Post  
That indicates the box where the selection will be dropped by chaning the frame width. You might as well change something else, e.g. color ot pen style.

Stoyan
  
Back to top
 
IP Logged
 
Jon Merrifield
Guest


Re: Dropping boxes on other boxes
Reply #3 - Oct 6th, 2005 at 6:52am
Print Post  
Thanks Stoyo,

That works well for providing the visual cue.  Can you suggest a way to obtain a reference to the box which has been/is about to be dropped?

I thought I could use the mousedown/mouseup events to maintain a reference to whichever box gets clicked on, but how would I know that it was actually being dragged?  The user could be resizing the box, or they could be creating an arrow between nodes etc.

Thanks again,
Jon
  
Back to top
 
IP Logged
 
Jon Merrifield
Guest


Re: Dropping boxes on other boxes
Reply #4 - Oct 6th, 2005 at 7:03am
Print Post  
Actually, I just had a thought: I can handle the BoxModified and SelectionMoved events, if this occurs while the flowchart is in the 'dragged over' state then I know that the drop has occurred and I will have a reference to the box/selection which has been dropped, does that sound correct? 

Jon
  
Back to top
 
IP Logged
 
Pascal Vantrepote
Guest


Re: Dropping boxes on other boxes
Reply #5 - Oct 6th, 2005 at 8:13am
Print Post  
Hi,

I tried to do that. But when you move the box, you didn't receive any DragOver event (Or I missed something).
Maybe you know a flags to do that.
Please, let us know if you it's working.


Thanks.
Pascal.
  
Back to top
 
IP Logged
 
Jon Merrifield
Guest


Re: Dropping boxes on other boxes
Reply #6 - Oct 6th, 2005 at 8:24am
Print Post  
The DragOver event is a WinForms drag+drop related event, which you would use if you wanted to drag items from other applications onto your flowchart and take action in response to that.

In Stoyo's example code, the line 'folderBox.PenWidth = 2' is the point at which 'folderBox' has something being dragged over it, and 'prevFolderBox.PenWidth = 0' occurs when that something is no longer positioned above folderBox.  You could insert your own code at these points to call your own methods to handle the dragging over.  You can then handle the MouseUp event, and if 'prevFolderBox' is not null, this would signal that the user has dropped the item. 

Hope that helps,
Jon
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dropping boxes on other boxes
Reply #7 - Oct 6th, 2005 at 10:09am
Print Post  
Hi Jon,

Yes , BoxModified and SelectionMoved seem the right events to handle the drop operation. In BoxModified you could check the handle index to know whether the box is moved or resized.

If you need to know what's being dragged in MouseMove, you might check what items are there in the Selection collections. However that won't work for items that are just being created.

Stoyan
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dropping boxes on other boxes
Reply #8 - Oct 6th, 2005 at 10:17am
Print Post  
Ok we often get requests for handling 'drag over box/table' operations, I'll get a developer here implement some events for these in the next release of FlowChart.NET.
  
Back to top
 
IP Logged
 
Pascal Vantrepote
Guest


Re: Dropping boxes on other boxes
Reply #9 - Oct 6th, 2005 at 10:48am
Print Post  
Thanks Stoyo, we really need that.
Do you know when the next version coming up?


Thanks again.
Pascal.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dropping boxes on other boxes
Reply #10 - Oct 6th, 2005 at 10:57am
Print Post  
Hi Pascal,

We released version 3.2.3 on Monday, so the next release will be in mid-November. The events might be implemented much earlier though; leave a message at our support email address and we'll send you the daily build of the control when the events are available.

Stoyan
  
Back to top
 
IP Logged
 
Jon Merrifield
Guest


Re: Dropping boxes on other boxes
Reply #11 - Oct 7th, 2005 at 7:44am
Print Post  
Stoyo,

I am seeing some odd visual artifacts while dragging these boxes around - if I use your code to change the appearance of a box which is acting as the drop target, it doesn't seem to refresh properly as the hovering box is dragged around it.  Are there any steps I can take to force a full redraw of the drop target box when another box is being dragged over it?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dropping boxes on other boxes
Reply #12 - Oct 7th, 2005 at 8:34am
Print Post  
Jon,

That seems to happen because of an optimization used in FlowChart.NET to redraw the view quickly while dragging items or drawing new items. When the mouse button is pressed, all items that won't be moved or resized are painted in an offscreen bitmap, which is later blitted to the screen and only the dragged items are redrawn.

So even if you change the folder box pen width or color, the cache bitmap contains its old appearance and the odd effect occurs. I guess we can add a method to recreate that cache bitmap, which you could call after changing the folder box properties.

Stoyan
  
Back to top
 
IP Logged
 
Jon Merrifield
Guest


Re: Dropping boxes on other boxes
Reply #13 - Oct 7th, 2005 at 2:44pm
Print Post  
I've noticed that if a box has an arrow attached the redraw happens perfectly, no matter where the arrow is attached or if it is near to the intersection of the two boxes.  Is there a way of fooling a box into thinking it has arrows attached so that it redraws the surrounding area as well?  Would this be a better solution than recreating the cache (or is this what happens anyway when arrows are involved - sorry if I have misunderstood)

Jon
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Dropping boxes on other boxes
Reply #14 - Oct 7th, 2005 at 3:41pm
Print Post  
I looked through the mouse move code, and indeed the cache is recreated if an arrow is moved and arrow crossing shapes are enabled (e.g. drawing arcs at arrow crossing points). I guess that's done because these arcs might have to be redrawn even for arrows that are not moved, when some other arrows that are being modified cause the crossing point locations to change.

So if you create an invisible arrow attached to the dragged box, that could force the redraw. However it isn't a problem for us to make the now internal method that recreates the cache public, it's a single line of code. A developer can do this on Monday and we'll send you the daily build of the dll then; I believe we have your email address in our registration database.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint