views:

439

answers:

2

Hi..

I have a transparent rectangle on a picture box,if i click next,the next image comes and transparent rectangle is drawn.The problem is flickering,while moving from one image to another image,the transparent rectangle flickers.please help me how to get rid of this problem.i want to eliminate flicker,please help.

Thanks

+3  A: 

Do double buffering. Basically created a cached image that will be displayed. Then when you need to redraw your surface do it to another image, and once you're done drawing, exchange that image with the cached image. That way you won't have any flickering.

I can write you an example, but I'm not aware whether you're coding c++ or C# since you've added both as tags. Here's an example of manual double buffering in C# http://www.developerfusion.com/code/4668/double-buffering-in-net/

Qua
Thanks Qua..i saw the link which u have given, basically we are using .net compact frame work 3.5. but we don't have support to control styles in .net 3.5 compact frame work..do u have any idea about how to set the control styles to picture box of .net compact framework 3.5?...even u know the same in c++ also file.. please let me know-Thank u
Shadow
I don't think it's supported at this point. The article does discuss the manual way of doing it and supplies code examples as well.
Qua
+1  A: 

How are you implementing it? I had a similar problem and implemented my own picturebox by inheriting from Control, overriding OnPaint to draw my image and transparent background etc, and also overriding OnPaintBackground and doing nothing. (The default behaviour of OnPaintBackground is to paint the background of the control, which you don't need to do if you are controlling the painting of the whole control)

You can also implement double buffering in the OnPaint if needed to reduce tearing if your paint operations take time.

Matt
Yup Matt, U r right.. But the thing is i am not getting how to set the double buffer to Picture controle of windows mobile..really i got head ache dude.. i tried lot to put double buffer, epically in .net 3.5 compact framework i m failing...kindly let me know how to put double buffering in .net 3.5 compact framework.
Shadow
I do it using custom controls, and paint the whole control myself. You can then allocate a bitmap that is the size of the control, override OnPaintBackground to do nothing, override OnPaint to do all your drawing to the bitmap, and then as the last thing in OnPaint, draw the bitmap onto the Graphics that is passed in the PaintEventArgs
Matt
yes matt, i tried the way u said fine, but one more problem comingI have a custom picture box with sizemode = CenterImage. I have set the BackColor to Black, and displaying a 100*100 image at center. Can I get the bitmap of the picturebox along with the background? iS so, How do i get it?
Shadow
not sure for the standard picture control, but as I said in my last comment, if you override onpaint and then you can fillrectangle in the bitmap black, then draw the image over it on the bitmap, then just draw the bitmap to the control at the end of onpaint.
Matt
ok.. Thank U Mr matt.. will try and Get back to u...any way Have a good day :-)..
Shadow