0

我正在使用 C++ Builder 10.3,我的应用程序适用于 Android,请注意我对 C++ Builder 非常陌生

我正在尝试更改 TSpinBox 的字体大小和高度,但我无法更改高度。

我尽最大努力移植以下 Delphi 解决方案
Firemonkey TEdit 高度,但没有任何乐趣,我完全输了。AdjustFixedSize 被宣布为私有我不认为它被覆盖,我也尝试创建一个设置器并调用它,但我再次无法让它工作。我遇到的最大问题是我缺乏 C++ Builder 知识。

标题

class TMySpinBox : public TSpinBox{

public:
protected:
virtual void AdjustFixedSize(const TControl Ref) ;

};

CPP

TMySpinBox::TMySpinBox() : TSpinBox(0){};
void TMySpinBox::AdjustFixedSize(const TControl Ref){
  SetAdjustType(TAdjustType::None);

代码

TMySpinBox* SpinBox1 = new TMySpinBox();

SpinBox1->ControlType=TControlType::Platform;
SpinBox1->Parent=Panel1->Parent;
SpinBox1->Position->Y=16.0;
SpinBox1->Position->X=16.0;
SpinBox1->Min=2;
SpinBox1->Max=99;
SpinBox1->Font->Size=48;
SpinBox1->Visible=true;
SpinBox1->Value=2;

SpinBox1->Align=TAlignLayout::None;
SpinBox1->Height=100;
Width=100;
4

1 回答 1

0

我试了一下并移动了一些东西 - 主要是在自定义的构造函数中TSpinBox。我跳过了使用AdjustFixedSize,因为它似乎没有必要。

myspinbox.h

#ifndef myspinboxH
#define myspinboxH
//---------------------------------------------------------------------------
#include <FMX.SpinBox.hpp>

class TMySpinBox : public TSpinBox {
protected:
    // The correct signature but commented out since I didn't use it:
    //void __fastcall AdjustFixedSize(TControl* const ReferenceControl) override;
public:
    // C++ Builder constructors can be virtual and override which is not
    // standard C++. This is afaik only important if you make a custom component
    // to integrate with the IDE to support streaming it, but I'll make it
    // virtual anyway.

    // This component sets Owner and Parent to the same component. You can change that if
    // you'd like to keep them separate.
    virtual __fastcall TMySpinBox(Fmx::Types::TFmxObject* OwnerAndParent);
};

#endif

myspinbox.cpp

#pragma hdrstop

#include "myspinbox.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)

__fastcall TMySpinBox::TMySpinBox(Fmx::Types::TFmxObject* OwnerAndParent) :
    TSpinBox(OwnerAndParent) // set owner
{
    // set properties
    this->Parent = OwnerAndParent;

    this->Position->Y = 16.0;
    this->Position->X = 16.0;
    this->Min = 2;
    this->Max = 99;
    this->Value = this->Min;

    this->Height = 100;
    this->Width = 100;

    // Remove the styled setting for Size to enable setting our own font size
    this->StyledSettings >>= Fmx::Types::TStyledSetting::Size;

    this->Font->Size = 48;
}

代码

// Let Panel1 own and contain the spinbox and destroy it when it itself is destroyed

TMySpinBox* SpinBox1 = new TMySpinBox(Panel1);

免责声明:仅在 Windows 上测试

于 2020-05-06T19:53:10.607 回答