user3036459
user3036459

Reputation:

C# make background image fit the screen?

I decided to add a background image to my winforms application and I wonder how I can make the background always fit with the screen? (auto-stretch it).

I have a form where users can resize it and choose their own window size, but I want the background to always fill the application. I have a huge background wallpaper, about 2000x1500 in resolution, if the user resize the form window to about 500x500 it will only show a small part of the wallpaper, how can I make it show the full wallpaper but in a smaller resolution?

I haven't found anything about this and I have no idea where to even start. Could anyone help me?

Upvotes: 2

Views: 18754

Answers (3)

Sanoop
Sanoop

Reputation: 1

private void MDIParent1_Load(object sender, EventArgs e)
    {
        BackgroundImage = System.Drawing.Image.FromFile("C:\\Users\\Downloads\\2137969.png");
        this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
    }

Upvotes: -1

Idle_Mind
Idle_Mind

Reputation: 39122

Set the BackgroundImageLayout() property of the Form to either "Stretch" or "Zoom".

Upvotes: 4

Alex K.
Alex K.

Reputation: 175768

Just set the forms BackgroundImageLayout to Stretch.

This will probably cause flickering, to prevent this you can (in the ctor):

this.SetStyle(
    ControlStyles.AllPaintingInWmPaint |
    ControlStyles.DoubleBuffer,
    true);

Upvotes: 9

Related Questions