Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try this... It is a stroke drawing method, implemented very simply and as close to your own code as possible. Stokes are individual collections of mouse movements. Every mouse move between down and up is recorded as a stroke, all the strokes are collected and then redrawn whenever the paint event is fired. This example is simple but could be a good starting point. </p> <p><em>Note that you will have to add the paint handler for your chart object.</em></p> <pre><code>using System; using System.Collections.Generic; using System.Drawing; using System.Windows.Forms; using System.Drawing.Drawing2D; namespace Grafi { public partial class Form1 : Form { bool isDrawing; // our collection of strokes for drawing List&lt;List&lt;Point&gt;&gt; _strokes = new List&lt;List&lt;Point&gt;&gt;(); // the current stroke being drawn List&lt;Point&gt; _currStroke; // our pen Pen _pen = new Pen(Color.Red, 2); public Form1() { InitializeComponent(); } private void chartTemperature_MouseDown(object sender, MouseEventArgs e) { isDrawing = true; // mouse is down, starting new stroke _currStroke = new List&lt;Point&gt;(); // add the initial point to the new stroke _currStroke.Add(e.Location); // add the new stroke collection to our strokes collection _strokes.Add(_currStroke); } private void chartTemperature_MouseMove(object sender, MouseEventArgs e) { if (isDrawing) { // record stroke point if we're in drawing mode _currStroke.Add(e.Location); Refresh(); // refresh the drawing to see the latest section } } private void chartTemperature_MouseUp(object sender, MouseEventArgs e) { isDrawing = false; } private void chartTemperature_Paint(object sender, PaintEventArgs e) { // now handle and redraw our strokes on the paint event e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; foreach (List&lt;Point&gt; stroke in _strokes.Where(x =&gt; x.Count &gt; 1)) e.Graphics.DrawLines(_pen, stroke.ToArray()); } } } </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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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