CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Question Opaque controls on a completely transparent form

    Folks,

    As everyone have noticed, the Form class has the Opacity property. It sets the opacity of the form and all of the controls. But is it possible to have opaque controls (e.g. picture boxes) on a transparent form?

    At the moment, I can think of two workarounds.
    (1) Form.Region is set to a disjoint region, which includes only “real estate” under the controls. In this case, what would be the best place to set the region of the form?
    (2) Separate Form object for each control.

    Any suggestion, insight or reference is really appreciated!

    - Nick

  2. #2
    Join Date
    Oct 2005
    Location
    Seattle, WA U.S.A.
    Posts
    353

    Re: Opaque controls on a completely transparent form

    Hello Nick.

    I'm not certain that I'm doing what you had in mind, but I think it is possible to render the form 'invisible' yet have the controls quite visible so that they appear to be 'floating' rather than contained in a form. How ?

    1. On the form properties, set the transparency key to whatever color the BackColor is set while retaining the 100% opacity setting.

    2. set the FormBorderStyle to 'none'

    3. Add the picturebox as one normally would and load your image.

    4. Give some consideration to how you'll close the form ... perhaps a context menu when clicking on the image (or any one of a million and one alternate mechanisms) ?
    Last edited by ThermoSight; February 7th, 2011 at 05:37 PM.

  3. #3
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Re: Opaque controls on a completely transparent form

    Quote Originally Posted by ThermoSight View Post
    1. On the form properties, set the transparency key to whatever color the BackColor is set while retaining the 100% opacity setting.
    ...
    That was illuminating. Thanks.

    One thing that makes this problem a little more interesting is that one of the controls is a picture with irregular outline. The image itself is drawn with only a few colors, so I can use fuchsia as key color for transparency. I know that I can write a straightforward function that will generate a region, provided a bitmap and a color key. Then this region can be assigned to Control.Region property. But is there a standard picture-box-type control that has a built-in feature like Form.TransparencyKey? (Wishful thinking?)

    Color.Transparent constant there is. Is there a way of somehow selecting Color.Transparent and drawing with it?

    Cheers,
    - Nick
    Last edited by kender_a; February 8th, 2011 at 12:32 PM. Reason: more added

  4. #4
    Join Date
    Oct 2005
    Location
    Seattle, WA U.S.A.
    Posts
    353

    Re: Opaque controls on a completely transparent form

    Hi Nick.

    I am unaware of a control property analogous to Form.TransparencyKey, but this might be of some interest to you. Regrettably, I'm in a rush to get out the door or I'd try it myself. Anyway, be that as it may, check this out and see if this item from the Visual Studio 2010 'Help' section has any relevance ...

    This is what I shudda done (and will do in the future) ... oh well, live and learn I guess.
    http://msdn.microsoft.com/en-us/library/wk5b13s4.aspx - let's see if this is any better.

    See ya.

    bill
    Last edited by ThermoSight; February 8th, 2011 at 08:09 PM.

  5. #5
    Join Date
    May 2001
    Location
    Silicon Valley
    Posts
    113

    Re: Opaque controls on a completely transparent form

    Quote Originally Posted by ThermoSight View Post
    This is what I shudda done (and will do in the future) ... oh well, live and learn I guess.
    http://msdn.microsoft.com/en-us/library/wk5b13s4.aspx
    Hey Bill,

    Actually, I was able to find the article from the GUID in the original version of the link.

    The article, however, deals with custom controls. It suggests to call the protected method SetStyle().

    May be, after all, assigning Form.Region is the way to go.

    - Nick

Tags for this Thread

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

Featured