AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein GUI-Design mit VCL / FireMonkey / Common Controls Delphi Hintergrundform abdunkeln, wenn andere Form Modal geöffnet wird?
Thema durchsuchen
Ansicht
Themen-Optionen

Hintergrundform abdunkeln, wenn andere Form Modal geöffnet wird?

Ein Thema von NoGAD · begonnen am 30. Apr 2024 · letzter Beitrag vom 14. Mai 2024
 
DaCoda

Registriert seit: 21. Jul 2006
Ort: Hamburg
171 Beiträge
 
Delphi 12 Athens
 
#17

AW: Hintergrundform abdunkeln, wenn andere Form Modal geöffnet wird?

  Alt 12. Mai 2024, 09:02
Ich habe mich aber entschieden den Code bzw. Aufruf von Uwe Raabe seinem Basiscode zu verwenden und das "Faden" nicht zu nutzen.
Damit ist der Aufruf aus meiner Sicht schöner/einfacher.

Aufrufbeispiele:
Code:
  ShowModalDimmed(Form, nil);

  ShowModalDimmed(Form, ParentForm);

  ShowModalDimmed(Form, ParentForm, Alphablend, BackColor, Centered);
Function:
Code:
function ShowModalDimmed(aForm: TForm; aParentForm: TForm; AlphaBlendValue: Integer = 100; BackColor: TColor = clGray; Centered: Boolean = True): TModalResult;
var
  Back: TForm;

  Dummy_Rect: TRect;

  targetAlpha: Integer;
  Dummy_Alpha_inc: Integer;
  alphaDiff: Integer;
begin
  Back := TForm.Create(nil);
  try
    Back.AlphaBlend := True;

    targetAlpha := AlphaBlendValue;
    if targetAlpha > 255 then
      targetAlpha := 255;
    if targetAlpha < 1 then
      targetAlpha := 1;

    Back.AlphaBlendValue := targetAlpha;
    Back.Color := BackColor;
    Back.DoubleBuffered := True;
    Back.BorderStyle := bsNone;

    if aParentForm <> nil then begin
      Back.Position := aParentForm.Position;
      Back.RoundedCorners := aParentForm.RoundedCorners;
      Dummy_Rect := GetFormShadow(aParentForm);
      Back.SetBounds(aParentForm.Left + Dummy_Rect.Left, aParentForm.Top + Dummy_Rect.Top, aParentForm.Width - Dummy_Rect.Right, aParentForm.Height - Dummy_Rect.Bottom);
    end else begin
      Back.SetBounds(0, 0, Screen.Width, Screen.Height);
    end;
    Back.Show;

    if Centered then begin
      aForm.Position := poMainFormCenter;
    end;

    Result := aForm.ShowModal;
    Back.Hide;
  finally
    Back.Free;
  end;
end;
Und die Function von Mathias (NoGAD):
Code:
function GetFormShadow(aForm: TForm): TRect;
var
  R1, R2: TRect;
begin
  (* Breite eines Schattens einer TForm *)
  Result := default (TRect);
  if (Win32MajorVersion >= 6) and DwmCompositionEnabled then
  begin
    if DwmGetWindowAttribute(aForm.Handle, DWMWA_EXTENDED_FRAME_BOUNDS, @R1, SizeOf(R1)) = S_OK then
    begin
      R2 := aForm.BoundsRect;
      Result.Left := R2.Left - R1.Left; // Linke Breite des Schattens
      if Result.Left < 0 then
        Result.Left := Result.Left * -1;
      Result.Right := (R2.Right - R1.Right) + Result.Left; // Rechte Breite des Schattens
      if Result.Right < 0 then
        Result.Right := Result.Right * -1;
      Result.Top := R2.Top - R1.Top; // Obere Höhe des Schattens
      if Result.Top < 0 then
        Result.Top := Result.Top * -1;
      Result.Bottom := (R2.Bottom - R1.Bottom) + Result.Top; // Untere Höhe des Schattens
      if Result.Bottom < 0 then
        Result.Bottom := Result.Bottom * -1;
    end;
  end;
Debuggers don’t remove bugs, they only show them in slow-motion.

Geändert von DaCoda (12. Mai 2024 um 09:05 Uhr)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 06:51 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz