控件继承关系
*.h文件
//---------------------------------------------------------------------------
#ifndef Unit1H
#define Unit1H
//---------------------------------------------------------------------------
#include <System.Classes.hpp>
#include <FMX.Controls.hpp>
#include <FMX.Forms.hpp>
#include <FMX.Controls.Presentation.hpp>
#include <FMX.Edit.hpp>
#include <FMX.Types.hpp>
#include <FMX.Layouts.hpp>
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TVertScrollBox *VertScrollBox1;
TLayout *MainLayout1;
TEdit *Edit1;
void __fastcall FormFocusChanged(TObject *Sender);
void __fastcall FormVirtualKeyboardHidden(TObject *Sender, bool KeyboardVisible,
const TRect &Bounds);
void __fastcall FormVirtualKeyboardShown(TObject *Sender, bool KeyboardVisible,
const TRect &Bounds);
void __fastcall FormCreate(TObject *Sender);
private: // User declarations
TRectF FKBBounds;
bool FNeedOffset;
void __fastcall CalcContentBoundsProc(
TObject Sender, TRectF &ContentBounds);
void __fastcall RestorePosition();
void __fastcall UpdateKBBounds();
public: // User declarations
__fastcall TForm1(TComponent Owner);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1* Form1;
//---------------------------------------------------------------------------
#endif
*.CPP文件
//---------------------------------------------------------------------------
#include <fmx.h>
#pragma hdrstop
#include “Unit1.h”
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource ".fmx"
TForm1 Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) {}
//---------------------------------------------------------------------------
void __fastcall TForm1::CalcContentBoundsProc(
TObject* Sender, TRectF &ContentBounds)
{
if (FNeedOffset && FKBBounds.Top) {
ContentBounds.Bottom =
Max(ContentBounds.Bottom, 2 * ClientHeight - FKBBounds.Top);
}
}
//---------------------------------------------------------------------------
void __fastcall TForm1::RestorePosition()
{
VertScrollBox1->ViewportPosition =
PointF(VertScrollBox1->ViewportPosition.X, 0);
MainLayout1->Align = TAlignLayout::Client;
VertScrollBox1->RealignContent();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::UpdateKBBounds()
{
TControl* LFocused;
TRectF LFocusRect;
FNeedOffset = False;
if (this->Focused) {
LFocused = (TControl*)Focused->GetObject();
LFocusRect = LFocused->AbsoluteRect;
LFocusRect.Offset(VertScrollBox1->ViewportPosition.X,
VertScrollBox1->ViewportPosition.Y);
if (LFocusRect.IntersectsWith(TRectF(FKBBounds)) &&
LFocusRect.Bottom > FKBBounds.Top)
{
FNeedOffset = True;
MainLayout1->Align = TAlignLayout::Horizontal;
VertScrollBox1->RealignContent();
Application->ProcessMessages();
VertScrollBox1->ViewportPosition =
PointF(VertScrollBox1->ViewportPosition.X,
LFocusRect.Bottom - FKBBounds.Top);
}
}
if (!FNeedOffset)
RestorePosition();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormFocusChanged(TObject* Sender)
{
UpdateKBBounds();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormVirtualKeyboardHidden(
TObject* Sender, bool KeyboardVisible, const TRect &Bounds)
{
FKBBounds.left = 0;
FKBBounds.top = 0;
FKBBounds.right = 0;
FKBBounds.bottom = 0;
FNeedOffset = False;
RestorePosition();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormVirtualKeyboardShown(
TObject* Sender, bool KeyboardVisible, const TRect &Bounds)
{
FKBBounds = (TRectF)Bounds;
FKBBounds.TopLeft() = ScreenToClient(FKBBounds.TopLeft());
FKBBounds.BottomRight() = ScreenToClient(FKBBounds.BottomRight());
UpdateKBBounds();
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject* Sender)
{
VKAutoShowMode = TVKAutoShowMode::Always;
VertScrollBox1->OnCalcContentBounds = CalcContentBoundsProc;
}
//---------------------------------------------------------------------------