Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a simple SSCCE. </p> <p>Edit: It might not be precisely what you wanted, now re-reading the question, but perhaps it can give you an idea of how to structure your filling tools. As for pixel-perfection, even MS Paint requires a complete closed drawing, where as other libraries might use degrees of antialias matching to avoid "leaks".</p> <p>XAML:</p> <pre><code>&lt;Window x:Class="FreeformDrawing.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" MouseLeftButtonDown="Window_MouseLeftButtonDown" MouseLeftButtonUp="Window_MouseLeftButtonUp" MouseMove="Window_MouseMove" Title="MainWindow" Height="400" Width="400"&gt; &lt;Grid&gt; &lt;Canvas x:Name="DrawingCanvas" /&gt; &lt;/Grid&gt; &lt;/Window&gt; </code></pre> <p>C#:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace FreeformDrawing { /// &lt;summary&gt; /// Interaction logic for MainWindow.xaml /// &lt;/summary&gt; public partial class MainWindow : Window { private Polygon polygon; private bool isDrawing = false; public MainWindow() { InitializeComponent(); } public void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (!isDrawing) { isDrawing = true; polygon = new Polygon() { Stroke = Brushes.Black, StrokeThickness = 1, StrokeMiterLimit = 1, StrokeLineJoin = PenLineJoin.Round, StrokeStartLineCap = PenLineCap.Round, StrokeEndLineCap = PenLineCap.Round }; AddPoint(e.GetPosition(DrawingCanvas)); DrawingCanvas.Children.Add(polygon); } } public void Window_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { isDrawing = false; if (polygon != null) { polygon.Points.Add(polygon.Points.First()); polygon.Fill = Brushes.Yellow; } } public void Window_MouseMove(object sender, MouseEventArgs e) { if (isDrawing) { AddPoint(e.GetPosition(DrawingCanvas)); } } private void AddPoint(Point value) { if (value.X &lt; (DrawingCanvas.ActualWidth - 1) &amp;&amp; value.Y &lt; (DrawingCanvas.ActualHeight - 1)) { polygon.Points.Add(value); } } } } </code></pre>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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