Stav Bodik Stav Bodik - 1 year ago 165
C# Question

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 :

Answer Source

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

  1. Create your controls (in my case its was pictureboxes)
  2. Add all controls to MainControl ( willywonkadailyblah Thanks!!! )
  3. Make all controls parent to be MainControl
  4. Here is the trick , when you move control on mouse down remove from the moved control the image , take screenshoot give back to moved control his image, set MainControl image to hold this screen shoot . . . now you can move the control and he is transparent on all the other controls because he is parent of them.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download