3

I have an image that I wanted to include in my vb.net app, so I sliced it up in photoshop and divided it into multiple picture boxes, and anchored them accordingly so when my application is resized it wont stretch all parts of the image. That is all good, it looks great and almost works great..except the fact that when the form is being resized it is causing the pictureboxes to flicker.

I know that the picturebox is not the fastest control, so I am geussing it is not refreshing fast enough. Aside from flickering it appears with a white background underneath even though the pictureboxes are transparent.

I tried adding a BG colour for the background hoping it would hide the flickering better while loading to no avail.

So my fist question would be is their any way of preventing this? If not is their a control that is faster that I could use?

Maybe a custom picture box someone knows, or even if you know a control thats faster. Basically any control that would allow a background image and transparent BG color would work as long as it is faster.

I really appreciate any help. Thanks. PS: My application is in VB.net but I am adding a C# tag aswell because I am most likely going to have to switch controls instead of repairing it through code.

user1632018
  • 2,485
  • 10
  • 52
  • 87
  • what does your Constructor look like..? have you tried setting `DoubleBuffered = true` – MethodMan Jan 20 '13 at 23:11
  • If you look on the right side of your screen you will find a previous question: http://stackoverflow.com/questions/64272/how-to-eliminate-flicker-in-windows-forms-custom-control-when-scrolling?rq=1 – Steve Jan 20 '13 at 23:23
  • Thanks. I took a look. I am not sure where I add the double buffered boolean to. I tried creating a sub new and put it in there but it reset my form. – user1632018 Jan 20 '13 at 23:46
  • [[Get the sample code](http://www.codeproject.com/Articles/12870/Don-t-Flicker-Double-Buffer)] – Ken Kin Jan 20 '13 at 23:53

2 Answers2

7

Two avoid flickering in controls in form u can use following function Only copy it and paste it anywhere in form.vb

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

only paste anwhere it is readonly property

dowhilefor
  • 10,971
  • 3
  • 28
  • 45
  • OMG how you did it? +1! I was looking for a solution to avoid flickering on my panel from 4 months ago! after asking in this forum and other forums, after reading, after trying subclassed panels... and you got the solution in few lines of code! Really awesome, Thankyou. but can you explain what does that lines? – ElektroStudios May 09 '13 at 05:43
  • @ElektroStudios See this link from Microsoft Docs to explain https://learn.microsoft.com/en-us/windows/desktop/winmsg/extended-window-styles – Nathan Jan 04 '19 at 19:38
  • Also, if you place this in a MDI Parent form, it will fix all child forms as well without having to place the snippet in each form class. – Nathan Jan 04 '19 at 19:41
1

Two ways to handle this are:

a) Resize the image in the picturebox so it is smaller and will redraw faster, or

b) Use a timer to redraw the image so it doesn't begin to redraw until 100 to 350 ms after the last resize event.

xpda
  • 15,585
  • 8
  • 51
  • 82
  • Okay, so I would add the code to redraw in the timer and then on the form resize handler I would enable the timer? Then disable when done? How would I stop it from automatically refreshing? I am guessing I will have to somehow override the paint process? Sorry if I am completely wrong, the whole special graphics thing is new to me. – user1632018 Jan 21 '13 at 08:11
  • Right. In the handler disable the timer. I think you can keep it from refreshing (or start the timer there instead of the resize event) in the paint event of the picture box, but I haven't tested it. – xpda Jan 21 '13 at 15:49