Einzelnen Beitrag anzeigen

Benutzerbild von ChrisE
ChrisE

Registriert seit: 15. Feb 2006
Ort: Hechingen
504 Beiträge
 
Delphi 10.2 Tokyo Professional
 
#7

Re: Repaint, Invalidate oder doch etwas anderes

  Alt 31. Mär 2006, 09:01
Hallo,

es klappt zwar mit dem direkten Repaint aufruf, doch ich finde man sollte es eher so machen:

in der deklaration der Klasse
Delphi-Quellcode:
protected
  ...
  procedure Paint;override;
  ...
dann noch folgende Anpassungen:
Delphi-Quellcode:
procedure TComboBoxPanel.DragDrop(Source: TObject; X, Y: Integer);
begin
  if (Source is TCustomComboBox) then
  begin
    Canvas.Brush.Color := Color;
    Canvas.FillRect(ClientRect);
    if FItemHeight < (Source as TCustomComboBox).Height then FItemHeight := (Source as TCustomComboBox).Height;
    if FItemList.IndexOf(Source) = -1 then begin // noch nicht in der Liste
      FItemList.Add(Source);
      TCustomComboBox(Source).Parent := Self;
    end;
    Repaint;
  end;
end;
Delphi-Quellcode:
procedure TComboBoxPanel.DrawItems;
var
  I, J, NL, NT : Integer;
  LineRect : TRect;
begin
  //for I := ControlCount -1 downto 0 do RemoveControl(Controls[I]);
  J := 0;
  for I := 0 to FItemList.Count -1 do
  begin
    // Position TCustomComboBox
    NL := FOffset * (i+1) + i * TCustomComboBox(FItemList[i]).Width;
    NT := FOffset * (i+1) + i * TCustomComboBox(FItemList[i]).Height;

    // Draw TCustomComboBox
    with TCustomComboBox(FItemList.Items[I]) do
    begin
      //Parent := Self;
      Left := NL;
      Top := NT;
    end;
    // Draw Link-Lines
    if J = 0 then
    begin
      LineRect.Left := (NL + TCustomComboBox(FItemList.Items[I]).Width) - (FOffset * 2);
      LineRect.Top := (NT + TCustomComboBox(FItemList.Items[I]).Height) + 2;
      Inc(J);
    end
    else
    begin
      LineRect.Right := NL;
      LineRect.Bottom := NT + (TCustomComboBox(FItemList.Items[I]).Height div 2);
      DrawLine(LineRect);
      LineRect.Left := (LineRect.Right + TCustomComboBox(FItemList.Items[I]).Width) - (FOffset * 2);
      LineRect.Top := LineRect.Bottom + FOffset + 3;
    end;
  end;
end;
Delphi-Quellcode:
procedure TComboBoxPanel.Paint;
begin
  inherited;
EDIT:
// if FAutoSize then Height := GetNewHeight;
// Das gehört hier sicher nicht rein
EDIT ENDE
  if FShowGrid then DrawGrid;
  DrawItems;
end;

procedure TComboBoxPanel.RePaint;
begin
  inherited Repaint;
  if FAutoSize then Height := GetNewHeight;
end;
Das ist zwar etwas komplizierter als die Lösung von marabu, aber wer denkt bei der nutzung einer Komponente schon daran diese Per Repaint neu zu zeichnen. Somit sollte sie sich - so finde ich zumindest - selber neu zeichnen.

Gruß, Chris
Christian E.
Es gibt 10 Arten von Menschen, die die Binär lesen können und die die es nicht können

Delphi programming rules
  Mit Zitat antworten Zitat