c # - the transparency is not drawn correctly (rather fast)


this is my first ever question on this website but it has helped me a lot in the past.

i have a small (but annoying) problem with a project i am working on. i am using a picturebox control which loads a png file with transparent areas. the transparency part works perfectly fine, but i need the user to be able to drag this picturebox around with the mouse. the picturebox is contained within a panel with squares. the squares are drawn in an overridden OnPaint method of the panel.

the problem is that if i move the picturebox control, the area which is transparent does not draw the background fast enough and the squares are not drawn exactly where they should be. is there any way to get around this and make everything look nice and smooth?

i have attached a picture so that you can understand better what i am trying to say. for this example i am using just a line instead of the actual picture that i will be using so that everything is more obvious. notice the squares around the line, which are not in drawn properly.


ps: i am using color.transparent for the backcolor of the picturebox

Maybe you could try to invalidate the layout on mousemove to force a faster rate of redraw?