不能使MDI子透明 [英] Cant able to make mdi child as transparent

查看:95
本文介绍了不能使MDI子透明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我正在开发Windows应用程序,因为我有一个MDI父级,并且为该父级设置了背景图像.我有许多MDI子窗体.所以现在我想使一个mdi子的背景变为透明,当我删除它的mdi父属性时,我尝试将该mdi子的背景色和透明键设置为相同的颜色,但是不起作用.

所以请给我任何解决方案.

在此先感谢您.

Hi everybody,
I am developing a windows application, in that I have a mdi parent and i set a background image for that parent.I have many mdi child forms. so now I want to make the background of a mdi child to transparent, I tried to give the back color and transparent key for that mdi child as same color, but not working, when i remove the mdi parent property of that it is working fine.

So please give me any solution for this.

Thanks in advance.

推荐答案

将以下代码添加到您的子窗体中,

< pre>受保护的重写CreateParams CreateParams
{
获取
{
CreateParams cp = base.CreateParams;
cp.ExStyle | = 0x00000020;//WS_EX_TRANSPARENT
返回cp;
}
}</pre>
Add the following code to your childform ,

<pre> protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020;//WS_EX_TRANSPARENT
return cp;
}
}</pre>


如果您遇到任何绘画问题,请在子窗体中添加以下代码

if you faced any painting problem add the following code in the child form

protected override CreateParams CreateParams
            {
                  get
                  {
                        CreateParams cp = base.CreateParams;
                        cp.ExStyle |= 0x00000020;//WS_EX_TRANSPARENT
                        return cp;
                  }





private int opacity1;
        public int Opacity1
        {
            get { return opacity1; }
            set
            {
            opacity1 = value;
            Rectangle rc = new Rectangle(this.Location, this.Size);
            Parent.Invalidate(rc, true);
            }
        }


protected override void OnPaintBackground(PaintEventArgs e)
        {
            Color bk = Color.FromArgb(Opacity1, this.BackColor);
            e.Graphics.FillRectangle(new SolidBrush(bk), e.ClipRectangle);
        }


这篇关于不能使MDI子透明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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