Dim p As New StylusPointCollection() p.Add(New StylusPoint(10, 10)) p.Add(New StylusPoint(70, 10)) p.Add(New StylusPoint(70, 70)) p.Add(New StylusPoint(10, 10)) InkCanvas1.Strokes.Add(New System.Windows.Ink.Stroke(p))
Private Sub Window1_Loaded(ByVal sender As Object, _ ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded InkCanvas1.EditingMode = InkCanvasEditingMode.None End Sub Private ellipse As Ellipse Private LeftTop As Point Private Sub InkCanvas1_MouseDown(ByVal sender As Object, _ ByVal e As System.Windows.Input.MouseButtonEventArgs _ ) Handles InkCanvas1.MouseDown ellipse = New Ellipse() LeftTop = e.GetPosition(InkCanvas1) ellipse.SetValue(InkCanvas.LeftProperty, LeftTop.X) ellipse.SetValue(InkCanvas.TopProperty, LeftTop.Y) ellipse.Width = 1.0# ellipse.Height = 1.0# ellipse.Fill = New SolidColorBrush(Colors.Blue) InkCanvas1.Children.Add(ellipse) End Sub Private Sub InkCanvas1_MouseMove(ByVal sender As Object, _ ByVal e As System.Windows.Input.MouseEventArgs _ ) Handles InkCanvas1.MouseMove If ellipse IsNot Nothing Then Dim p As Point = e.GetPosition(InkCanvas1) Dim w As Double = p.X - LeftTop.X Dim h As Double = p.Y - LeftTop.Y ellipse.Width = If(w <= 0.1#, 0.1#, w) ellipse.Height = If(h <= 0.1#, 0.1#, h) End If End Sub Private Sub InkCanvas1_MouseUp(ByVal sender As Object, _ ByVal e As System.Windows.Input.MouseButtonEventArgs _ ) Handles InkCanvas1.MouseUp If ellipse IsNot Nothing Then ellipse = Nothing End If End Sub