So to explain what my problem is, I made a PictureBox, and I need to fill in many FILLED squares inside of it. However, to do so I would need to create a brush and all of the solutions I've found online are returned as errors by Visual Studio 2019. I don't know what to do anymore.
Here's an example for brush declaration:
SolidBrush shadowBrush = new SolidBrush(customColor) (returns error)
Brush randomBrush = new brush(customColor) (returns error)
The way GDI+ drawing works, you should store all the data that represents your drawing in one or more fields and then read that data in the
Paintevent handler of the appropriate control to do the drawing. In your case, you need information to represent a square and the colour it will be drawn in and you need multiple of them. In that case, you should define a type that has aRectangleproperty and aColorproperty and store a genericListof that type. You can then loop through that list, create aSolidBrushwith theColorand callFillRectangle.Now, to add a square, you simply create a new
Boxobject, add it to theListand then callInvalidateon thePictureBox. For simplicity, you can callInvalidatewith no arguments and the wholePictureBoxwill be repainted. It is better if you can specify the area that has or may have changed though, because that keeps the repainting, which is the slow part, to a minimum. As you already have aRectanglethat describes the area that has changed, you can pass that, e.g.