Note that there are some explanatory texts on larger screens.

plurals
  1. POIn a PictureBox, drawing a temporary circle on mouse down, to follow the mouse, until the mouseUp event is detected
    primarykey
    data
    text
    <p>I'm really new to drawing in C#, and I'm using Windows Forms instead of WPF, so maybe I'm doing it wrong from the get-go... you tell me... but I'd like to have a temporary marker put down on the PictureBox (on MouseDown) that will follow the mouse (erasing the previous drawings of itself, i.e. not leaving a trail), and then being drawn in the final position on the MouseUp event.</p> <p>Here's some skeleton code that you guys can fill in:</p> <pre><code>bool mDown; Graphics g; // initialized to pictureBox1.CreateGraphics() on Form_Load, though // I am unsure how that differs from Graphics.FromImage(pictureBox1) SolidBrush sbGray, sbGreen; private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { mDown = true; // store/push initial drawing g.FillEllipse(sbGray, e.X - 5, e.Y - 5, 10, 10); } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (mDown) { // restore/pop initial drawing, erasing old trail g.FillEllipse(sbGray, e.X - 5, e.Y - 5, 10, 10); } } private void pictureBox1_MouseClick(object sender, MouseEventArgs e) { // restore/pop initial drawing, erasing old trail g.FillEllipse(sbGreen, e.X - 5, e.Y - 5, 10, 10); mDown = false; } </code></pre> <p>I suppose there are several ways to skin a cat, such as changing the mouse icon, so perhaps this is not even the best way to do it? Even so, I will probably need to know the answers to both questions -- whether there is a better way to do it, and also how to extract the graphics from a PictureBox (as this knowledge will most likely prove useful later anyways.)</p> <p>(Note: Although the gray circles should erase themselves, the green circles should be persistent and multiple green circles should be capable of existing in the PictureBox at the same time.)</p>
    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.
 

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