Suggestion: Transparent container

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #36028
    Jeremy©JTECH
    Participant

    I've been developing Windows apps for awhile now, and one of the components I always find myself wanting is a simple, transparent container. Grouping several controls together in a single, invisible parent makes it much easier to hide or move all children controls at once, and there are other benefits as well. Call it TsContainer or something simple like that.

    Over the years I've used the standard VCL TPanel control (ParentBackground = true) and also the AC TsPanel control (SkinSection = 'CHECKBOX'), and for the most part these work well as transparent containers. However, using a panel (which normally paints its own background and requires an underyling WinAPI window object) as a simple transparent container seems like wasteful overkill. Also, there are certain limitations with this approach.

    For example, refer to the image I've attached. Both sets of TsLabels [A & B] have the same settings, but they appear in different colors. Labels A are contained in an invisible TsPanel (SkinSection = 'CHECKBOX'), while Labels B are contained in another TsPanel (SkinSection = 'TOOLBAR'). Both parent panels are contained in another TsPanel (also with SkinSection = 'TOOLBAR'). Ideally both sets of labels should look like B.

    I'm guessing that the labels check their parent's SkinSection to see how they should paint themselves, but unfortunately they aren't handling transparency correctly. If a label (or any control really) sees that its parent is transparent, it should then look at its parent's parent (or even higher) until it finds the SkinSection information it needs to paint itself properly.

    Also, using CHECKBOX as a transparent SkinSection is not very obvious to new users. I would add a standard TRANSPARENT skin section, or even better, introduce a new transparent container control as I've suggested. Obviously I use transparency a lot, since it greatly improves the visual appearance of my software. Thank you for considering my suggestion. 🙄

    [attachment=6657:AC Sample.jpg]

    #51525
    mol
    Participant
    'Jeremy©JTECH' wrote:
    I always find myself wanting is a simple, transparent container. Grouping several controls together in a single, invisible parent

    A groupbox is not an option?

    http://stackoverflow.com/questions/8927802/transparent-group-box

    #51526
    TCount
    Participant
    'Jeremy©JTECH' wrote:

    It would be great! :a3:

    #51527
    Jeremy©JTECH
    Participant
    'mol' wrote:

    A groupbox is not an option?

    http://stackoverflow…arent-group-box

    Can the border on TGroupBox be made invisible? Either way, TPanel can also work, it just seems like overkill. It also doesn't work well with Alpha Controls, which is why I often have to use TsPanel with a CHECKBOX SkinSection. Even then, there are still issues.

    #51528
    mol
    Participant
    'Jeremy©JTECH' wrote:
    Can the border on TGroupBox be made invisible?

    I would think so. You could derive your own groupbox and override the paint method (untested):

    Code:
    type
    tBorderless=class(TGroupbox)
    protected
    procedure Paint; Override;
    end;

    procedure tBorderless.Paint;
    var
    R: TRect;
    begin
    with Canvas do
    begin
    R := ClientRect;
    Brush.Color := Color;
    FillRect(R);
    end;
    end;

    #51529
    Jeremy©JTECH
    Participant
    'mol' wrote:

    I would think so. You could derive your own groupbox and override the paint method (untested):

    You could do much the same with practically any TWinControl descendent, no? Also, the code you posted will overwrite the group box's client area, the opposite of transparent. Simply NOT painting anything can work (if I remember right), but I also recall this introducing certain visual artifacts.

    You don't even have to derive your own component to make a TPanel transparent, but as I mentioned before, it doesn't always play nicely with Alpha Controls. It just makes sense (to me) to have a standard, lightweight, invisible component that does nothing more than group other child controls together for alignment, sizing, and other similar layout purposes.

    Another common thing I like to do is nest a TFrame inside another TFrame or TForm (it helps organize and compartmentalize really complicated forms/frames that otherwise would have thousands of lines of code in them). However, in order to get a nested child frame to be partially transparent, I have to add a TsFrameAdapter and set its SkinSection to CHECKBOX. Wouldn't a new TRANSPARENT setting make more sense (and be more obvious to new users)?

    #51530
    mol
    Participant
    'Jeremy©JTECH' wrote:
    the code you posted will overwrite the group box's client area

    Well, you wanted to get rid of the border… 😉

    Here's another approach which should work: http://delphidabbler.com/tips/74

    Quote:
    Wouldn't a new TRANSPARENT setting make more sense

    Don't know; I hardly ever work with transparency. If I recall correctly, there are always problems associated with TWinControls and transparency. What happens if you put those on a semi-transparent TFrame? Isn't the painting too much of a hassle?

    -Uwe

    #51531
    Jeremy©JTECH
    Participant
    'mol' wrote:

    Well, you wanted to get rid of the border… 😉

    Here's another approach which should work: http://delphidabbler.com/tips/74

    Lol true… thanks for the link too. I might have to dabble with making my own control at some point.

    Quote:

    Don't know; I hardly ever work with transparency. If I recall correctly, there are always problems associated with TWinControls and transparency. What happens if you put those on a semi-transparent TFrame? Isn't the painting too much of a hassle?

    -Uwe

    You're probably right (the article you linked indicates as much), but somehow the people behind AC have already got it working pretty well. I've found a few little issues over the years, but most or all of them have been resolved by the AC developers. The image I posted in my first post highlights a new issue I found, but that should be fixable as well.

    They have already done the hard work of making transparency work, so why not wrap that functionality in a more lightweight component that doesn't carry all the extra TPanel/TsPanel baggage? AC gives us these beautifully skinned forms and panels, which only increases my desire to embed transparent frames and panels within them.

    #51553
    Support
    Keymaster

    Hello

    TRANSPARENT skin section will be added in the version 9.

    This skin section will be internal and will work even if skin haven't such section.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.