简体   繁体   English

在C ++ Builder RadioGroup中滚动

[英]Scrolling in C++ Builder RadioGroup

I have RadioGroup with many buttons. 我有许多按钮的RadioGroup。 Now when I add an item, they become smaller and smaller. 现在,当我添加一个项目时,它们变得越来越小。 How is it possible to make them scrollable? 如何使其滚动?

TRadioGroup does not natively support scrolling. TRadioGroup本身不支持滚动。 However, what you can do instead is the following: 但是,您可以执行以下操作:

  1. place a TGroupBox on your UI. 在您的UI上放置一个TGroupBox

  2. place a TScrollBox onto the TGroupBox , set its Align property to alClient , and its BorderStyle property to bsNone . TScrollBox放置在TGroupBox ,将其Align属性设置为alClient ,并将BorderStyle属性设置为bsNone

  3. place a TRadioGroup onto the TScrollBox , clear its Caption property, and set its Left property to -2 and its Top property to -15 (or whatever the TRadioGroup.Font is set to plus a few extra pixels). TRadioGroupTScrollBox ,清除其Caption属性,并将其Left属性设置为-2并将其Top属性设置为-15 (或将TRadioGroup.Font设置为加上一些额外的像素)。 This positioning is needed because you cannot turn off the TRadioGroup 's borders or the space reserved for its Caption . 因为您无法关闭TRadioGroup的边框或为其Caption保留的空间,所以需要此定位。

  4. Tweak the TScrollBox.HorzScrollBar.Range and TScrollBox.VertScrollBar.Range properties so they do not scroll far enough to see the TRadioGroup 's right and bottom borders. 调整TScrollBox.HorzScrollBar.RangeTScrollBox.VertScrollBar.Range属性,以使它们滚动的距离不足以看到TRadioGroup的右边界和底边界。

This way, the buttons appear as if they are part of the TGroupBox , but with the added scrollbar(s). 这样,按钮看起来就像它们是TGroupBox一部分,但是带有添加的滚动条。

屏幕截图

  1. RadioGroup->Items->Count
  2. TRadioGroup component doesn't have an embedded scrollbar, but you can put the radio group on a TScrollBox for a similar effect. TRadioGroup组件没有嵌入式滚动条,但是您可以将单选组放在TScrollBox以获得类似的效果。

    You can use the Buttons collection to refer each button, eg 您可以使用Buttons集合来引用每个按钮,例如

     RadioGroup->Buttons[0]->Height = 5; RadioGroup->Buttons[1]->Top = RadioGroup->Buttons[0]->Top + 10; 

    Anyway a TComboBox could also be a good choice. 无论如何, TComboBox也是一个不错的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM