Home > Net >  Delphi VCL style on child window
Delphi VCL style on child window

Time:05-24

I have a simple unit with a form and an OnClick even to create a new Form when the main form is clicked.

unit DPS.Main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, DPS.Materials, System.Generics.Collections, Vcl.ExtCtrls, DPS.ChildForm;

type
  TForm6 = class( TForm )
    procedure FormClick( Sender : TObject );

    private
      { Private declarations }

    public
      { Public declarations }

    end;

var
  Form6: TForm6;

implementation

{$R *.dfm}

procedure TForm6.FormClick( Sender : TObject );
  var
    Form1 : TForm;

  begin
    Form1 := TForm.Create( Self );

    //Form1.Parent := Self;

    Form1.Show();
  end;

end.

If I don't assign a parent for the created form I get the default Windows 11 style.

No Form Parent

if I uncomment out the line

//Form1.Parent := Self;

I get the sexy Windows 7 lick of paint. Ughh.

Form with a parent

This semms to be a default VCL Styles skin, as, surprisingly if I change the appearance to one of the inbuilt VCL styles such as carbon this is not a problem.

Any thoughts on this?

CodePudding user response:

This has nothing to do with VCL styles, it is standard Windows behaviour.

You get the same behaviour on any themed Windows version and not only in Delphi applications.

You are not really supposed to have a bordered window as a child of another window in a non-MDI setup. That's very unusual and strange. Almost no Windows application does that. (And Win32 MDI is quite ancient too.)

It works (albeit with a few quirks), but Windows will not give the child window the full set of visual effects, as you observe.

There's not much you can (or should) do about that.

Your best option is not to do strange things like this: don't let a bordered window be a child of another window.

  • Related