Frage

I have trouble in minimizing all my MDIChildren and came across MDIChild to minimize not activated properly

My code to minimize all my children is:

procedure TMainWindow.MinimizeAll1Click(Sender: TObject);
var
  i: Integer;
begin
  for i := 0 to MDIChildCount - 1 do begin
    MDIChildren[i].WindowState := wsMinimized;
    //ShowWindow(MDIChildren[i].Handle, SW_MINIMIZE)
  end;
end;

I tried both methods (SW_MINIMIZE and wsMinimized) but for some reason one last MDI children form gets NOT minimized. However if you try to minimize all the children again, it works. The minimize all works in the MDIAPP example from Delphi XE. How do I properly minimize all MDI Children in 1 routine?

War es hilfreich?

Lösung

Minimizing an MDI child window changes the order in which the forms appear in MDIChildren[]. This indexed property always returns the active MDI child in MDIChildren[0]. So, the cleanest way to do what you want is to take a copy of all the forms first, and then start minimizing.

var
  i: Integer;
  Forms: array of TForm;
....
SetLength(Forms, MDIChildCount);
for i := 0 to high(Forms) do
  Forms[i] := MDIChildren[i];
for i := 0 to high(Forms) do
  Forms[i].WindowState := wsMinimized;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top