私はこのような16x4のグリッドパネルを持っています:
一部の行を非表示にして、下の行を上に移動したい場合があります。コンポーネントのvisibleプロパティをfalseに設定すると、レイアウトが更新されません。
それにもかかわらず、行サイズのタイプは自動に設定されています。
表示するものがないのに、コンポーネントが行の高さをゼロに設定しないのはなぜですか?
私はこのような16x4のグリッドパネルを持っています:
一部の行を非表示にして、下の行を上に移動したい場合があります。コンポーネントのvisibleプロパティをfalseに設定すると、レイアウトが更新されません。
それにもかかわらず、行サイズのタイプは自動に設定されています。
表示するものがないのに、コンポーネントが行の高さをゼロに設定しないのはなぜですか?
表示するものが何もないときにコンポーネントが行の高さをゼロに設定しないのはなぜですか?
その行は、表示されているかどうかではなく、その行のすべての列にコンポーネントがない場合にのみ空と見なされるためです。したがって、同じIsRowEmpty
メソッドが返されます。これを回避するには、可視性の変更についてセル コンポーネントから通知を受ける必要があります。この通知が生成されると、IsRowEmpty
メソッドと同じように行を確認できますが、コントロールが割り当てられているかどうかではなく、表示されているかどうかを確認します。このようなメソッドの結果に基づいて、のサイズValue
を 0 に設定して行を非表示にすることができます。
行または列内のすべてのコントロールが表示されているかどうかをチェックする方法である介在クラスの助けを借りて、次のように書くことができます。これらのメソッドは、特定の行または列にあるすべての既存のコントロールが表示されている場合は True を返し、それ以外の場合は False を返します。
uses
ExtCtrls, Consts;
type
TGridPanel = class(ExtCtrls.TGridPanel)
public
function IsColContentVisible(ACol: Integer): Boolean;
function IsRowContentVisible(ARow: Integer): Boolean;
end;
implementation
function TGridPanel.IsColContentVisible(ACol: Integer): Boolean;
var
I: Integer;
Control: TControl;
begin
Result := False;
if (ACol > -1) and (ACol < ColumnCollection.Count) then
begin
for I := 0 to ColumnCollection.Count -1 do
begin
Control := ControlCollection.Controls[I, ACol];
if Assigned(Control) and not Control.Visible then
Exit;
end;
Result := True;
end
else
raise EGridPanelException.CreateFmt(sInvalidColumnIndex, [ACol]);
end;
function TGridPanel.IsRowContentVisible(ARow: Integer): Boolean;
var
I: Integer;
Control: TControl;
begin
Result := False;
if (ARow > -1) and (ARow < RowCollection.Count) then
begin
for I := 0 to ColumnCollection.Count -1 do
begin
Control := ControlCollection.Controls[I, ARow];
if Assigned(Control) and not Control.Visible then
Exit;
end;
Result := True;
end
else
raise EGridPanelException.CreateFmt(sInvalidRowIndex, [ARow]);
end;
そして、最初の行に示されている使用法:
procedure TForm1.Button1Click(Sender: TObject);
begin
// after you update visibility of controls in the first row...
// if any of the controls in the first row is not visible, change the
// row's height to 0, what makes it hidden, otherwise set certain height
if not GridPanel1.IsRowContentVisible(0) then
GridPanel1.RowCollection[0].Value := 0
else
GridPanel1.RowCollection[0].Value := 50;
end;
私はハッキーな解決策を持っています...オートサイジングを維持します
Procedure ShowHideControlFromGrid(C:TControl);
begin
if C.Parent = nil then
begin
c.Parent := TWinControl(c.Tag)
end
else
begin
c.Tag := NativeInt(C.Parent);
c.Parent := nil;
end;
end;
procedure TForm4.Button1Click(Sender: TObject);
begin // e.g. Call
ShowHideControlFromGrid(Edit5);
ShowHideControlFromGrid(Edit6);
ShowHideControlFromGrid(Edit7);
ShowHideControlFromGrid(Label1);
end;