We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Move symbols programmatically...

Hello, I would like to write an EventHandler to process KeyDown-Events and to move selected shapes with arrow keys on the keyboard. I''ve tried out following: this.diagramComponent = new Syncfusion.Windows.Forms.Diagram.Controls.Diagram(); this.Controls.Add(this.diagramComponent); this.diagramComponent.KeyDown += new System.Windows.Forms.KeyEventHandler(this.diagramComponent _KeyDown); private void diagramComponent_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e) { switch(e.KeyCode) { case Keys.Up: Syncfusion.Windows.Forms.Diagram.NodeCollection selNodes = new NodeCollection(); selNodes = this.diagramComponent.SelectionList; foreach (INode curNode in selNodes) { string childName = curNode.FullName; Syncfusion.Windows.Forms.Diagram.INode tmpNode; tmpNode = this.diagramComponent.Model.GetChildByName(childName); Syncfusion.Windows.Forms.Diagram.MoveCmd moveNodes = new MoveCmd(0, 1); moveNodes.Nodes.Add(tmpNode); } break; case Keys.Down: MessageBox.Show("DOWN"); break; case Keys.Left: MessageBox.Show("LEFT"); break; case Keys.Right: MessageBox.Show("RIGHT"); break; } base.OnKeyDown (e); } But nothing is happened. I guess there is either something wrong with EventHandler or this is the wrong way to move symbols. Has anybody already solved a similar issue like this one?

6 Replies

MF Meera Fathima Syncfusion Team October 28, 2005 05:55 AM UTC

Hi, You can do this by overriding the ProcessCmdKey() method. This will let you have the control on the keyboard inputs. If your intension is to move the selected symbol then you can directly add the selected symbol to the MoveNodesCmd class. And after the node is added you need to execute the command.The following sample code snippet shows how to go about it, protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { switch(keyData) { case Keys.Up: Syncfusion.Windows.Forms.Diagram.NodeCollection selNodes = new NodeCollection(); selNodes = this.diagram.SelectionList; foreach (INode curNode in selNodes) { Syncfusion.Windows.Forms.Diagram.MoveCmd moveNodes = new MoveCmd(0,1); moveNodes.Nodes.Add(curNode); this.diagram.Controller.ExecuteCommand(moveNodes); } break; case Keys.Down: MessageBox.Show("DOWN"); break; case Keys.Left: MessageBox.Show("LEFT"); break; case Keys.Right: MessageBox.Show("RIGHT"); break; } return base.ProcessCmdKey (ref msg, keyData); } The other way to go about this would be customizing the Diagram control and overriding KeyUp,KeyBown and KeyPress methods with the necessary implementation in that derived class. I hope the above information will help you. Thanks and Regards, Meera.


AR Alexander Riske October 28, 2005 03:07 PM UTC

Thank you Meera, It works fine, the symbol’s does really moves! But since overriding Proceed-Method of the form it is not possible to use arrow keys into a TextBox anymore. How could I avoid that?


MF Meera Fathima Syncfusion Team October 31, 2005 05:58 AM UTC

Hi, Thanks for the update. I have tested overriding the ProcessCmd() method for Textbox. It works as expected. You can also use KeyUp,KeyDown or KeyPress handler for the Textbox which will let you have the control on the keyboard arrow keys. Please let me know if you run with any problem. We will be glad to assist you. Thanks for your support to Syncfusion. Regards, Meera.


AR Alexander Riske November 3, 2005 04:51 PM UTC

>>"The other way to go about this would be >>customizing the Diagram control and overriding >>KeyUp,KeyBown and KeyPress methods with the >>necessary implementation in that derived >>class." I''ve tried out this method, but I wasn''t sucessfull:( Could you please help me with some advice.


MF Meera Fathima Syncfusion Team November 7, 2005 09:39 AM UTC

Hi, Kindly look at the following code snippet that shows how to sub class the diagram control and navigate the keyboard arrow keys. public class MyDiagram : Syncfusion.Windows.Forms.Diagram.Controls.Diagram { public MyDiagram() { } // KeyDown event is not raised for the Arrow keys unless an override of the Control.IsInputKey method returns a TRUE value for the particular key. protected override bool IsInputKey(Keys keyData) { switch(keyData) { case Keys.Up: case Keys.Left: case Keys.Down: case Keys.Right: return true; } return base.IsInputKey(keyData); } protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown (e); if (e.KeyValue ==40) // KeyValue for DOWN arrow key { Syncfusion.Windows.Forms.Diagram.NodeCollection selNodes = new NodeCollection(); selNodes = this.Controller.SelectionList; foreach (INode curNode in selNodes) { Syncfusion.Windows.Forms.Diagram.MoveCmd moveNodes = new MoveCmd(0, 1); moveNodes.Nodes.Add(curNode); this.Controller.ExecuteCommand(moveNodes); this.Controller.UpdateAllViews(); } } } } In the MainForm.cs create an instance for this MyDiagram class instead of creating the instance for the Syncfusion.Windows.Forms.Diagram.Controls.Diagramclass. I hope the above informations will help you on how to go about this. Thanks for your continued support. Best Regards, Meera.


AD Administrator Syncfusion Team November 7, 2005 11:43 AM UTC

Thank you Meera, It works great! >>"KeyDown event is not raised for the Arrow keys unless an override of the Control.IsInputKey method returns a TRUE value for the particular key." - That''s the key, this is the knowhow I missed...

Loader.
Live Chat Icon For mobile
Up arrow icon