VinkyH
VinkyH

Reputation: 47

How is the best way to add background image in form - WinForm?

I try to add background image in my form. When I run it, there is some flicker before the form fully load the image.

I've tried:

public Form1()
{
    this.TransparencyKey = Color.Empty;
    this.SetStyle(ControlStyles.DoubleBuffer, true);
    this.SetStyle(ControlStyles.UserPaint, true);
    this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
    this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);

    InitializeComponent();
}

but seems it only reduce a little. Is there anything I miss? Thanks.

Upvotes: 0

Views: 1185

Answers (1)

Pedery
Pedery

Reputation: 3636

I can think of three things.

1) Is the image very large? In that case reduce the size of the image with an appropriate image editor.

2) You mention that there is a problem before the form is fully loaded. I assume you mean in the first second of loading or something. You could potentially try to set the form as invisible (or something appropriate) until the image is fully loaded.

3) Try to move the painting of the image to the form's Paint event or alternatively an overridden OnPaintBackground event (that is, remove the image from the Background Image property).

You could also try to describe your problem better so that we can find the most appropriate solution for you.

Upvotes: 1

Related Questions