Thema: Delphi Editcontrol

Einzelnen Beitrag anzeigen

Benutzerbild von Jens Schumann
Jens Schumann

Registriert seit: 27. Apr 2003
Ort: Bad Honnef
1.644 Beiträge
 
Delphi 2009 Professional
 
#2

Re: Editcontrol

  Alt 12. Jul 2003, 17:32
Hallo,
wenn Du in die VCL-Sourcen schaust liegt meines erachtens das Problem in UpdateHeight und AdjustHeight.
Das Problem liegt hier zu einem hier:
Code:
  if FAutoSize{ and (BorderStyle = bsSingle)} then
  begin
    ControlStyle := ControlStyle + [csFixedHeight];
    AdjustHeight;
  end
   else
    ControlStyle := ControlStyle - [csFixedHeight];
Es wird nur AdjustHeigth aufgerufen wenn BorderStyle=bsSingle ist.
Zum anderen liegt noch ein Problem in AdjustHeight:
Code:
  if NewStyleControls then
  begin
    if Ctl3D then I := 8 else I := 6;
     I := GetSystemMetrics(SM_CYBORDER) * I;
  end else
I:=6 wenn Ctl§d=False. 6 ist zuviel wenn BorderStyle auf bsNone steht besser wäre 2.
Die beiden Methoden sind leider private. So kannst Du Sie nicht überschreiben.
Wenn Du jedoch die die VCL-Sourcen Datei StdCtrls.pas mit in das Verzeichnis Deiner Komponente kopierst kannst Du die Änderungen direkt in der Datei machen. Das hat aber folgenden Haken -> Du kannstDeine Komponente nicht mit Sourcen weitergeben. Wg Lizenzbestimmungen und so. Du müsstest auch die geänderte StdCtrls.pas weitergeben. Das ist verboten.
Wenn Dir das aber egal ist, kannst Du die beiden Methoden wie folgt abändern
Delphi-Quellcode:
procedure TCustomEdit.UpdateHeight;
begin
  if FAutoSize{ and (BorderStyle = bsSingle)} then //einmal hier
  begin
    ControlStyle := ControlStyle + [csFixedHeight];
    AdjustHeight;
  end
   else
    ControlStyle := ControlStyle - [csFixedHeight];
end;

procedure TCustomEdit.AdjustHeight;
var
  DC: HDC;
  SaveFont: HFont;
  I: Integer;
  SysMetrics, Metrics: TTextMetric;
begin
  DC := GetDC(0);
  GetTextMetrics(DC, SysMetrics);
  SaveFont := SelectObject(DC, Font.Handle);
  GetTextMetrics(DC, Metrics);
  SelectObject(DC, SaveFont);
  ReleaseDC(0, DC);
  if NewStyleControls then
  begin
    if Ctl3D then I := 8 else I := 6;
    If BorderStyle=bsNone then // und einmal hier
      I:=2;
    I := GetSystemMetrics(SM_CYBORDER) * I;
  end else
  begin
    I := SysMetrics.tmHeight;
    if I > Metrics.tmHeight then I := Metrics.tmHeight;
    I := I div 4 + GetSystemMetrics(SM_CYBORDER) * 4;
  end;
  Height := Metrics.tmHeight + I;
end;
Du könnest auch die Höhe der Komponente verkleinern, dann ist der Text auch in der Mitte. Dann ist die Höhe aber Fix. D.h. bei einer Font Änderung wird die Höhe nicht angepasst.
  Mit Zitat antworten Zitat