Results 1 to 15 of 15

Thread: TransparencyKey [Accepted]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127

    Question TransparencyKey [Accepted]

    Strolling along the Internet one day I found an article on using the TranparencyKey with VB.NET along with a GIF file to allow one to make a simple borderless, non rectangular form.

    Here's the link but I can't get it to work.

    Following the steps to a T and I still get just a form with a background on it. To me it seems like the picture is just covering the form and the picture isn't recognized as being part of the form in the sence that the TransparencyKey would affect it like it would the form itself. Am I doing something wrong? Did the article leave out an importiant step? is it hawg wash? and does anyone have a better suggestion if they have played around with non rectangular forms before?
    Last edited by teamdad; Aug 3rd, 2004 at 01:10 PM.

  2. #2
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Well , MS says the image (skin) should be a bmp picture . Did you try to use bmp picture ?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    I tried the BMP today when I got home from work and still doesn't
    render transparency. I also tried just using this and it still didn't work.... I tried it in the form load and in the form paint event and same old nothing.

    Code:
    Me.BackColor = Color.Blue
    Me.TransparencyKey = Color.White

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Well.... I found my flaw. errr should I say Bill Gate's flaw. Using a BMP, GIF, JPG or just drawing directly on the form and then setting a TransparencyKey color works great!!! The catch is that if your'e like me and like nice rich colors it won't work. Your video card settings have to be below 32bit -something like 24bit or 16bit settings and you can see transparency all day long. Set it above 24bit to 32bit or true color and forget it.

    Anyone know a clever way around it aside from forcing the user to reduce their settings just to get this effect to work on their machine?

  5. #5
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    That's not true. There's no problem using 24 or 32 bit colors.
    I just tried it and it works great. You must be doing something else wrong.

    Try making a simple form with only a panel on it.

    Set the panel backcolor to White and set the transparencykey to white.

    When you run your app, you should see a hole in your form where the panel was. No matter your color setting.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    uh huh I never saw it mentioned (I may have and didn't realize it) that you can't just slap your picture as the form's background and it work. If you cover the form with a panel and set the transparency key to match your color it works great at any color resolution. My transparency problem solved by pax and my friend pirate

    Now on my machine it won't work unless I put the panel down over the form first. If I just put the picture on over the form and set the transparency it won't work unless I drop my color to under 32bit.... go figure though. using the panel method is fine with me though.

  7. #7
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    You should be able to just use the picture as backgroundimage.
    I think your colors are not exactly what you think they are.

    Imagine this: You set the transparencykey to white.

    White has these values :a=255,r=255,g=255,b=255
    The color you want to hide could be : a=255,r=254,g=254,b=254.

    Now, these two color will be identical to the naked eye, but not the pc. But when you lower you colorsetting the 3x254 color would be rounded to match the white, since you don't have as many colors available anymore.

    Why it works inside a panel, I don't know. Maybe the panels internal painting method rounds the colors to be websafe or something like that.

    So, I suggest you open your bmp in Paint and try to use the colorpicker on the color you think is white (or whatever it is).
    Then use the menu "Colors - Edit Colors". Make sure you click the "Define Colors" in the colorpicker and you should see the RGB values to the right. Then you should be able to see if the color is really what you think it is.

    NB. I'm not sure about the menunames. My system is Danish, but I hope you get the idea

    Does this make any sense at all?
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  8. #8
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Just out of curiousity , what's your Graphics Card and do you have latest drivers for it ? GDI is related to any problem happens on the screen (well not always though )

  9. #9
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Hi.

    Please disregard my last post (although it still may be true)
    I just did some testing, and the clear white panel works like a charm, BUT when using an image there were one thing causing problems for me. (As you probably allready guessed, it didn't work at first)

    1. The image has to be saved as a 24bit bitmap.

    then it works by just setting the image to backgroundimage property.

    EDIT: The borderstyle didn't matter...
    Last edited by pax; Jul 28th, 2004 at 07:30 AM.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    My card is an Nvidia GeForce4 MX 440 w/ AGP 8X and the latest drivers that I am aware of. I think Pax hit my head on the nail when he discovered the bitmap image has to be a 24bit bitmap. I wasnt creating it like that.

    I'll have to try it when I get home tonight.

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    Checked the RBB and matched black and white colors, used paint and saved as 24 bit BMP and used it as the form background and still no transparency. Took the same picture and put it on a panel as the background and still no transparency.

    Used plain form with one panel control in the middle; set the form background to white then the panel background color to black and the transparency key to white. Debugged and was transparent except the black square that was visible.

    It's like pictures just don't work for me


    Here's where I am getting the info about the 24bit graphics settings causing a problem. Microsoft


    Note Monitors set to a color depth of greater than 24-bit can display problems with certain parts of the form not being transparent, despite setting of the TransparencyKey property. To avoid this problem, ensure that the monitor's color depth is set to less than 24-bit in the Display control panel. When developing applications that feature this transparency, keep in mind that you will have to make your users aware of this issue.
    Last edited by teamdad; Jul 28th, 2004 at 08:21 PM.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    On a side note; would one be able to detect the color depth that the user has set on their pc and then be able to use a button on the form to manually change it to 24 bit then after the form is disposed/unloaded it would change it back to the users setting before it was changed?

    Sounds like a lot of work just to get 100% transparency out of a game you are creating but then again.... it's a game I am trying to create.

    I'm open to suggestions

  13. #13
    Fanatic Member pax's Avatar
    Join Date
    Mar 2001
    Location
    Denmark
    Posts
    840
    Now ain't that a b****?. I have never heard of that before but it sure does explain alot.

    I'm sorry to say though, that I have no idea how to detect and change the colorsettings.
    I think you may have to resort to "old-fashion" API.
    I wish I could think of something witty to put in my sig...

    ...Currently using VS2013...

  14. #14
    Fanatic Member LITHIA's Avatar
    Join Date
    Dec 2002
    Location
    UK, England
    Posts
    575
    Originally posted by teamdad
    My card is an Nvidia GeForce4 MX 440 w/ AGP 8X and the latest drivers that I am aware of. I think Pax hit my head on the nail when he discovered the bitmap image has to be a 24bit bitmap. I wasnt creating it like that.

    I'll have to try it when I get home tonight.
    ouch, i suggest getting a different graphics card fast if you are hoping to play games on that.

    The MX is garbage... but i think its fine for applications. Run it on a game and it'll just hate you lol, i used to have it...

    I got the 256MB Geforce FX 5600, it works very nice

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Dec 2003
    Posts
    127
    I guess we all have to adapt in some way

    Anyone have suggestions on tutorials or links to info
    on using API calls for transparency with VB.NET 2002?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width