Transparencies won't work!

I have an msn like popup that I'm trying to put round corners on.  I have an image for it, and I have tried several approaches.   I have tried using yellow and blue, as the transparency color, and coloring the corners as blue in my image.  I've set that image to the label background, and that didn't work so i put it on a panel background, and that still didn't work.  I tried transparent gif's with the form background giving it the yellow background color, and I have double checked my image to make sure that the color was saved properly (FFFF00, and not FFFF01 or 02). 

I'm completely lost here!  ! 

Can someone tell me what I'm doing wrong or not doing   

Thanks !

Brett


Answer this question

Transparencies won't work!

  • Josep Maria Roy

    Point added: 

    Transparencies do work now on xp, but only briefly.  I get about 3 pop ups that come in with transparencies working, and then all of a sudden I have yello corners again. 

  • Sstar

    Here is one example of why what I'm doing SHOULD work.  

    http://www.c-sharpcorner.com/Code/2004/April/TransparentPanel.asp

    Except my panel will have the outer edges transparent, and show content on the inside.  I will simulate that top bar by creating an image for it and docking it to the top of the panel, so that I can make the bottom part stretch out when the form (popup) is displayed. 

  • T-boy

    oops wrong thread. 

    with transparencies I have set the transparency key to yellow on the form, I haven't seen a transparency key for the bitmap, or is this something I have to set in photoshop on the bitmap

    I should be able to use a transparent gif too right


  • Juan Gabardini

    Ok, if you have one image (bitmap) that is going to be the actual form, you'll want to do the following:

    0.  Set the FormBorderStyle to None

    1.  Set the BackColor of your Form to pure green (0,255,0) (you could use any color; pure RGB green is one of the best as it does not exist in nature)

    2.  Set the TransparencyKey of the Form to pure green as well

    3.  In code, load the image you want to use into a class-wide variable:

        Dim b As New Bitmap("C:\...\formimage.gif")


    4.  Finally, override the OnPaint event of the form and have it draw your image using ImageAttributes to specify the transparency:


        Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    'Create an ImageAttributes object to hold the transparecy info
            Dim ia As New System.Drawing.Imaging.ImageAttributes

    'Set the transparency to pure green (named color = Lime)
            ia.SetColorKey(Color.Lime, Color.Lime, Imaging.ColorAdjustType.Bitmap)

    'Draw the image on the form using the attributes
            e.Graphics.DrawImage(b, New Rectangle(0, 0, b.Width, b.Height), 0, 0, b.Width, b.Height, GraphicsUnit.Pixel, ia)

    'Release the attribute object
            ia.Dispose()

        End Sub



    That will create a form with the look and bounds of your image.  If you click an area of the image that is transparent, your form will NOT recieve that click; it will pass through to the window below (or desktop).  Also, for your image, any bitmap will do.  You just need to be sure that the bitmap uses Pure Green (or your chosen color) for all portions you want to have transparent.  You DO NOT have to specify transparency info in your image editor (ie Photoshop).

  • Banslug

    this makes sense, but what doesn't make sense is that the method I am currently using works on windows 2000.  It also works on windows xp, on an old project that I had done. 

    Although my previous project had the actual forms background image set with the yellow corners for transparency, and this one I have panels. 

    Thanks for the tips.

  • Croc1986

    Hmm... that seems strange to me. 
    Maybe someone else can confirm. 

    The bitmap transparency key should be the background of the bitmap.
    The form transparency key should be the background of the form. 

    Are you doing this correctly


  • Inc

    before I try that, my layout is a bit different, and maybe it does make a difference.. 

    I have a form, and 2 panels.  One panel is the title and one is the body. (its an msn like popup, so the titlebar needs to be handled differently..the bottom is resized as needed.)

    the top form has a background of transparent, and the panels on the layer above that have images, with Yellow colored into the bitmap. (tried this with transparency on the bitmap too). 

    Why would I have to code it manually  what is different between the code you have and the code that the form designer would create

  • Saso

    I have tried to keep that in mind when coding, but I have multiple threads that are running on this app... so is the best way to kill those threads in the 'closing' method
  • Gugapriya Jagadeesan

    The point is that the OnPaint event is what draws an object.  If you don't override that event, the object's default painting behavior will occur.

    Transparencies, as you are trying to use them, only allow an image to have transparent portions when drawn to a form.  The Form itself will be visible under the image in its transparent regions.  Since the default draw behavior of a form is to make a rectangle, you'll always get that shape.  If you want rounded corners on a form, you have to draw the form yourself.  That's what overriding the OnPaint event allows you to do.

    Since you want two different looks on the form, you can draw each image to the form seperately, calculating the size of the second image based on the info you intend to display.

  • Transparencies won't work!