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.
Unfortunately, activation email could not send to your email. Please try again.

Move symbols programmatically...

Thread ID:

Created:

Updated:

Platform:

Replies:

36354 Oct 27,2005 10:03 AM Nov 7,2005 06:43 AM Windows Forms 6
loading
Tags: Diagram
Alexander Riske
Asked On October 27, 2005 10:03 AM

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?

Meera Fathima [Syncfusion]
Replied On October 28, 2005 01:55 AM

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.

Alexander Riske
Replied On October 28, 2005 11:07 AM

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?

Meera Fathima [Syncfusion]
Replied On October 31, 2005 12:58 AM

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.

Alexander Riske
Replied On November 3, 2005 11:51 AM

>>"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.

Meera Fathima [Syncfusion]
Replied On November 7, 2005 04:39 AM

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.

Administrator [Syncfusion]
Replied On November 7, 2005 06:43 AM

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...

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;