This project is read-only.

Drag-n-Drop support

Mar 21, 2011 at 5:45 PM

Hello, everybody.
First, thank you for such a good control!

My aim is to create an App for constructing Artificial Neural Network. I've searched a lot and I think Qgraph and G# are the best way to visualize network.
I want to create drug and drop support for creating network element (there will be icons with different types of neurons and i want users to grag them to GraphLayout Control) 

can anyone help me with this? some code example will be enough!

Apr 6, 2011 at 4:51 PM

problem solved!

Jun 2, 2011 at 7:29 PM

How did you do it? Can you share some code?

Jun 20, 2011 at 8:23 PM
Edited Jun 20, 2011 at 8:26 PM

yes, of course!

here I define what kind of neuron is dragged (example is for imAddRec - receptor image):

private void imAddRec_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            mousePressedOnRec = true;
        }

        private void imAddRec_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
        {
            if (mousePressedOnRec && e.LeftButton == MouseButtonState.Pressed)
            {
                System.Windows.DataObject d = new System.Windows.DataObject();
                d.SetData(System.Windows.DataFormats.StringFormat, "receptor", false);
                DragDrop.DoDragDrop(imAddRec, d, System.Windows.DragDropEffects.Move);
            }
            mousePressedOnRec = false;
        }

Drop event on GraphLayout:

private void graphLayout_Drop(object sender, System.Windows.DragEventArgs e)
        {            
            var type = new object();
            if (e.Data.GetDataPresent(System.Windows.DataFormats.StringFormat))
                type = e.Data.GetData(System.Windows.DataFormats.StringFormat, false);
            else
                return;
            
            switch (type.ToString())
            {
                case "receptor":
                    {
                        AddReceptor();
                        break;
                    }
                case "recn":
                    {
                        AddNeuronToRecZone();
                        break;
                    }
                case "effn":
                    {
                        AddNeuronToEffZone();
                        break;
                    }
                case "effector":
                    {
                        AddEffector();
                        break;
                    }
            }
        }

Jun 21, 2011 at 6:30 AM

Thanks