如何删除MDI父窗体上的灰色背景? [英] How to remove gray background on MDI parent form?

查看:161
本文介绍了如何删除MDI父窗体上的灰色背景?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做的是画一些玻璃标记为MDI容器窗体上。然而只要的IsMdiContainer被设置,形式增加了一个MDICLIENT到它的控制的列表。此时有事父窗体 - 几乎像一个暗灰色面板正在停靠在其上MDICLIENT被放置在整个表单

What I'm trying to do is draw some glass on a form marked as an mdi container. However as soon as the IsMdiContainer is set, the form adds an MdiClient to it's list of Controls. At this point something happens to the parent form - almost like a dark gray panel is being docked to the entire form onto which the MdiClient is being placed on.

然后我做的。在下面的移动MDICLIENT控制闪开了一下:

I then do is the following to move the MdiClient control out of the way a bit:

    foreach(var c in Controls)
    {
        if(c is MdiClient)
        {
            var client = (MdiClient)c;
            client.BackColor = Color.Red;
            client.Dock = DockStyle.None;
            client.Size = new Size(this.Width-100, this.Height);
            break;
        }
    }

这则使得实际MDICLIENT面积小,所以我们可以看到的是它背后(其中承载儿童位构成),它是公然明显的父窗体不画画什么的。

This then makes the actual MdiClient area smaller so we can see what is behind it (the bit which hosts the children forms) and it is blatantly obvious that the parent form is not painting or something.

由于可以在这里看到:的http:// img525 .imageshack.us / img525 / 8605 / mdiglassproblem.png

As can be seen here: http://img525.imageshack.us/img525/8605/mdiglassproblem.png

我现在需要以某种方式得到它呈现白色MDICLIENT后面的区域(暗灰色部分。在玻璃部分)走开

I now need to somehow get the area behind the MdiClient (dark gray part which is rendered white on the glass section) to go away.

任何想法

PS - 玻璃是被使用在Vista中DwmExtendFrameIntoClientArea方法呈现。

推荐答案

我设法得到它的工作。这深灰色区域我说的,这被涂过一切都存在的形式的OnPaint方法。显然,当有一个MdiContainer呈现形式被预先编程到油漆其阻碍玻璃暗灰色区域。

I managed to get it working. That dark gray area I was talking about, which gets painted over everything was occuring in the OnPaint method of the form. Obviously when there is an MdiContainer present the form is preprogrammed to paint the dark gray area which was obstructing the glass.

所以才重写OnPaint方法没有调用它的基地,然后采取被用来绘制在正常画图法玻璃,贴在OnPaint方法的代码。

So just override the OnPaint method without calling it's base and then take the code that was used to draw the glass in the normal Paint method and stick it in the OnPaint method.

protected override void OnPaint(PaintEventArgs e)
    {
        //base.OnPaint(e);
        bool glassEnabled = IsGlassEnabled();
        if (glassEnabled) // draw glass if enabled
        {
            Rectangle rc = picPlaceHolder.ClientRectangle;

            IntPtr destdc = e.Graphics.GetHdc(); // hwnd must be the handle of form, not control
            IntPtr Memdc = CreateCompatibleDC(destdc);
            IntPtr bitmapOld = IntPtr.Zero;

            BITMAPINFO dib = new BITMAPINFO();
            dib.bmiHeader.biHeight = -(rc.Bottom - rc.Top);
            dib.bmiHeader.biWidth = rc.Right - rc.Left;
            dib.bmiHeader.biPlanes = 1;
            dib.bmiHeader.biSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER));
            dib.bmiHeader.biBitCount = 32;
            dib.bmiHeader.biCompression = BI_RGB;
            if (!(SaveDC(Memdc) == 0))
            {
                IntPtr bitmap = CreateDIBSection(Memdc, ref dib, DIB_RGB_COLORS, 0, IntPtr.Zero, 0);
                if (!(bitmap == IntPtr.Zero))
                {
                    bitmapOld = SelectObject(Memdc, bitmap);
                    BitBlt(destdc, rc.Left, rc.Top, rc.Right - rc.Left, rc.Bottom - rc.Top, Memdc, 0, 0, SRCCOPY);
                }

                // remember to clean up
                SelectObject(Memdc, bitmapOld);

                DeleteObject(bitmap);
                ReleaseDC(Memdc, -1);
                DeleteDC(Memdc);
            }
            e.Graphics.ReleaseHdc();
        }
    }



然后,只需确保MdiContainer是不是在路上玻璃,它应完全绘制

Then just ensure that the MdiContainer is not in the way of the glass and it should draw perfectly.

这篇关于如何删除MDI父窗体上的灰色背景?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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