in one of my previous posts i described a lightbox class that was activex friendly.
the old post is here: vfp lightbox class - now activex friendly

unfortunately because of the logic used in the class, for large "busy" forms with a large number of objects, it caused a couple of seconds delay before the lightbox was displayed and even then on slower computers the screen update was noticeably slow.

so i had another look at the logic of the previous version and threw away most of the code. the result is a lean, mean lightbox that is very snappy to display. it now uses only the gdi+x imgcanvas class exclusively for its display.

to ensure speed the following must be observed:

  • the class will only work on a form. it will not support any other containers
  • it requires the gdi+x libraries ( and gdiplus.vcx/vct)
  • it is however,activex friendly

to use it is simplicity itself as shown in the sample form.
just drop the class on a form and call it as shown.

lparameters tcmsg
local lret as boolean
if messagebox(tcmsg,292,"are you sure?",0) = 7
lret = .f.
lret = .t.
return lret

in the control.beforedraw() method you will find some code like this:
* change the colours as needed here
* possible colours are (220,128,0,0),(220,0,0,128) etc.

lobrush =,0,0,0))

these are argb where the first number denotes the opacity
0 = full transparent, 255 = full opaque
the other 3 numbers are just 3 rgb numbers to denote the colour to be used. you can change these to get different lightbox colours as below.

the complete source code and sample form can be downloaded from the attachment link below. enjoy.

it was also suggested that a shape object be used instead with its drawmode property = 9.
that would work in some cases, because of the way vfp displays colours,
when the form or image control on the form has a picture set, this is
the result - 8 bit colours under the control. also the control can
never support activex and they come to the top.


10 Responses to The Fastest Lightbox Ever

  • Noel says:

    Hi Bernard,

    Really cool stuff.

    Sorry for asking, but It’s just too fast for me. I like slow fading. Where can I tweak it?


    Check out this one:

  • Bhavbhuti says:

    Hi Bernard

    Thanks for the class.  I tried it briefly and I think it does not overlay the child forms on the VFP desktop (attached the object to _SCREEN).  Is there something else I need to do over and above what the sample has?

    Thanks and regards


    This one is for forms not _screen. I thought I made that clear in the blog.

    • The class will only work on a form. It will not support any other containers

    However it can easily be made to work for _screen with a few changes.

  • Vivek Deodhar says:

    Hi Bernard,

    When I use the command button more than once, the activex control becomes darker and darker. I click on commnad2 (lightbox) for the first time, select “No”. The activex is redisplayed ok. Then, I click again on command2, select “No”. The activex control is redisplayed but is semi transparent. As I repeat this, this control becomes darker and darker and after 4 to 5 times, becomes completely black.

    I had changed opacity value to 135 in this line of VCX.

    loBrush = .SolidBrush.New(.Color.FromArgb(135,0,0,0))

    What’s wrong?


    When you say “Activex” you mean the web browser control. You are
    telling me something I already know. Does the DateTime  picker Activex also
    become blacker? How about any other Activex control?

    You see I did not program the Microsoft Web browser control nor did I program VFP. That is a problem between VFP and the Web Browser control over which I have no control.

    Have you tried with any other Activex control?

  • Davide says:

    needed here

  • Luis Navas says:

    Hi Bernard, thanks for sharing it. Just a tough you may add .Anchor = 15 in the Setup Method.

    With This
    .Left = 0
    .Top = 0
    .Height = ThisForm.Height
    .Width = ThisForm.Width
    .Anchor = 15
    .Visible = .F.

    Good point Luis. Missed that. Either above code or just set the anchor property = 15  in the class itself. Thanks

  • Rabih Tawil says:

    Good job bernard, i really like it!

  • Jim Wiggins says:

    Thank you. Thank you. Thank you. As soon as I saw my first lightbox, I knew I wanted to add it to my apps. (Being ‘hit over the head’, as the Nielsen Norman Group calls it, is just what my clients need.) As you stated, your original solution was too slow, but this one is plenty fast.

    Like Bhavbhuti, I also want to use it when multiple forms are open, but I was able to do that without changing your class. I put your control on every form, and then when I need the lightbox effect, I call the following program:

    LPARAMETERS tlShowHide

    FOR EACH oForm IN _SCREEN.Forms



    I have found that a translucency (a.k.a. opacity) setting of 80 gives the desired effect while still allowing users to read what’s on the screen.

  • yohanasse says:

    man, that’s really so cool 🙂 – wonderful class

  • Trial03 says:

    Hi Bernard, thanks for great class.

    I found an issue when using dual monitors.  The class cannot work properly in 2nd monitor.

    Hope you can fix the bug.


  • Craig Boyd says:

    Nice. Thank you Bernard.

Leave a Reply

Your email address will not be published. Required fields are marked *