Einzelnen Beitrag anzeigen

Benutzerbild von stahli
stahli

Registriert seit: 26. Nov 2003
Ort: Halle/Saale
4.337 Beiträge
 
Delphi 11 Alexandria
 
#1

SetFocus ohne ScrollInView

  Alt 1. Dez 2008, 22:25
Hallo alle,

meinen Controls in einer TscrollBox weise ich den Focus zu. Dadurch wird ScrollInView ausgeführt und das entsprechende Control komplett in den sichtbaren Bereich verschoben, was ich (unter bestimmten Umständen) verhindern möchte.

Delphi-Quellcode:
procedure TWinControl.SetFocus;
var
  Parent: TCustomForm;
begin
  Parent := GetParentForm(Self);
  if Parent <> nil then
    Parent.FocusControl(Self) // <===
  else if ParentWindow <> 0 then
    Windows.SetFocus(Handle)
  else
    ValidParentForm(Self);
end;

procedure TCustomForm.FocusControl(Control: TWinControl);
var
  WasActive: Boolean;
begin
  WasActive := FActive;
  SetActiveControl(Control); // <===
  if not WasActive then SetFocus;
end;

procedure TCustomForm.SetActiveControl(Control: TWinControl);
begin
  if FActiveControl <> Control then
  begin
    if not ((Control = nil) or (csDesigning in ComponentState) or ((Control <> Self) and
      (GetRealParentForm(Control) = Self) and ((csLoading in ComponentState) or
        Control.CanFocus))) then
      raise EInvalidOperation.Create(SCannotFocus);
    FActiveControl := Control;
    if not (csLoading in ComponentState) then
    begin
      if FActive then SetWindowFocus;
      ActiveChanged;
    end;
  end;
end;

Kann jemand sagen, wie ich das automatische ScrollInView verhindern kann und die Controls trotzdem den Fokus erhalten?
Die letzten beiden Methoden sind nicht virtual.

Danke
Stahli
  Mit Zitat antworten Zitat