简体   繁体   中英

C# Test if there is already something drawn where I am going to draw

I am trying to make a test to see if I have already drawn something where I am going to draw.

My drawing code:

Graphics g = panel1.CreateGraphics();
SolidBrush brush = new SolidBrush(Color.Blue);
// Want my test to be here here
g.FillEllipse(brush, playerX-3, playerY-3, 6, 6);

g.Dispose();

Realistically you cannot do this the way you think you can. When you draw a shape you already know where it's going. You know the rectangle you're telling it to draw at.

You have to keep track of things you've drawn and where, then you can check against this list when you want to see where things are.

You absolutely need to do this no matter what because in reality you need to be painting in the OnPaint method or the Paint event and you should write within those methods the code to redraw the entire scene.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM