Results 1 to 6 of 6

Thread: [2.0] How to make a transparent clickable button with C# using VS2005?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    11

    Question [2.0] How to make a transparent clickable button with C# using VS2005?

    I mean if I'd put a background image to the windows forms application and the background would already have "button-images" in it, but I would just want the user to be able to click on those buttons and that the program would respond.

    The problem is that I can't make the button invisible and if I can, it can't be clicked. Someone please help!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] How to make a transparent clickable button with C# using VS2005?

    That doesn't sound like a very good idea to me, but if you want to go ahead then just place a Label over that part of the image and set its BackColor to Transparent. You'd then handle the Click event of the Label.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    11

    Re: [2.0] How to make a transparent clickable button with C# using VS2005?

    The color "Transparent" isn't transparent, I chose both BackColor and ForeColor of the label as "Transparent" and it still shows up white... I need it COMPLETELY hidden, yet there. I mean I've seen many programs do this...

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] How to make a transparent clickable button with C# using VS2005?

    When you set the BackColor of certain controls, including the Label, to Transparent it will let the background of the control's parent show through. If you have a Label whose parent is the form and you set its BackColor to Transparent then the form's background will show through, which includes the form's BackColor and BackgroundImage. I know this for a fact. See the screen shot below. That's a form with a BackgroundImage set, then a Panel on that and a Label on that. Both the Panel and Label have their BackColor set to Transparent and, as you can see, the image shows through.

    Now, if you have the Label over some other control, like a PictureBox, then you will still see the form's background, not that of the PictureBox, because it is still the form that is the Label's parent, not the PictureBox.

    Also, there's no point to setting the ForeColor to Transparent. Why would you need to have transparent text when you can simply have no text? Of course, you'll need to set AutoSize to false and manually set the Size of the Label to exactly match the image underneath.
    Attached Images Attached Images  
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    New Member
    Join Date
    May 2010
    Posts
    1

    Re: [2.0] How to make a transparent clickable button with C# using VS2005?

    Is there a way to make the parent of the label the picture box? I need to do the same thing as vanQ. Setting the background image of the form isn't what I need. I need the an invisible clickable button/label/anything above the picture box.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] How to make a transparent clickable button with C# using VS2005?

    Quote Originally Posted by nicolef6 View Post
    Is there a way to make the parent of the label the picture box? I need to do the same thing as vanQ. Setting the background image of the form isn't what I need. I need the an invisible clickable button/label/anything above the picture box.
    There is, and it's exactly what you'd expect: you set the Parent property of the Label to the PictureBox. It has to be done in code though. My advice is to add both the PictureBox and Label to the form in the designer and position them exactly where you want them, then do this in the form's Load event handler:
    vb.net Code:
    1. Me.Label1.Parent = Me.PictureBox1
    2. Me.Label1.Location = Me.PictureBox1.PointToClient(Me.PointToScreen(Me.Label1.Location))
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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