Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting MdiParent Background Image properly

Tags:

c#

winforms

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;
        }
    }
}
like image 735
Durga Avatar asked Jan 25 '26 01:01

Durga


1 Answers

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

this points to 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();
}
like image 97
Sriram Sakthivel Avatar answered Jan 27 '26 18:01

Sriram Sakthivel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!