How to make image have transparent colour?

Posted by Tung on 01-Dec-2010 06:19

Hi, my GUI for .NET form has a splash image. I would like it to behave like the Transparent attribute for an image widget. I've tried setting the Back Color property to Transparent for various controls (imagelists, picturebox, panel) but nothing worked. Is this possible in GUI for .NET?

All Replies

Posted by Admin on 01-Dec-2010 06:35

It's not a problem of the image. It's a problem of the Form. You'll have to extend the Form's transparency.

I've used this as a starting point here: http://www.codeproject.com/KB/vista/AeroGlassForms.aspx

Posted by Tung on 01-Dec-2010 07:38

Thanks for the suggestion but I'm using XP and I think Aero is possible only on Vista.

But at least now I know the issue is with the form, not image. I tried the form's TransparencyKey but it makes the key's colour see through! I'll try again later.

It's not a huge issue but frustrating that something so simple in Progress is hard to achieve in NET.

Posted by Peter Judge on 01-Dec-2010 07:55

Tung wrote:

Thanks for the suggestion but I'm using XP and I think Aero is possible only on Vista.

But at least now I know the issue is with the form, not image. I tried the form's TransparencyKey but it makes the key's colour see through! I'll try again later.

It's not a huge issue but frustrating that something so simple in Progress is hard to achieve in NET.

Attached is a generic lightbox form, which works in XP just fine. It may or not do what you want, but here it is anyway . The image itself is not transparent, but I suspect you will have to play around with the image in a (decent) image editor like Paint.NET.

The end result looks something like the below. The lightbox form is the opaque overlay with the login screen on top of it.

lb.png

The code below illustrates using the LightboxForm.

    method protected void ShowServerConnect():

        def var oFrame as Progress.Windows.UserControl extent 1 no-undo.

        define variable oServerConnectForm as UI.LightboxForm no-undo.

        /* */

        oFrame[1] = new Progress.Windows.UserControl().

        /* position where we want it on *this* form */

        oFrame[1]:Location = new System.Drawing.Point(

            int((this-object:Size:Width / 2) - (oFrame[1]:Size:Width / 2 )),

            int((this-object:Size:Height / 2) - (oFrame[1]:Size:Height / 2 ) )).

        oServerConnectForm = new UI.LightboxForm(this-object, oFrame).

        oServerConnectForm:Show().

    end method.

Oh, and if you have or want a Fuschia background you'll need to change the background colour in CreateOverlay().

-- peter

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/LightboxForm.cls.zip:550:0]

[View:~/cfs-file.ashx/__key/communityserver-discussions-components-files/19/LightboxForm.resx.zip:550:0]

Posted by Tung on 02-Dec-2010 06:42

Peter, a lightbox isn't quite what I want but I might use it in our login form.

I asked Progress Support and I got a reply from Rob Debbage who pointed me towards this http://www.codeproject.com/KB/dotnet/transparent_controls_net.aspx

I had a quick go converting it to an ABL class but couldn't override the panel's CreateParams property. It's not a big issue so I'll try again when I have time.

Posted by Admin on 02-Dec-2010 07:00

I had a quick go converting it to an ABL class but couldn't override the panel's CreateParams property. It's not a big issue so I'll try again when I have time.

The ABL does not support property overriding.

Posted by Tung on 02-Dec-2010 07:06

Yep, I realised that when it kept throwing compile errors. I meant try another way to set CreateParams, instead of overriding it, maybe a method

Posted by Tung on 06-Dec-2010 05:42

I managed to find a different and much easier solution.

You need to make your image have a transparent background. I used Paint.NET to do that then saved it as a PNG image, but apparently you can also use GIF89a.

Then add a control to your form (eg. panel, picture box), set its BackgroundImage as your image and its BackColor to Transparent (the first Web colour), and voila!

This thread is closed