0

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

ElektroStudios
  • 19,105
  • 33
  • 200
  • 417

1 Answers1

3

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.

Haji
  • 1,999
  • 1
  • 15
  • 21
  • Thanks but I wanted to improve the performance, not to loose it, I did time ago a lot of performance tests with that "anti-flickering magic code" and turns the application around 30% more slow when using that, thankyou anyways, really flickering is not my problem now, the resize operation turns slow because the background image that's what I want to avoid. – ElektroStudios Dec 14 '13 at 16:46
  • Can you explain the code a bit.? What's the actual flow of this code.? when will this particular piece of code get invoked.? To which, the variable `cp` will be returned.? It'll be helpful for me as well as others, if you give some explanations. Thanks. – Rajaprabhu Aravindasamy Dec 14 '13 at 17:00
  • this would not speed up the control painting but it will hold the screen for a while and just show the updated screen instead of flickering – Haji Dec 14 '13 at 17:04