Feature Request: Ability to draw straight lines

Nov 2, 2007 at 9:41 AM
I would find it very helpful if I could hold the shift or ctrl or alt key down and have NLarge draw a straight line when I draw with the mouse. I would also find it helpful to draw an ellipse instead of my rather tragic attempts that just end up looking like scribble.
Coordinator
Mar 27, 2008 at 8:09 PM

gsmithferrier wrote:
I would find it very helpful if I could hold the shift or ctrl or alt key down and have NLarge draw a straight line when I draw with the mouse. I would also find it helpful to draw an ellipse instead of my rather tragic attempts that just end up looking like scribble.

It's a really good idea. I'm using the InkCanvas for drawing. Maybe someone could figure out how to make the InkCanvas draw a straight line?
Jun 2, 2008 at 3:30 PM
I know this is late, but I just stumbled across this thread, figured I'd answer the question...

If you want to constrain your InkCanvas to draw straight lines, the simplest thing to do (assuming you want to constrain to horizontal and/or vertical lines) is to use the gesture system.  So, you start by setting your InkCanvas.EditingMode to "InkAndGesture" and then you SetEnabledGestures to just "Right","Left","Up","Down" ...

                myInkCanvas.EditingMode = InkCanvasEditingMode.InkAndGesture;
                //  The gestures in which the application is interested are enabled here.
                myInkCanvas.SetEnabledGestures(new ApplicationGesture[] {
                ApplicationGesture.Up, ApplicationGesture.Down, ApplicationGesture.Left, ApplicationGesture.Right });
                // Hook up the "Gesture" event.
                myInkCanvas.Gesture += new InkCanvasGestureEventHandler(InkCanvas_Gesture);

In the Gesture event, you need to handle these something like this:

            GestureRecognitionResult topResult = e.GetGestureRecognitionResults()[0];
            if (topResult.RecognitionConfidence == RecognitionConfidence.Strong)
            {
                ApplicationGesture gesture = topResult.ApplicationGesture;
                switch (gesture)
                {

          // basically, each of them looks something like this:
           case ApplicationGesture.Right {
               // You're hodling CTRL to draw straight lines
               if( System.Windows.Input.Keyboard.Modifiers && System.Windows.Input.ModifierKeys.Control == System.Windows.Input.ModifierKeys.Control ) {
                  System.Windows.Input.StylusPointCollection points = new System.Windows.Input.StylusPointCollection();
                  points.Add( new System.Windows.Input.StylusPoint(  e.strokes[0].StylusPoints[0].X, e.strokes[0].StylusPoints[0].Y ) )
                  points.Add( new System.Windows.Input.StylusPoint( e.strokes.GetBounds().Right, e.strokes[0].StylusPoints[0].Y  ) )

                  myInkCanvas.Strokes.Add( new System.Windows.Ink.Stroke( points, e.strokes[0].DrawingAttributes ) )
               } else {
                  e.Cancel = true
               }
           }
Apr 8, 2009 at 7:41 PM
Modified the code to include the above. Quite easy to do and it works well on 2008 (and Vista, I assume). I had to add some error handling for XP as the calls to the Ink routines throw an exception.
May 4, 2014 at 2:23 AM
Hi gsmithferrier,

It's not that hard to draw straight lines, you simply need to set the line properties and specify a target location for it. Here's a detailed guide to draw line annotation. Hope that'll help!

Cheers,
Derek