C#将PictureBox移动到其他具有透明背景的PictureBox上 [英] C# Moving PictureBox over other PictureBoxes with transparent background

查看:416
本文介绍了C#将PictureBox移动到其他具有透明背景的PictureBox上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是制作跳棋游戏,用户可以在棋盘上移动跳棋.

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

我制作的板子来自DataGridView类.

The board I have made is from DataGridView class .

现在,我正在为透明背景下的每个检查器创建图片框,并且当用户移动选定的检查器时,我将其设置为BringToFront.

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.

问题在于,透明"效果实际上是相对于父控件而言的,所有检查器的父元素都是DataGridView.

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

结果是当2个棋子重叠时没有透明效果.

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

我的问题图片示例

我有一些解决方案,但是它占用大量内存,并且即使在UI线程中没有的线程上也全部冻结.

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 !

快完成了:

https://youtu.be/nyhfIOzqeY8

推荐答案

因此,如果将来有人在此问题上需要帮助.

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

(:

这篇关于C#将PictureBox移动到其他具有透明背景的PictureBox上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆