Improve performance when resizing a Form with a Hi-Res background image

1.7k views Asked by At

I have a Winforms with some controls and the main form has a big picture as background with a BackgroundImageLayout property Stretched enabled.

The main problem is that the resize operation turns slowly because the background image.

The problem is that resizing a Winforms which has a picture and Stretched BackgroundImageLayout property is a nightmare! it begins slow and all the controls are flickering when resizing the form.

I've tried to reduce the image size but I can't reduce it more to don't loose image quality.

I've tried also to do something like this but doesn't reduced the annoying effect:

Private Sub Main_ResizeBegin(sender As Object, e As EventArgs) Handles MyBase.ResizeBegin

    GroupBox_Genres.SuspendLayout()
    GroupBox_Options.SuspendLayout()
    ListBox_Genres.SuspendLayout()
    ListView_Elektro1.SuspendLayout()

    Me.BackgroundImageLayout = ImageLayout.None
    Me.SuspendLayout()

End Sub

Private Sub Main_ResizeEnd(sender As Object, e As EventArgs) Handles MyBase.ResizeEnd

    GroupBox_Genres.ResumeLayout()
    GroupBox_Options.ResumeLayout()
    ListBox_Genres.ResumeLayout()
    ListView_Elektro1.ResumeLayout()
    Me.BackgroundImageLayout = ImageLayout.Stretch
    Me.ResumeLayout()

End Sub

Any ideas of how to resolve the slow and annoying effects of resizing a winforms with a big picture as background?.

EDIT

For take an idea of my problem the application is this:

enter image description here

1

There are 1 answers

3
Haji On BEST ANSWER

Use the below code in your form to avoid form flickering which also avoids your image flickering. you don't need to resize the image you are using.

Protected Overrides ReadOnly Property CreateParams() As Windows.Forms.CreateParams
    Get
        Dim cp As CreateParams = MyBase.CreateParams
        cp.ExStyle = cp.ExStyle Or &H2000000
        Return cp
    End Get
End Property

This will paint the controls in your form and brings the form visible after all controls loaded and avoids the flickering.