当TEdit设置为纵向模式时,如何在横向位置显示包含TEdit的矩形?我使用这样的代码,但是在横向位置,当Tedit设置为纵向时,键盘会覆盖Tedit。
procedure TForm1.RestorePosition; begin VertScrollBox1.ViewportPosition := PointF(VertScrollBox1.ViewportPosition.X, 0); Layout1.Align := TAlignLayout.Client; VertScrollBox1.RealignContent; end;
procedure TForm1.UpdateKBBounds; var LFocused : TControl; LFocusRect: TRectF; begin FNeedOffset := False; if Assigned(Focused) then begin
LFocused := TControl(Focused.GetObject);
LFocusRect := LFocused.AbsoluteRect;
LFocusRect.Offset(VertScrollBox1.ViewportPosition);
if (LFocusRect.IntersectsWith(TRectF.Create(FKBBounds))) and
(LFocusRect.Bottom > FKBBounds.Top) then
begin
FNeedOffset := True;
Layout1.Align := TAlignLayout.Horizontal;
VertScrollBox1.RealignContent;
Application.ProcessMessages;
VertScrollBox1.ViewportPosition :=
PointF(VertScrollBox1.ViewportPosition.X,
LFocusRect.Bottom - FKBBounds.Top);
end; end; if not FNeedOffset then
RestorePosition; end;
procedure TForm1.FormFocusChanged(Sender: TObject); begin UpdateKBBounds; end;
procedure TForm1.FormVirtualKeyboardHidden(Sender: TObject; KeyboardVisible: Boolean; const Bounds: TRect); begin FKBBounds.Create(0, 0, 0, 0); FNeedOffset := False; RestorePosition; end;
procedure TForm1.FormVirtualKeyboardShown(Sender: TObject; KeyboardVisible: Boolean; const Bounds: TRect); begin FKBBounds := TRectF.Create(Bounds); FKBBounds.TopLeft := ScreenToClient(FKBBounds.TopLeft); FKBBounds.BottomRight := ScreenToClient(FKBBounds.BottomRight); UpdateKBBounds; end;
procedure TForm1.CalcContentBoundsProc(Sender: TObject;
var ContentBounds: TRectF); begin if FNeedOffset and (FKBBounds.Top > 0) then begin
ContentBounds.Bottom := Max(ContentBounds.Bottom,
2 * ClientHeight - FKBBounds.Top); end; end;
procedure TForm1.Edit1Click(Sender: TObject); begin focus := 'edit1'; end;
procedure TForm1.FormCreate(Sender: TObject); begin if TPlatformServices.Current.SupportsPlatformService(IFMXVirtualKeyboardToolbarService, IInterface(FService1)) then begin
FService1.SetToolbarEnabled(True);
FService1.SetHideKeyboardButtonVisibility(True); end; VertScrollBox1.OnCalcContentBounds := CalcContentBoundsProc; end;
当我在potrait模式下设置Tfocus setfocus时,我想显示在横向位置包含tEdit的矩形。非常感谢