Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to drag-and-drop ComponentBase based class in a CompositeNode? (Read 247 times)
GrandSon
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Nov 26th, 2023
How to drag-and-drop ComponentBase based class in a CompositeNode?
May 8th, 2024 at 5:04am
Print Post  
Hi.

I had DragDrop logic. It works fine on WinForms.Control based program.
I'd like to drag-and-drop Component(s) in a CompositeNode.
How can I drag drop Component?

I have tried make prototype with following node and components.
CompositeNode
- StackPanel(Vertical orientation)
- - TextComponent1
- - TextComponent2

I want drag Text1 and drag to Text2, then move Text1 under Text2.

I can find TextComponen1 and 2 in MouseDown method, but I can't in DragOver method.
In MouseDown, MouseEventArgs.Location is like (37, 7).
In DragOver, DragEventArgs.X and Y is like (159, 157).
Why coordinate to be larger?

I guess _view.DoDragDrop(data, DragDropEffects.Move); in MouseMove is wrong.
Or this way is whole wrong?

Code (C++)
Select All
        private void MouseDown(object? sender, MouseEventArgs e)
        {
            Size dragSize = SystemInformation.DragSize;
            _dragBoxFromMouseDown = new RectangleF(
                new Point(e.X - dragSize.Width / 2,
                          e.Y - dragSize.Height / 2),
                dragSize);

            var location = _view.ClientToDoc(e.Location);
            _part = _node.GetComponentAt(location);
            Debug.WriteLine($"MouseDown:{_part}");
            Debug.WriteLine($"{e.Location} v.s. {location}");
            if(_part is TextComponent text)
                Debug.WriteLine($"MouseDown:{text.Text}");
        }
        private void MouseMove(object? sender, MouseEventArgs e)
        {
            if(_dragBoxFromMouseDown != Rectangle.Empty && !_dragBoxFromMouseDown.Contains(e.X, e.Y))
            {
                var data = MakeData(_part!);
                Debug.WriteLine($"MouseMove:before dnd{_part}");
                _view.DoDragDrop(data, DragDropEffects.Move);
                Debug.WriteLine($"MouseMove:after drop");
            }
        }
        private void DragOver(object? sender, DragEventArgs e)
        {
            var location = _view.ClientToDoc(new Point(e.X, e.Y));
            Debug.WriteLine($"{new Point(e.X, e.Y)} v.s. {location}");
            _dropTarget = _node.GetComponentAt(location);
            Debug.WriteLine($"DragOver: {_dropTarget}");
            if(_dropTarget is TextComponent text)
                Debug.WriteLine($"DragOver: {text.Text}");
        }

 

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3228
Joined: Oct 19th, 2005
Re: How to drag-and-drop ComponentBase based class in a CompositeNode?
Reply #1 - May 8th, 2024 at 7:25am
Print Post  
Hi,

For DragDrop you'll need additional conversion from screen to client coordinates before client to diagram ones -

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.dragov...

Quote:
The X and Y properties of the DragEventArgs are in screen coordinates, not client coordinates. The following line of C# code converts the properties to a client Point:

Point clientPoint = targetControl.PointToClient(new Point(de.X, de.Y));


so first call PointToClient, and then pass its result to ClientToDoc.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
GrandSon
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 10
Joined: Nov 26th, 2023
Re: How to drag-and-drop ComponentBase based class in a CompositeNode?
Reply #2 - May 8th, 2024 at 11:01am
Print Post  
Thank you so much.
I resolved problem.

Found Component.
Code (C++)
Select All
            var clientLoc = _view.PointToClient(new Point(e.X, e.Y));
            var location = _view.ClientToDoc(clientLoc);
 

« Last Edit: May 8th, 2024 at 11:28pm by GrandSon »  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint