Note that there are some explanatory texts on larger screens.

plurals
  1. POfull fledged paint (drawing) application in metro style app
    primarykey
    data
    text
    <p>I am developing paint like application for windows 8. I have tried but I can't even developed a line drawing tool. My application will have free hand tool, line, rectangle, ellipse, circle drawing tool, eraser, saving the canvas content as JPG. I am using canvas tool for drawing. I am confused among the various "pointer" events. I have checked some samples of paint like application in WPF, but I am not able to completely port those applications.</p> <p>So please guide me with some coding, please provide me working code.</p> <p>Here I am attaching the sample code for line drawing. but in that line is constantly drawn, as there is no provision for checking whether the left mouse button is pressed or not.</p> <pre><code>&lt;!-- XAML CODE --&gt; &lt;Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}"&gt; &lt;StackPanel Orientation="Horizontal" Margin="0,-700,0,0" Grid.Row="0"&gt; &lt;Button x:Name="btnLine" Click="btnLine_Click" Height="50" Width="auto" Content="Line" Grid.Row="0"/&gt; &lt;Button x:Name="btnElipse" Click="btnElipse_Click" Height="50" Width="auto" Content="Elipse" Grid.Row="0"/&gt; &lt;Button x:Name="btnPencil" Click="btnPencil_Click" Height="50" Width="auto" Content="Pencil" Grid.Row="0"/&gt; &lt;/StackPanel&gt; &lt;Canvas Name="canvas" Background="AntiqueWhite" Margin="0,65,0,0"/&gt; </code></pre> <hr> <pre><code>/* C# Code*/ void canvas_PointerEntered(object sender, PointerRoutedEventArgs e) { switch (DrawingTool) { case "Line": { clickPoint = e.GetCurrentPoint(canvas).Position; newLine = new Line(); newLine.Fill = new SolidColorBrush(Windows.UI.Colors.Black); newLine.StrokeLineJoin = PenLineJoin.Bevel; newLine.X1 = clickPoint.X; newLine.Y1 = clickPoint.Y; newLine.X2 = clickPoint.X + 10; newLine.Y2 = clickPoint.Y + 10; newLine.StrokeThickness = 2; canvas.Children.Add(newLine); int zindex = canvas.Children.Count; Canvas.SetZIndex(newLine, zindex); } break; case "Pencil": { startPoint = e.GetCurrentPoint(canvas).Position; line = new Polyline(); line.Stroke = new SolidColorBrush(Windows.UI.Colors.Black); line.StrokeThickness = 2.0; canvas.Children.Add(line); } break; case "Ellipse": { newEllipse = new Ellipse(); newEllipse.StrokeThickness = 2; newEllipse.Stroke = new SolidColorBrush(Windows.UI.Colors.Black); newEllipse.StrokeLineJoin = PenLineJoin.Bevel; newEllipse.Width = clickPoint.X; newEllipse.Height = clickPoint.Y; canvas.Children.Add(newEllipse); } break; default: break; } } void canvas_PointerMoved(object sender, PointerRoutedEventArgs e) { switch (DrawingTool) { case "Pencil": { if (true) { Point currentPoint = e.GetCurrentPoint(canvas).Position; if (startPoint != currentPoint) { line.Points.Add(currentPoint); } } } break; case "Line": { drawPoint = e.GetCurrentPoint(canvas).Position; ; if (newLine != null) { newLine.X2 = drawPoint.X; newLine.Y2 = drawPoint.Y; } } break; default: break; } } void canvas_PointerReleased(object sender, PointerRoutedEventArgs e) { newLine = null; } string DrawingTool; Line newLine; Ellipse newEllipse; Point clickPoint; Point drawPoint; Point startPoint; Polyline line; /// &lt;summary&gt; /// Invoked when this page is about to be displayed in a Frame. /// &lt;/summary&gt; /// &lt;param name="e"&gt;Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.&lt;/param&gt; protected override void OnNavigatedTo(NavigationEventArgs e) { } private void btnPencil_Click(object sender, RoutedEventArgs e) { DrawingTool = "Pencil"; } private void btnLine_Click(object sender, RoutedEventArgs e) { DrawingTool = "Line"; } private void btnElipse_Click(object sender, RoutedEventArgs e) { DrawingTool = "Ellipse"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload