让图片框透明,每个重叠另用一个角落? [英] Make Picture boxes transparent, each overlapping the other with a corner?

查看:277
本文介绍了让图片框透明,每个重叠另用一个角落?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TL; DR:看看下面

所以我想做一个小图片,我和周围的人我还挺的想法。

So I'm trying to make a little picture, and I and people around me are kinda out of ideas.

我有一个表(坐吃+一个),中间(从上面看),人们围坐它。那些人是圆的,因为isthe表。

I have a table (the sitting+eating one) in the middle (seen from above), and people sitting around it. Those people are round, as isthe table.

每个人都有自己的图片框,我只是用一张图片,旋转,并在接下来的盒子将其设置为图像。

Every person has their own picturebox, I just use one picture, rotate it, and set it as image in the next box.

人Thep roblem现在是:人对角的PictureBoxes重叠表空的角落,在图像中有透明性存在。它应该显示它下面的表,而是它显示了表格的背景:(

Thep roblem now is: The PictureBoxes of people on corners overlap the table with empty corner, in the image there is transparency there. It should show the table below it, but instead it shows the background of the Form :(

编辑:所有的背景都设置为透明,表单有大理石背景和白色(窗口)作为背景颜色。

我把后面的一个人,一个在前面,所以很容易见:

I put one person in the back and one in the front, so it's easy to see:

编辑2(同ocmment)

Edit 2 (same as ocmment):

在过去的两天我读到这个问题,10倍左右,而不是一个描述这个确切的问题已经有一个实际的答案。当试图把其中的一个。 ,有人告诉我,我应该发布一个新的问题

In the last two days I read this question about 10 times, and not one that described this exact problem has had an actual answer. When trying to push one of those, I was told I should post a new question.

例如:的如何使图片框透明?

推荐答案

透明度的WinForms是怎么样误导,因为它不是真正的透明度。结果
WinForms控件通过绘制他们的父母控制,他们会躲在而不是他们自己的背景部分模仿的透明度。结果
然而,他们不会画画可能被他们部分覆盖其他控件。结果
这是你最上面的图片框隐藏你的大图片框的原因。

Transparency in winforms is kind of misleading, since it's not really transparency.
Winforms controls mimic transparency by painting the part of their parent control they would hide instead of their own background.
However, they will not paint the other controls that might be partially covered by them.
This is the reason your top most picture boxes hides your big picture box.

您可以通过创建从继承的自定义控制图片框克服这一点并覆盖其的 OnPaintBackground 方法(拍摄,稍作调整,从该代码项目文章):

You can overcome this by creating a custom control that inherits from PictureBox and override its OnPaintBackground method (taken, with slight adjustments, from this code project article):

protected override void OnPaintBackground(PaintEventArgs e)
{
    base.OnPaintBackground(e);
    Graphics g = e.Graphics;

    if (this.Parent != null)
    {
        var index = Parent.Controls.GetChildIndex(this);
        for (var i = Parent.Controls.Count - 1; i > index; i--)
        {
            var c = Parent.Controls[i];
            if (c.Bounds.IntersectsWith(Bounds) && c.Visible)
            {
                using (var bmp = new Bitmap(c.Width, c.Height, g))
                {
                    c.DrawToBitmap(bmp, c.ClientRectangle);
                    g.TranslateTransform(c.Left - Left, c.Top - Top);
                    g.DrawImageUnscaled(bmp, Point.Empty);
                    g.TranslateTransform(Left - c.Left, Top - c.Top);
                }
            }
        }
    }
}

微软已经发布了知识库文章来解决这个问题由来已久很久以前,但它是一个有点过时,它的代码示例是在VB.Net。

Microsoft have published a Knowledge base article to solve this problem a long time ago, however it's a bit out-dated and it's code sample is in VB.Net.

另一个选择是自己画的图片,没有图片框拿着他们通过使用 Graphics.DrawImage 方法。结果
做到这一点的最佳地点可能是在的 的OnPaint 形式的方法。

Another option is to paint the images yourself, without picture boxes to hold them, by using Graphics.DrawImage method.
The best place to do it is probably in the OnPaint method of the form.

这篇关于让图片框透明,每个重叠另用一个角落?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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