/// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnStrokeEraseResultChanged(object sender, StrokeHitEventArgs e)
        {
            Debug.Assert(null != e.HitStroke);

            bool fSucceeded = false;

            // The below code calls out StrokeErasing or StrokeErased event.
            // The out-side code could throw exception.
            // We use try/finally block to protect our status.
            try
            {
                InkCanvasStrokeErasingEventArgs args = new InkCanvasStrokeErasingEventArgs(e.HitStroke);
                this.InkCanvas.RaiseStrokeErasing(args);

                if (!args.Cancel)
                {
                    // Erase only if the event wasn't cancelled
                    InkCanvas.Strokes.Remove(e.HitStroke);
                    this.InkCanvas.RaiseInkErased();
                }

                fSucceeded = true;
            }
            finally
            {
                if (!fSucceeded)
                {
                    // Abort the editing.
                    Commit(false);
                }
            }
        }
Ejemplo n.º 2
0
        private void EraserTester_StrokeHit(object sender, StrokeHitEventArgs e)
        {
            StrokeCollection eraseResult = e.GetPointEraseResults();

            Console.WriteLine("Strokes eraseResult: " + eraseResult.Count);
            StrokeCollection strokesToReplace = new StrokeCollection();

            strokesToReplace.Add(e.HitStroke);

            // Replace the old stroke with the new one.
            if (eraseResult.Count > 0)
            {
                Console.WriteLine("LETS REPLACE");
                surfaceDessin.Strokes.Replace(strokesToReplace, eraseResult);
            }
        }
        // Token: 0x06006D6C RID: 28012 RVA: 0x001F6ABC File Offset: 0x001F4CBC
        private void OnPointEraseResultChanged(object sender, StrokeHitEventArgs e)
        {
            bool flag = false;

            try
            {
                InkCanvasStrokeErasingEventArgs inkCanvasStrokeErasingEventArgs = new InkCanvasStrokeErasingEventArgs(e.HitStroke);
                base.InkCanvas.RaiseStrokeErasing(inkCanvasStrokeErasingEventArgs);
                if (!inkCanvasStrokeErasingEventArgs.Cancel)
                {
                    StrokeCollection pointEraseResults = e.GetPointEraseResults();
                    StrokeCollection strokeCollection  = new StrokeCollection();
                    strokeCollection.Add(e.HitStroke);
                    try
                    {
                        if (pointEraseResults.Count > 0)
                        {
                            base.InkCanvas.Strokes.Replace(strokeCollection, pointEraseResults);
                        }
                        else
                        {
                            base.InkCanvas.Strokes.Remove(strokeCollection);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        if (!ex.Data.Contains("System.Windows.Ink.StrokeCollection"))
                        {
                            throw;
                        }
                    }
                    base.InkCanvas.RaiseInkErased();
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    base.Commit(false);
                }
            }
        }
Ejemplo n.º 4
0
    // When the stylus intersects a stroke, erase that part of
    // the stroke.  When the stylus dissects a stoke, the
    // Stroke.Erase method returns a StrokeCollection that contains
    // the two new strokes.
    void eraseTester_StrokeHit(object sender,
                               StrokeHitEventArgs args)
    {
        StrokeCollection eraseResult =
            args.GetPointEraseResults();
        StrokeCollection strokesToReplace = new StrokeCollection();

        strokesToReplace.Add(args.HitStroke);

        // Replace the old stroke with the new one.
        if (eraseResult.Count > 0)
        {
            presenter.Strokes.Replace(strokesToReplace, eraseResult);
        }
        else
        {
            presenter.Strokes.Remove(strokesToReplace);
        }
    }
        // Token: 0x06006D6B RID: 28011 RVA: 0x001F6A4C File Offset: 0x001F4C4C
        private void OnStrokeEraseResultChanged(object sender, StrokeHitEventArgs e)
        {
            bool flag = false;

            try
            {
                InkCanvasStrokeErasingEventArgs inkCanvasStrokeErasingEventArgs = new InkCanvasStrokeErasingEventArgs(e.HitStroke);
                base.InkCanvas.RaiseStrokeErasing(inkCanvasStrokeErasingEventArgs);
                if (!inkCanvasStrokeErasingEventArgs.Cancel)
                {
                    base.InkCanvas.Strokes.Remove(e.HitStroke);
                    base.InkCanvas.RaiseInkErased();
                }
                flag = true;
            }
            finally
            {
                if (!flag)
                {
                    base.Commit(false);
                }
            }
        }
Ejemplo n.º 6
0
        // When the stylus clips a stroke,
        // delete that stroke.
        // When the stylus erases a stoke,
        // replace the stroke with the strokes returned by
        // the Stroke.Erase method.
        void myIHT_StrokeIntersectionChanged(object sender, StrokeHitEventArgs e)
        {
            Stroke thisStroke = e.HitStroke;

            // <Snippet11>
            Rect myRect = thisStroke.GetBounds();

            // </Snippet11>

            if (state == sMode.clip)
            {
                // ***Stroke.Clip***
                // <Snippet4>
                // Get the intersections when the stroke is clipped.
                // e is a StrokeIntersectionChangedEventArgs object in the
                // StrokeIntersectionChanged event handler.
                StrokeCollection clipResult = e.GetPointEraseResults();

                StrokeCollection strokesToReplace = new StrokeCollection();

                strokesToReplace.Add(thisStroke);

                // Replace the old stroke with the new one.
                if (clipResult.Count > 0)
                {
                    myInkPresenter.Strokes.Replace(strokesToReplace, clipResult);
                }
                else
                {
                    myInkPresenter.Strokes.Remove(strokesToReplace);
                }
                // </Snippet4>

                if (!gotFirstStroke)
                {
                    // <Snippet3>
                    // Create a guid for the date/timestamp.
                    Guid dtGuid = new Guid("03457307-3475-3450-3035-640435034540");

                    DateTime now = DateTime.Now;

                    // Check whether the property is already saved
                    if (thisStroke.ContainsPropertyData(dtGuid))
                    {
                        // Check whether the existing property matches the current date/timestamp
                        DateTime oldDT = (DateTime)thisStroke.GetPropertyData(dtGuid);

                        if (oldDT != now)
                        {
                            // Update the current date and time
                            thisStroke.AddPropertyData(dtGuid, now);
                        }
                    }
                    // </Snippet3>

                    // <Snippet30>
                    // Create a guid for the date/timestamp.
                    Guid dateTimeGuid = new Guid("03457307-3475-3450-3035-045430534046");

                    DateTime current = DateTime.Now;

                    // Check whether the property is already saved
                    if (thisStroke.ContainsPropertyData(dateTimeGuid))
                    {
                        DateTime oldDateTime = (DateTime)thisStroke.GetPropertyData(dateTimeGuid);

                        // Check whether the existing property matches the current date/timestamp
                        if (!(oldDateTime == current))
                        {
                            // Delete the custom property
                            thisStroke.RemovePropertyData(dateTimeGuid);
                        }
                    }
                    // </Snippet30>

                    // <Snippet12>
                    // Save the stroke as an array of Point objects
                    //Point[] myPoints = thisStroke.GetRenderingPoints();
                    // </Snippet12>

                    // Port to VB if I ever get this working!
                    // See if we can figure out which stroke point(s) got hit
                    //StrokeIntersection[] myStrokeIntersections = e.GetHitStrokeIntersections();

                    //Point[] myStrokeIntersectionPoints = new Point[myStrokeIntersections.Length];

                    //int p = 0;

                    //for (int k = 0; k < myStrokeIntersections.Length; k++)
                    //{
                    //    StrokeIntersection s = myStrokeIntersections[k];

                    //    if (s.HitBegin != StrokeIntersection.BeforeFirst && s.HitEnd != StrokeIntersection.        AfterLast)
                    //    {
                    //        // Get stroke point that is closest to average between HitBegin and HitEnd:
                    //        double x = s.HitBegin;
                    //        double y = s.HitEnd;

                    //        double midPoint = (x + y) / 2;

                    //        int middlePoint = (int)midPoint;

                    //        // Now add that Point from the existing stroke points
                    //        myStrokeIntersectionPoints[p] = myPoints[middlePoint];

                    //        p++;
                    //    }

                    //}

                    // Get DrawingContext for InkPresenter
                    //VisualCollection myVisuals = VisualOperations.GetChildren(myInkPresenter);

                    //DrawingVisual myVisual = new DrawingVisual();
                    //DrawingContext myContext = myVisual.RenderOpen();

                    //// Draw midpoints of stroke intersections a little green circles
                    //for (int j = 0; j < myStrokeIntersectionPoints.Length; j++)
                    //{
                    //    // Draw green circles around each point
                    //    myContext.DrawGeometry(Brushes.Green,
                    //        new Pen(Brushes.Green, 1.0),
                    //        new EllipseGeometry(myStrokeIntersectionPoints[j], 4.0, 4.0));
                    //}

                    //myContext.Close();
                    //myVisuals.Add(myVisual);


                    // Do I have to do something here to display the revised InkPresenter?


                    // Open the file to hold strokes
                    // if the file already exists, overwrite it
                    //myFile = new StreamWriter(File.Open(STROKE_FILE, FileMode.Create));

                    //Point myPoint;

                    //int xVal, yVal;

                    //for (int i = 0; i < myPoints.Length; i++)
                    //{
                    //    myPoint = myPoints[i];

                    //    xVal = (int)myPoint.X;
                    //    yVal = (int)myPoint.Y;

                    //    // Save the point to a file
                    //    myFile.WriteLine(xVal.ToString() + " " + yVal.ToString());
                    //}

                    //myFile.Flush();
                    //myFile.Close();

                    //gotFirstStroke = true;
                }
            }
            else
            {
                // ***erase**
                // <Snippet10>
                // Remove the stokee that is hit.
                myInkPresenter.Strokes.Remove(e.HitStroke);
                // </Snippet10>
            }
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnPointEraseResultChanged(object sender, StrokeHitEventArgs e)
        {
            Debug.Assert(null != e.HitStroke, "e.HitStroke cannot be null");

            bool fSucceeded = false;

            // The below code might call out StrokeErasing or StrokeErased event.
            // The out-side code could throw exception.
            // We use try/finally block to protect our status.
            try
            {
                InkCanvasStrokeErasingEventArgs args = new InkCanvasStrokeErasingEventArgs(e.HitStroke);
                this.InkCanvas.RaiseStrokeErasing(args);

                if (!args.Cancel)
                {
                    // Erase only if the event wasn't cancelled
                    StrokeCollection eraseResult = e.GetPointEraseResults();
                    Debug.Assert(eraseResult != null, "eraseResult cannot be null");

                    StrokeCollection strokesToReplace = new StrokeCollection();
                    strokesToReplace.Add(e.HitStroke);

                    try
                    {
                        // replace or remove the stroke
                        if (eraseResult.Count > 0)
                        {
                            this.InkCanvas.Strokes.Replace(strokesToReplace, eraseResult);
                        }
                        else
                        {
                            this.InkCanvas.Strokes.Remove(strokesToReplace);
                        }
                    }
                    catch (ArgumentException ex)
                    {
                        //this can happen if someone sits in an event handler
                        //for StrokeErasing and removes the stroke.
                        //this to harden against failure here.
                        if (!ex.Data.Contains("System.Windows.Ink.StrokeCollection"))
                        {
                            //System.Windows.Ink.StrokeCollection didn't throw this,
                            //we need to just throw the original exception
                            throw;
                        }
                    }


                    //raise ink erased
                    this.InkCanvas.RaiseInkErased();
                }

                fSucceeded = true;
            }
            finally
            {
                if (!fSucceeded)
                {
                    // Abort the editing.
                    Commit(false);
                }
            }
        }
Ejemplo n.º 8
0
 private void IncrementalStrokeHitTester_StrokeHit(object sender, StrokeHitEventArgs e)
 {
     InkCanvas.Strokes.Remove(e.HitStroke);
     InkCanvas.Strokes.Add(e.GetPointEraseResults());
 }