用鼠标移动时透明图片框会闪烁

发布于 2024-09-11 20:11:10 字数 258 浏览 2 评论 0原文

我制作了一个用图片盒制作的纸牌游戏。可以放置卡片的空位置是一个具有透明背景和 3D 边框的空图片框。然后我有一张当前卡,它也是一个图片框,由 MouseMove 事件移动。

一旦我将卡片拖到透明图片框上,卡片所在的位置就会留下一张卡片,直到我停止鼠标并让图片刷新。当我将当前卡片的背景设置为透明时,尽管卡片被设置为图像(所以它并不重要,因为如果我将背景设置为绿色,它就会消失),情况也是如此。

有什么解决方法吗?我尝试了 DoubleBuffered 但没有成功。谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩世 2024-09-18 20:11:10

从您的描述中不清楚您的代码是什么样的。但解决此问题后请注意下一个问题:当控件重叠时,控件的透明度效果在 Windows 窗体中不起作用。您将看到父级的背景,而不会看到与移动卡片重叠的图片框的内容。

这对于 WPF 来说不是问题,它具有非常不同的渲染模型。但只要您想坚持使用 Windows 窗体,就需要通过窗体的 OnPaint() 事件来实现此操作。先画牌桌,再画股票,最后画移动牌。当卡片移动时,调用 Invalidate() 强制重新绘制表单,现在将卡片显示在新位置。

换句话说,不要解决当前的问题。重新设计你的程序。

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.

|煩躁 2024-09-18 20:11:10

您可以调用

Application.DoEvents();

pictureBox.Move事件;所以所有的背景图片都会重新绘制。

you can call

Application.DoEvents();

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文