Oskar Kjellin
Oskar Kjellin

Reputation: 21880

Transparent pictureboxes flickers when moved with mouse

I have made a card game built of pictureboxes. The empty places a card can be put in is an empty picture box with a transparent background and a 3d border. And then I have a current card which is also a picturebox which is moved by a MouseMove event.

As soon as I drag a card over the transparent PictureBoxes there is a card left all over the place where the card has been until I stop the mouse and let the picture refresh. This is also the case when I have the background of the current card set to transparent although a card is set to be the image (so it does not really matter there as it goes away if I set the background to green).

Is there any workaround for this? I tried DoubleBuffered but with no success. Thanks!

Upvotes: 0

Views: 1378

Answers (2)

Hans Passant
Hans Passant

Reputation: 941515

It isn't clear from your description what your code looks like. But heads up on your next problem after you get this one fixed: transparency effects for controls do not work in Windows Forms when controls overlap. You'll see the background of the parent, you won't see the content of the picture box that's overlapped by your moving card.

This isn't a problem with WPF, it has a very different rendering model. But as long as you want to stick with Windows Forms, you need to make this work with the form's OnPaint() event. Draw the card table, then the stock, then draw the moving card. When the card moves, call Invalidate() to force the form to be repainted, now showing the card in its new position.

In other words, don't fix your current problem. Redesign your program.

Upvotes: 1

MBZ
MBZ

Reputation: 27592

you can call

Application.DoEvents();

in pictureBox.Move events; so all the background pictures will redraw themselves.

Upvotes: 0

Related Questions