How to fade some components in the background to highlight a Tpanel on them?

Asked

Viewed 1,493 times

1

I have a main screen, with some Tpanels and other components, and one of these Tpanels would like to create a login screen. By calling this login Tpanel over the other components of the form I am disabling the components below, as if it were a "modal" used on websites. But I would also like to leave the lower components faded (darkened). Is there any simple way to do this using Delphi 7? I’ve done a lot of research and haven’t found it, just animation methods.

See below for an example of what you would like to do:

inserir a descrição da imagem aqui

Thanks in advance for any help!

  • Whoa, Guy, I do with forms, on my main screen, I create a procedure to open the screen, with centralization options, etc. When opening my login form, create another form at runtime, called Background, and in it I put the size of my main screen form, with AlphaBlend and AlphaBlendValue := 200, and other parameters to look cute. In formClose from the Login screen, I will kill this form from behind. What do you think? If you want later I can post an example...

  • 1

    @David, I’m going to first try a way to do this using Panels. If it really is not possible then I will go to another approach, like the one you reported (I had already seen in a forum about it). Thanks anyway! Hug!

1 answer

2


Hello, after the image you sent I broke my head.

The simplest solution I could find was to use the Jedi Project that adds many components.

The idea was to put a panel with alClient transparent and inside it a semi-transparent image and was like this: inserir a descrição da imagem aqui

The code:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, pngimage, ExtCtrls, JvExExtCtrls, JvExtComponent, JvPanel,
  StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    btn1: TButton;
    jvpnl1: TJvPanel;
    Button2: TButton;
    Image1: TImage;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure btn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
  jvpnl1.Align := alClient;
  jvpnl1.Visible := True;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  jvpnl1.Visible := False;
end;

procedure TForm1.btn1Click(Sender: TObject);
begin
  Close;
end;

end.

Unit1.dmf file

object Form1: TForm1
  Left = 192
  Top = 117
  Width = 829
  Height = 413
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object Button1: TButton
    Left = 152
    Top = 40
    Width = 75
    Height = 25
    Caption = 'Button1'
    TabOrder = 0
    OnClick = Button1Click
  end
  object btn1: TButton
    Left = 256
    Top = 152
    Width = 75
    Height = 25
    Caption = 'btn1'
    TabOrder = 1
    OnClick = btn1Click
  end
  object jvpnl1: TJvPanel
    Left = 456
    Top = 80
    Width = 337
    Height = 201
    Transparent = True
    BevelOuter = bvNone
    TabOrder = 2
    Visible = False
    object Image1: TImage
      Left = 0
      Top = 0
      Width = 337
      Height = 201
      Align = alClient
      Picture.Data = {
        0A54504E474F626A65637489504E470D0A1A0A0000000D49484452000000F000
        0000C80806000000D67C6C52000002424944415478DAEDD3010D00301003A1BE
        7F6B13351D9780076EDB1B90741318B204863081214C60081318C20486308121
        4C60081318C204863081214C60081318C204863081214C60081318C204863081
        214C60081318C204863081214C60081318C204863081214C60081318C2048630
        81214C60081318C204863081214C60081318C204863081214C60081318C20486
        3081214C60081318C204863081214C60081318C204863081214C60081318C204
        863081214C60081318C204863081214C60081318C204863081214C60081318C2
        04863081214C60081318C204863081214C60081318C204863081214C60081318
        C204863081214C60081318C204863081214C60081318C204863081214C600813
        18C204863081214C60081318C204863081214C60081318C204863081214C6008
        1318C204863081214C60081318C204863081214C60081318C204863081214C60
        081318C204863081214C60081318C204863081214C60081318C204863081214C
        60081318C204863081214C60081318C204863081214C60081318C20486308121
        4C60081318C204863081214C60081318C204863081214C60081318C204863081
        214C60081318C204863081214C60081318C204863081214C60081318C2048630
        81214C60081318C204863081214C60081318C204863081214C60081318C20486
        3081214C60081318C204863081214C60081318C204863081214C60081318C204
        863081214C60081318C204863081214C60081318C204863081214C60081318C2
        04863081214C60081318C20486308121EC030928A029907BE5A9000000004945
        4E44AE426082}
      Stretch = True
      Transparent = True
    end
    object Button2: TButton
      Left = 64
      Top = 32
      Width = 75
      Height = 25
      Caption = 'Button2'
      TabOrder = 0
      OnClick = Button2Click
    end
  end
end
  • Thank you for trying to help, but I’m not sure I understand... You played the Jvpanel in alClient and inside the Jvpanel an image also in alClient, and this image is a PNG or semi-transparent GIF? Or how did you make the image semi-transparent? Thank you!

  • I created a semi-transparent image 80% black in PNG. If you want I send you.

  • Okay, no need, I’ll try to do the same here. But thanks for the attention!

  • Delphi 7 does not have native support for PNG. I installed a component called pngimage, but I’m not being able to simulate what you did. Even with the 80% transparent PNG image and the transparent Jvpanel, when compiling the project the screen turns black. Please, which component supports the PNG format you are using?

  • I also have Delphi 7 and use Pngcomponents: https://www.dropbox.com/s/v2mzussb0wf3wk3/PngComponents.rar?dl=0

  • The base library of this component you are using is the same one I installed, but my library is up to date. But unfortunately I couldn’t make it work at all. Could you please include in the response the DFM file code (unit1.dfm) so I can analyze if you have any property, of any of the components, out of the standard? Thank you!

  • I put the DFM.... I’m trying to use only components of Delphi and nothing... all day trying... I think this is the solution to Delphi 7.... I read that in other versions we can use Alphablend only for the form and keeping the objects solid.

  • Versions of Delphi with Firemonkey already do this with few clicks and little programming. I don’t know if it is possible to use it in your case, but if so, use it! For me, Firemonkey is today what VCL should have been in the past, although Delphi 7 has always been my favorite until XE versions mature more and become usable for me, plus the fact, of course, that I can distribute my systems also to OSX and other platforms.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.