Double Buffer with Transparency

Is there a way to use the Double Buffer property and keep Transparency? I have several Canvas Controls that function as buttons but when I set them to either Enable True or False there is a momentary flicker on each canvas. I need the Canvas Buttons to be set Enable False depending on the circumstances.

I know that Windows doesn’t Auto Double Buffer like Mac OS X. I need the transparency and Double Buffer. Is there a way to have both.

I am simply using a tmpImage for each Canvas Button with the Paint Event and calling Refresh(False) when I first set the image and only when the image changes.

I haven’t done Double Buffering in RealBasic with Windows for several years so I’m a little out of date.

Try Invalidate(false) instead of Refresh(false)

Doesn’t change a thing.

Double-buffer only means that you don’t do many small paints but one big one. So if you keep all your paints into a transparent picture the double-buffering should work transparently with transparency.

You have completely lost me.

You have a g as graphics in the paint event. Instead of doing your drawing there create a picture and use it’s graphics property. Then do paint the picture to your original graphics.

I’m still lost.

Without code this may be hard to understand. Have a look at this old post from Thom McGrath: http://permalink.gmane.org/gmane.comp.lang.realbasic.forums/22881

I guess I’ll have to fake the Transparency if I want Xojo to do the Double Buffering itself on Windows.

I don’t remember how to grab a part of a picture and combine it with another with alpha channels.

Let me give you the location and size of one canvas button and maybe you can tell what code I need with the proper values.

Canvas1:
Left = 587
Top = 414
Width = 400
Height = 60

Window1:
Width = 1024
Height = 768

[quote=170306:@Charles Fasano]Is there a way to use the Double Buffer property and keep Transparency? I have several Canvas Controls that function as buttons but when I set them to either Enable True or False there is a momentary flicker on each canvas. I need the Canvas Buttons to be set Enable False depending on the circumstances.

I know that Windows doesn’t Auto Double Buffer like Mac OS X. I need the transparency and Double Buffer. Is there a way to have both.

I am simply using a tmpImage for each Canvas Button with the Paint Event and calling Refresh(False) when I first set the image and only when the image changes.

I haven’t done Double Buffering in RealBasic with Windows for several years so I’m a little out of date.[/quote]

Double buffer or not, I do not see any flicker when I set enabled false or true. Would you post a test project demonstrating ?

Double buffer works if you paint every pixel. Transparency implies not painting certain pixels. So double buffer plus transparency only works if you never paint the “transparent” pixels and always paint the opaque pixels.

No. You can only do simulated transparency. For windows, the secret to flicker free drawing is:

  1. DoubleBuffer = True.
  2. EraseBackground = False.
  3. Never use Refresh, RefreshRect, or Invalidate with the default EraseBackground parameter left as true. I usually override these methods to call the super version with false so that I can’t screw it up.
  4. Never overlap controls.

But this means you lose transparency. Fact of life.

How do I do simulated transparency? I know it involves grabbing a portion of the background and combining it with the top image but it’s been quite some time since I did that so I need a refresher.

I am not having much luck. Can anyone help me with this?

Put you canvas with DoubleBuffer off, EraseBackground off, Trasparent ON
in the open event put:

#if TargetWin32 me.DoubleBuffer=True #Endif

use invalidate to “refresh” the canvas
in the Paint event if you want to simulate transparency set g.trasparency=value where value must be between 0 (solid) to 100 (transparent)

Don’t forget to put Use GDI Plus ON in the windows build setting

g.Transparency=100 does nothing when DoubleBuffer is True

I finally figured out (after much trial and error) how to get the simulated transparency by taking the part of the background image and combining it with the button image.

g.DrawPicture(imgBG_01,0,0,me.width,me.height,me.top,me.left) g.DrawPicture(AboutRegular,0,0,me.width,me.height,0,0)

I am setting the Method as a public Function so that all of my Windows can use this as I have many Windows with these types of buttons.