| |

VerySource

 Forgot password?
 Register
Search
View: 584|Reply: 4

C # new line drawing problem,

[Copy link]

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-2-11 15:30:01
| Show all posts |Read mode
Ask you,
// Code 1
Graphic g = panel.CreateGraphics ();
g.DrawEllipse (new Pen (Color.Red), 50, 50, Math.Abs ​​(MousePoint.X-50), Math.Abs ​​(MousePoint.Y-50));
The result of this will be that the place the mouse walks over becomes red, that is, many circles are drawn, but in fact I only need one.
If you modify the code:
// Code 2
Graphic g = panel.CreateGraphics ();
if (oldPoint! = Point.Empty)
  g.DrawEllipse (new Pen (panel.BackColor), 50, 50, Math.Abs ​​(MousePoint.X-50), Math.Abs ​​(MousePoint.Y-50));
g.DrawEllipse (new Pen (Color.Red), 50, 50, Math.Abs ​​(MousePoint.X-50), Math.Abs ​​(MousePoint.Y-50));
This is correct, but if the background painting is added to the control, the effect is almost the same as above, but the color is different, and the background painting is not visible.

Ask you how to write the code, but you can't do it in the Paint event of the control.
Thank you in advance for your help
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-4-9 16:30:01
| Show all posts
When you draw, you must first remove your original drawing area, or send Invalidate to redraw the area you have already drawn
Reply

Use magic Report

1

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

 Author| Post time: 2020-4-11 21:30:02
| Show all posts
njuwelkindoesn't feel very good, when drawing, it flickers very badly
Reply

Use magic Report

0

Threads

9

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-4-12 13:15:01
| Show all posts
Clear the screen before painting each time
Reply

Use magic Report

0

Threads

13

Posts

9.00

Credits

Newbie

Rank: 1

Credits
9.00

 China

Post time: 2020-5-27 18:45:01
| Show all posts
Or you can draw to the cache first (for example to Bitmap), and finally to the display device
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list