如何在 FireMonkey 中访问 ComboBox 中的 ListBox 和 ComboEdit 中的 VScrollBar?

问题描述 投票:0回答:1

我需要访问

VScrollBar
TListBox
TComboBox
TComboEdit
,以便找到其中的
TThumb
(使用
EnumControls
方法)并设置自定义
OnMouseEnter
OnMouseLeave
OnMouseDown
OnMouseUp
事件,如下所示:

class TScrollThumb : public TCppInterfacedObject<TFunc__2<TControl*, TEnumControlsResult>> {

public:

    TEnumControlsResult __fastcall Invoke(TControl* Control) {

        if (Control->ClassNameIs("TThumb")) {

            Control->OnMouseEnter = MouseEnter;
            Control->OnMouseLeave = MouseLeave;
            Control->OnMouseDown = MouseDown;
            Control->OnMouseUp = MouseUp;

            return TEnumControlsResult::Stop;

        }

        return TEnumControlsResult::Continue;

    }

};

if (ComboBox->ListBox->VScrollBar) ComboBox->ListBox->VScrollBar->EnumControls(new TScrollThumb);

// TScrollBar *scrollbar = ComboBox->ListBox->GetVScrollBar();
// if (scrollbar) scrollBar->EnumControls(new TScrollThumb);

VScrollBar
属性是
Fmx::Layouts::TCustomScrollBox
的受保护成员,而
GetVScrollBar()
Fmx::Layouts::TCustomScrollBox
的私有成员,但即使将它们公开也没有任何作用,我仍然无法访问
VScrollBar

同样的方法对于

TThumb
内的
TVertScrollBox
非常有效。这种情况我能做什么?

firemonkey c++builder
1个回答
0
投票

我自己似乎找到了解决办法。有点棘手,但它就像一个魅力。所以我就按原样将其发布在这里:

class TScrollThumb : public TCppInterfacedObject<TFunc__2<TControl*, TEnumControlsResult>> {

public:

    TEnumControlsResult __fastcall Invoke(TControl* Control) {

        if (Control->ClassNameIs("TThumb")) {

            Control->OnMouseEnter = MouseEnter;
            Control->OnMouseLeave = MouseLeave;
            Control->OnMouseDown = MouseDown;
            Control->OnMouseUp = MouseUp;

            return TEnumControlsResult::Stop;

        }

        return TEnumControlsResult::Continue;

    }

};

void __fastcall ListBoxMouseEnter(TObject *Sender) {

    ((TControl*)Sender)->EnumControls(new TScrollThumb);
    // The tricky part: working with a ListBox inside of its own event handler;

}

ComboBox->ListBox->OnMouseEnter = ListBoxMouseEnter;
// Assign an auxiliary event handler to a ListBox that has already been displayed;
© www.soinside.com 2019 - 2024. All rights reserved.