To have styled form without borders you have to remove seBorder
from form's StyleElements
property.
StyleElements := [seFont, seClient];
But you have to set that property for each and every form. If I understood you correctly you want to show message dialog with Windows border. In that case setting StyleElements
property for form that invokes ShowMessage
will have no effect on dialog box, because that is completely new form.
What you have to do is to somehow set StyleElements
property for dialog form that Delphi creates out of your reach. To do that you have to create your own form StyleHook
and replace TFormStyleHook
registered for all forms.
Just add following unit in your project and all forms will have Windows border, without the need to set it explicitly for every form.
unit WinBorder;
interface
uses
Winapi.Windows,
Winapi.Messages,
Vcl.Themes,
Vcl.Controls,
Vcl.Forms;
type
TWinBorderFormStyleHook = class(TFormStyleHook)
protected
procedure WndProc(var Message: TMessage); override;
public
constructor Create(AControl: TWinControl); override;
end;
implementation
constructor TWinBorderFormStyleHook.Create(AControl: TWinControl);
begin
inherited;
OverridePaintNC := false;
end;
procedure TWinBorderFormStyleHook.WndProc(var Message: TMessage);
begin
inherited;
if Message.Msg = CM_VISIBLECHANGED then
begin
if (Control is TCustomForm) and (seBorder in TCustomForm(Control).StyleElements) then
TCustomForm(Control).StyleElements := [seFont, seClient];
end;
end;
initialization
TCustomStyleEngine.UnRegisterStyleHook(TCustomForm, TFormStyleHook);
TCustomStyleEngine.UnRegisterStyleHook(TForm, TFormStyleHook);
TCustomStyleEngine.RegisterStyleHook(TCustomForm, TWinBorderFormStyleHook);
TCustomStyleEngine.RegisterStyleHook(TForm, TWinBorderFormStyleHook);
finalization
TCustomStyleEngine.UnRegisterStyleHook(TCustomForm, TWinBorderFormStyleHook);
TCustomStyleEngine.UnRegisterStyleHook(TForm, TWinBorderFormStyleHook);
TCustomStyleEngine.RegisterStyleHook(TCustomForm, TFormStyleHook);
TCustomStyleEngine.RegisterStyleHook(TForm, TFormStyleHook);
end.
Removing
seBorder` from the parent formsStyleElements
doesn't do the trick.` – Tom Brunberg