Hi Stoyan,
Here is the code for all the things I do:
[code]
public partial class Form1 : Form { private Timer t;
private bool arrowKeyDown; private List<Keys> keyDown; private List<Keys> keyUp;
public Form1() { InitializeComponent(); }
private void Form1_Load(object sender, EventArgs e) { ShapeNode shape = new ShapeNode(this.diagram1); this.diagram1.Nodes.Add(shape); shape.Image = null;
shape.Move(50, 50);
this.diagram1.Selection.Change(shape);
t = new Timer(); t.Interval = 300; t.Tick += new EventHandler(time_Tick); }
private void time_Tick(object sender, EventArgs e) { t.Stop();
List<int> downKeysASCII = this.keyDown.Select(p => (int)p).Distinct().OrderBy(p => p).ToList(); List<int> upKeysASCII = this.keyUp.Select(p => (int)p).Distinct().OrderBy(p => p).ToList();
if (downKeysASCII.SequenceEqual(upKeysASCII) && this.diagram1.Interaction != null) { arrowKeyDown = false; Console.WriteLine("Save");
DiagramNode firstNode = this.diagram1.Selection.Nodes[0]; this.diagram1.Interaction.Complete(firstNode.GetCenter(), this.diagram1);
this.diagram1.Interaction = null;
this.diagram1.Invalidate(); } }
private void diagramView1_KeyDown(object sender, KeyEventArgs e) { this.keyDown.Add(e.KeyData);
if (arrowKeyDown) { DiagramNode firstNode = this.diagram1.Selection.Nodes[0]; PointF firstNodeCenter = firstNode.GetCenter();
if (e.KeyCode == Keys.Right) { firstNodeCenter.X += 4; } if (e.KeyCode == Keys.Left) { firstNodeCenter.X -= 4; } if (e.KeyCode == Keys.Down) { firstNodeCenter.Y += 4; } if (e.KeyCode == Keys.Up) { firstNodeCenter.Y -= 4; }
Cursor.Position = diagramView1.PointToScreen(this.diagramView1.DocToClient(firstNodeCenter));
//uint lParam = MakeLong(Cursor.Position.X, Cursor.Position.Y); //SendMessage(this.diagramView1.Handle, (int)Msgs.WM_MOUSEMOVE, 0, lParam);
// Cursor.Position = newCursorPosition;
if (e.KeyData == Keys.Escape) { this.diagram1.Interaction.Cancel(this.diagram1); this.diagram1.Interaction = null; arrowKeyDown = false; } else { this.diagram1.Interaction.Update(firstNodeCenter, this.diagram1); bool allowModify = this.diagram1.Interaction.IsAllowed(firstNodeCenter); }
this.diagram1.Invalidate(); } }
private void diagramView1_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e) { if (this.diagram1.Selection.Nodes.Count > 0 && (e.KeyCode == Keys.Right || e.KeyCode == Keys.Left || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)) { if (!arrowKeyDown) { DiagramNode firstNode = this.diagram1.Selection.Nodes[0];
Point newCursorPosition = this.diagramView1.PointToScreen(this.diagramView1.DocToClient(firstNode.GetCenter()));
Console.WriteLine("start interaction");
uint lParam = MakeLong(Cursor.Position.X, Cursor.Position.Y); //SendMessage(this.diagramView1.Handle, (int)Msgs.WM_LBUTTONDOWN, 0, lParam);
Cursor.Position = newCursorPosition;
this.diagram1.Interaction = new InteractionState(firstNode, 8, MindFusion.Diagramming.Action.Modify); this.diagram1.Interaction.Start(firstNode.GetCenter(), diagram1);
this.keyUp = new List<Keys>(); this.keyDown = new List<Keys>(); }
arrowKeyDown = true;
e.IsInputKey = true; t.Stop(); } }
private uint MakeLong(int low, int high) { return (uint)((high << 16) + low); }
private void diagramView1_KeyUp(object sender, KeyEventArgs e) { this.keyUp.Add(e.KeyData);
if (this.diagram1.Selection.Nodes.Count > 0 && (e.KeyCode == Keys.Right || e.KeyCode == Keys.Left || e.KeyCode == Keys.Up || e.KeyCode == Keys.Down)) { t.Start(); } } }
[/code]
This is all the code there is in the application.
Regards, Dexter
|