Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   GUI-Design mit VCL / FireMonkey / Common Controls (https://www.delphipraxis.net/18-gui-design-mit-vcl-firemonkey-common-controls/)
-   -   Delphi SetFocus ohne ScrollInView (https://www.delphipraxis.net/125168-setfocus-ohne-scrollinview.html)

stahli 1. Dez 2008 22:25


SetFocus ohne ScrollInView
 
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

stahli 4. Dez 2008 09:38

Re: SetFocus ohne ScrollInView
 
*push*

stahli 9. Dez 2008 15:29

Re: SetFocus ohne ScrollInView
 
So, durch Überschreiben der virtuellen Methode AutoScrollInView ist es realisierbar.
"BlockAutoScrollInView" ist eine neue Variable, die ich nach Bedarf selbst definieren kann.

Delphi-Quellcode:
procedure TDesignerBox.AutoScrollInView(AControl: TControl);
begin
  if not BlockAutoScrollInView then
    inherited;
end;
stahli


Alle Zeitangaben in WEZ +1. Es ist jetzt 07:14 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz