DelphiFeeds.com

  • Dashboard
  • Popular Stories
  • Trending Stories
  • Feeds
  • Login
Trending now

HeidiSQL Is A Lightweight Open Source Database Management Tool Built In Delphi

Learn How To Use C++ Explicit Virtual Overrides In Windows Development

Learn Python With The 5 Best Python GUI Libraries Video

Brook Framework

Trial – TMS Scripter

Trial – TMS VCL Chart

Trial – TMS VCL Cloud Pack

Trial – TMS VCL UI Pack

Trial – TMS VCL WebGMaps

Get These Visually Stunning FireMonkey Styles Free To Enhance User Experience In Your Delphi Apps

VCL Styles: Master The Secrets Of Beautiful Modern Apps In Windows 10

grep for Delphi .dproj file containing copy commands for certain DLLs

Powerful Cross Platform Multitrack Music Recording Software Built In Delphi FireMonkey

Ultra-Fast Enterprise-Grade List And Label Reporting Tool For Delphi

Learn An Efficient Way to Use C++ Extern Templates For Robust Windows Development

Dim Out the Main Form of an Application When a Modal Form (/Dialog) is Displayed

1
zarkogajic zarkogajic 2 years ago in Delphi, dialogs, messagedlg, TApplicationEvents 0

Dim Main Form From Dialog
Dialog windows you use to display critical information to the user are, in most cases, displayed modally. A modal window (form) is the one where the application can’t continue to run until the modal window is closed. Delphi’s ShowMessage, InputBox and MessageDlg, for example, display a modal form to the user waiting for some action. Your custom dialogs are displayed using the ShowModal method of a form.

Dimmer – a device for varying the brightness of light

To emphasize the importance of a modal form and the information it presents, you could gray out the main form of the application when the modal form is activated.

Here’s how to add a dim-out effect to your main form when modal forms are waiting for the user input.

  • Have a main form in your application. (Or some other form you want to dim).
  • Add a new form to the project. This will be the “dimmer” form.
  • Drop the TApplicationEvents component on the main form
  • Handle OnModalBegin and OnModalEnd events…

The dimmer form is created at application startup – and since it is not the main form, it will not be displayed initially.

The Display procedure aligns the dimmer form above the main form and gets displayed before any modal form is shown. This happens in the ApplicationEvent’s OnModalBegin event. OnModalEnd ensures that dimmer form is hidden until needed next time.

procedure TDimmerForm.FormCreate(Sender: TObject);
begin
  AlphaBlend := true;
  AlphaBlendValue := 128;
  BorderStyle := bsNone;
end; 

The above is the OnCreate event handler for the dimmer form. By using the AlphaBlend property and the AlphaBlendValue you can make the form translucent. As it will be displayed over the main form, we want it to create the dim-out effect. BorderStyle ensures this form has no border, no caption bar, no title buttons.

The Display procedure aligns the dimmer form above the main form:

type
  TDimmerForm = class(TForm)
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    procedure Display(const dimForm : TForm);
  end;

...

procedure TDimmerForm.Display(const dimForm: TForm);
begin
  with Self do
  begin
    Left := dimForm.Left;
    Top := dimForm.Top;
    Width := dimForm.Width;
    Height := dimForm.Height;

    Show;
  end;
end; 

Finally, handle the OnModalBegin and OnModalEnd events of the TApplicationEvents component on the main form:

procedure TMainForm.ApplicationEvents1ModalBegin(Sender: TObject);
begin
  if Assigned(DimmerForm) then DimmerForm.Display(self);
end;

procedure TMainForm.ApplicationEvents1ModalEnd(Sender: TObject);
begin
  if Assigned(DimmerForm) then DimmerForm.Hide;
end;

And … that’s it.

You can also decide to “Time Out a Message Dialog – Auto Close a Dialog Window After Some Time / Seconds” since we know no user is actually reading what the dialog has to say.

Trending Stories

  • Learn How To Use C++ Explicit Virtual Overrides In Windows...

  • Learn Python With The 5 Best Python GUI Libraries Video

  • Trial – TMS VCL WebGMaps

  • Trial – TMS VCL UI Pack

  • Trial – TMS VCL Cloud Pack

Embarcadero GetIt

  • Brook Framework

    Microframework which helps to develop web Pascal applications.

  • Trial - TMS Scripter

    Add the ultimate flexibility and power into your apps with native Pascal or Basic scripting and […]

  • Trial - TMS VCL Chart

    DB-aware and non DB-aware feature-rich charting components for business, statistical, financial […]

  • Trial - TMS VCL Cloud Pack

    TMS VCL Cloud Pack is a Delphi and C++Builder component library to seamlessly use all major cloud […]

  • Trial - TMS VCL UI Pack

    Create modern-looking & feature-rich Windows applications faster with well over 600 components […]

  • Learn Delphi Programming
  • Learn C++
  • Embarcadero Blogs
  • BeginEnd.net
  • Python GUI
  • Firebird News
  • Torry’s Delphi Pages
Copyright DelphiFeeds.com 2021. All Rights Reserved
Embarcadero
Login Register

Login

Lost Password

Register

Lost Password