Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic how to use the UP,Down,Left,Right Key of the keyboard to move the node? (Read 3303 times)
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
how to use the UP,Down,Left,Right Key of the keyboard to move the node?
Jan 5th, 2015 at 8:26am
Print Post  
hi,
I want use the UP(Down,Left,Right) key to move the node.but I find the UP-Key's EventHandle has been Used by Diagram. Could you please give me some help?
thanks.
Code
Select All
void DesignDiagram_KeyDown(object sender, KeyEventArgs e)
{
    if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Shift && e.Key == Key.Up)
    {
        if (DesignDiagram.Selection.Nodes.Count > 0)
        {
            double currentX = 0d;
            double currentY = 0d;
            foreach (var node in DesignDiagram.Selection.Nodes)
            {
                currentX = node.Bounds.X;
                currentY = node.Bounds.Y;
                currentY -= DesignDiagram.GridSizeY / 5;
                node.Move(currentX, currentY);
            }
        }
    }
}
 

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use the UP,Down,Left,Right Key of the keyboard to move the node?
Reply #1 - Jan 5th, 2015 at 9:25am
Print Post  
Hi,

You can find an example here:
http://mindfusion.eu/Forum/YaBB.pl?num=1337156437/1#1

KeyDown should work too, but to make sure the keyboard focus isn't captured by ScrollViewer, set <ScrollViewer Focusable="False" ... >

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to use the UP,Down,Left,Right Key of the keyboard to move the node?
Reply #2 - Jan 22nd, 2015 at 2:14am
Print Post  
Hi Stoyan,
  Thanks for your help.but If I Press the Shift+UP key, the shapenode in Diagram always loses focus.
look, I just want to reach this effect:
1. when I press the UP key, the selected shapeNode move up whit 20 px.
2. when I press the Shift+UP key,the selected shapeNode move up whit 2 px.
I want to separate those functions.
thanks.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: how to use the UP,Down,Left,Right Key of the keyboard to move the node?
Reply #3 - Jan 22nd, 2015 at 9:08pm
Print Post  
Arrow keys will unselect a node to select adjacent one if you leave the default Diagram.Navigate* bindings shown in sample linked above and try to handle via other commands or KeyDown handler. They won't execute if you handle PreviewKeyDown though, so you can process both arrow and shift+arrow key from such PreviewKeyDown handler:

Code
Select All
private void OnDiagramKeyDown(object sender, KeyEventArgs e)
{
	var node = diagram.ActiveItem as DiagramNode;
	if (node == null)
		return;

	int amount = (Keyboard.Modifiers & ModifierKeys.Shift) != 0 ?
		2 : 20;

	int dx = 0;
	int dy = 0;

	if (e.Key == Key.Left)
		dx = -amount;
	else if (e.Key == Key.Right)
		dx = +amount;
	else if (e.Key == Key.Up)
		dy = -amount;
	else if (e.Key == Key.Down)
		dy = +amount;
	else
		return;

	var r = node.Bounds;
	r.Offset(dx, dy);
	node.Bounds = r;

	e.Handled = true;
} 



It should be possible to set this up via command bindings too, but it seems the ScrollViewer has its own command bindings for shift+arrow keys with higher-priority that prevents them from reaching to diagram. So if you want to use commands instead of PreviewKeyDown, you'd have to find and remove shift+arrow bindings from ScrollViewer's InputBindings first.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
heyx
Junior Member
**
Offline


I Love MindFusion!

Posts: 69
Joined: Oct 9th, 2014
Re: how to use the UP,Down,Left,Right Key of the keyboard to move the node?
Reply #4 - Jan 23rd, 2015 at 8:26am
Print Post  
Thanks Stoyan, It works.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint