Search code examples
c#drawmovepictureboxtransparent

C# Moving PictureBox over other PictureBoxes with transparent background


My goal is to make checkers game , where user can move checkers on the board.

The board I have made is from DataGridView class .

Right now what am i doing is creating picture boxes for each checker with transparent background and when the user moves the selected checker i am setting him BringToFront.

The problem is that the "transparent" effect is actually relative to parent control, and the parent of all checkers is the DataGridView.

So the result is when there is 2 checkers overlapping there is no transparent effect .

Example of my problem image

I have got some solution but its takes a lot of memory and all freezes even on thread which is not in UI thread.

My solution was to have one big panel (parent of all checkers) that its background is build of client screenshot and changes while moving the checker.

What is the correct way of doing thing like that ? I was looking and trying solutions on the net from the mooring ): Please help !

Edit :

Almost done :

https://youtu.be/nyhfIOzqeY8


Solution

  • So if anyone in the future will need help with this issue .

    The idea is to have another control panel over all the other panels (game board and checkers).

    Then each time we would like to move an checker we take a screenshot from the game board without the moving checker and putting this screenshot to be the image of the top most panel.

    Now we change the parent of the moving checker to be the top most panel and now we are moving the checker upon this panel with transparent background.

    https://youtu.be/PUEyZPhPTlc

    (: