views:

25

answers:

2

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!

A: 

you can call

Application.DoEvents();

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

MBZ
Thanks, made it better, but not good. Still flickers and when I release the mouse the picture sometimes freezes
Oskar Kjellin
+1  A: 

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.

Hans Passant
Thanks, this sounds like a good idea. The problem is I suck at WPF and do not know how to make the stuff like the draggable images etc
Oskar Kjellin
You can make it work in winforms too, just not with picture boxes.
Hans Passant