Title | Make a scribble application with XAML in Visual Basic 2008 |
Description | This example shows how to make a scribble application with XAML in Visual Basic 2008. |
Keywords | XAML, WPF, Visual Basic 2008, scribble, drawing |
Categories | Graphics |
|
|
When the user presses the left mouse button, the following code creates a new Polyline object. The Stroke property determines how the ellipse's border is drawn.
The call to e.GetPosition returns the mouse position relative to the control you pass it, in this case the Canvas canScribble. The code adds a Point to the Polyline recording the mouse's current position.
After creating the Polyline, the code adds it to the Canvas control canScribble.
|
|
Private new_polyline As Polyline = Nothing
' Start drawing.
Private Sub canScribble_MouseLeftButtonDown(ByVal sender As _
Object, ByVal e As _
System.Windows.Input.MouseButtonEventArgs) Handles _
canScribble.MouseLeftButtonDown
' Create a new Polygon object.
new_polyline = New Polyline()
new_polyline.Points.Add(e.GetPosition(canScribble))
new_polyline.Stroke = Brushes.Red
' Add the object to the canvas.
canScribble.Children.Add(new_polyline)
End Sub
|
|
When the mouse moves, the following code adds the mouse's current position to the Polyline's Points collection.
|
|
' Continue drawing. Add a new point to the Polyline.
Private Sub canScribble_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Input.MouseEventArgs) Handles _
canScribble.MouseMove
If new_polyline IsNot Nothing Then
new_polyline.Points.Add(e.GetPosition(canScribble))
End If
End Sub
|
|
When the user releases the left mouse button, the following code sets new_polyline to Nothing so future MouseMove events don't add new points to it.
|
|
' Stop drawing.
Private Sub canScribble_MouseLeftButtonUp(ByVal sender As _
Object, ByVal e As _
System.Windows.Input.MouseButtonEventArgs) Handles _
canScribble.MouseLeftButtonUp
new_polyline = Nothing
End Sub
|
|
|
|