Transparent Button in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • khaing
    New Member
    • Apr 2010
    • 5

    Transparent Button in C#

    I have a button in c# windows forms and set the image property of that button as menubtn.png (i want the transparent image)
    But it doesn't work and show white color.
    I also set the BackColor property to Transparent and it also shows white color.
    How can I get the transparent button?
  • Monomachus
    Recognized Expert New Member
    • Apr 2008
    • 127

    #2
    Originally posted by khaing
    I have a button in c# windows forms and set the image property of that button as menubtn.png (i want the transparent image)
    But it doesn't work and show white color.
    I also set the BackColor property to Transparent and it also shows white color.
    How can I get the transparent button?
    Google/Bing is your best friend. Common guys.

    Link 1. .Net & C#: Trying to have a transparent image on a button
    Link 2. Button Image Transparent Background

    Comment

    • ThatThatGuy
      Recognized Expert Contributor
      • Jul 2009
      • 453

      #3
      Originally posted by khaing
      I have a button in c# windows forms and set the image property of that button as menubtn.png (i want the transparent image)
      But it doesn't work and show white color.
      I also set the BackColor property to Transparent and it also shows white color.
      How can I get the transparent button?
      Set the Back color of the button to some color and then change the Transparency Key of the form to the color you chose for the button's back color...

      you'll have a transaprent button

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        Helpful links, if you have bitmap without transparancy. But since you are using a png that is already transparant you don't have to go through all that.

        I had no need to play silly games of matching the button color to the form transparancy key. Why do all that?

        Set the button back color to transparant.
        Set the button FlatStyle to flat.
        Place the .png.
        Done - get back to writing code.

        You have to set the FlatStyle, because otherwise the O.S. theme of 3d style will cause it to do all the fancy glass and reflection effects when painted, thus overriding the transparency. It's one of those things that makes sense in hind-sight but will keep you guessing for a while the first time.

        [imgnothumb]http://files.me.com/tlhintoq/eif6dq[/imgnothumb]

        Comment

        • khaing
          New Member
          • Apr 2010
          • 5

          #5
          I found why my procedures doesn't work for transparent button.
          It's my thinking wrong.

          The back color of my form is white. I add a label and set it's image. I put the transparent button onto that label. It's normal that I can see only white color because the form's back color is white.

          When I put a transparent button onto something, I think wrong I can see anything what's at the back of it (in this case, the color of image).

          I want transparent button because my buttons are rounded rectangle so the corners of buttons are white.

          Thanks all for replying.

          Comment

          Working...