Snap to grid when holding CTRL and moving shape with mouse

Apr 1, 2014 at 8:38 AM

Is it possible to enable "snap to grid" function when holding down CTRL and dragging the shape with mouse? I've tried with handling Digram.KeyDown/KeyUp events, but it doesn't work as expected.

Here is the code:
        private void display1_KeyDown(object sender, KeyEventArgs e)
            if (e.Control && !e.Alt && !e.Shift)
                this.display1.SnapToGrid = true;

        private void display1_KeyUp(object sender, KeyEventArgs e)
            this.display1.SnapToGrid = false;
Apr 1, 2014 at 11:16 AM
Edited Apr 1, 2014 at 2:05 PM
The control key is currently implemented as override key for not snapping to grid when pressed.
We will discuss about changing the behavior when pressing CTRL from "do not snap" to "toggle snapping".

As solution, you can derive your own display and override the SnapToGrid property:
public new bool SnapToGrid {
    get { 
        if ((Control.ModifierKeys & (Keys.Control | Keys.ControlKey)) == 0) 
            return snapToGrid;
        else return !snapToGrid; 
Marked as answer by zmanbb on 5/15/2014 at 10:37 PM
May 7, 2014 at 8:21 AM
Update: In NShape 2.2.0, the control key toggles the 'Snap to Grid' feature instead of allways deactivating it.
Marked as answer by zmanbb on 5/15/2014 at 10:37 PM
May 16, 2014 at 5:37 AM
Great! Thank you.