正确设置 MdiParent 背景图像 [英] Setting MdiParent Background Image properly

查看:36
本文介绍了正确设置 MdiParent 背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用下面的代码来设置 MdiParent 表单的背景图像,并且它运行良好,但是当我单击最大化按钮时,BackgroundImage 在右侧和底部边缘重复(即右侧和底部图像部分正在重复),如何避免这种情况并正确显示图像?

I am using below code to set background image of MdiParent form ,and it is working well ,but when I click on maximize button than BackgroundImage is repeating at rightside and bottom edge(i.e right side and bottom side Image portion is repeating) ,how do I avoid this and display Image properly ?

public Parent()
{
    InitializeComponent();

    foreach (Control ctl in this.Controls)
    {
        if (ctl is MdiClient)
        {
            ctl.BackgroundImage = Properties.Resources.bg;
            ctl.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
            break;
        }
    }
}

推荐答案

this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;

this 指向 Form.

我自己也注意到了您提到的相同行为.好像只是画的问题.添加以下代码来修复它.

Myself too noticed the same behavior you mentioned. It seems just a painting issue. Add the following code to fix it.

protected override void OnSizeChanged(EventArgs e)
{
    base.OnSizeChanged(e);
    this.Refresh();
}

这篇关于正确设置 MdiParent 背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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