如何更改窗体上所有控件的标题?[C++生成器]
How to change the caption of all controls on a form? [C++ Builder]
我想将标题设置为所有控件(Tlabel,Tbutton,Teditlabel,Tbitbtn,TGroupBox等(和所有具有语言文件标题的组件(TMenuItems,TActions(。
我的问题是,Caption 在 TComponent、TControl 甚至 TWinControl 中都不公开。更重要的是,一些"通用"控件,如TLabel/TBitBtn,甚至不是从TWinControl派生出来的。
例:
void SetCaptionAll(TComponent *container)
{
for (int i = 0; i < container->ComponentCount; i++)
{
TComponent *child = container->Components[i];
child->Caption = ReadFromFile; <-- This won't work. Caption is private
}
}
最重要的是:我不想使用宏(我认为这就是所谓的宏(:
#define GetCtrlCaption(p)
{ code here }
因为这不可调试。
我需要C++生成器示例,但德尔福也被接受。
适用于所有 TControl 后代:
for i := 0 to ControlCount - 1 do
Controls[i].SetTextBuf('CommonText');
要遍历所有控件,包括像面板这样的子控件,可以使用递归遍历:
procedure SetControlText(Site: TWinControl; const s: string);
var
i: Integer;
begin
for i := 0 to Site.ControlCount - 1 do begin
Site.Controls[i].SetTextBuf(PWideChar(s));
if Site.Controls[i] is TWinControl then
SetControlText(TWinControl(Site.Controls[i]), s);
end;
end;
begin
SetControlText(Self, 'CommonText');
对于像TMenuItems
这样的组件,你可以使用 RTTI - 检查组件是否具有Caption, Text
等属性并设置新字符串。
使用旧式方法的德尔福RTTI示例(新的RTTI自D2010起可用(。不确定它是否适用于生成器
uses... TypInfo
if IsPublishedProp(Site.Controls[i], 'Caption') then
SetStrProp(Site.Controls[i], 'Caption', 'Cap');
相关文章:
- 为什么在Windows上的VS 2019和Clang 9中"size_t"在没有标题的情况下工作
- 对于C++,方括号中的标题必须总是在引号中的标题之上吗
- 库标题在标题中不可见,但在 cmake build 下.cpp文件中完全可见.为什么?
- 为什么我不应该把所有东西都放在标题中?
- WinAPI 检查窗口是否具有常规标题栏
- 如何更改窗体上所有控件的标题?[C++生成器]
- 提升用于解析标题列的精神语法
- 所以我正在为我的学校作业练习继承,但我无法正确实施标题保护
- 如何删除已输入的书以及如何使标题,语言和名称在上面放置空格不会出错?
- 使用类 ?C++ 和 SFML 以及标题中的 15 个字符
- Gtkmm 窗口为空白,不显示任何小部件或标题
- 我将如何在 cpp 中生成一个随机且独特的标题
- std::带有颜色和标题的 clog 包装器无法正确打印整数
- 仅提升计时标题与链接
- 是否有理由在标题中保留完全专用的模板?
- 如何在QGroundControl的标题中放置空格?
- 崇高的林特与叮当在标题中找不到头文件
- C++ - 从 MFC 应用程序启动记事本,并将其默认标题从 "Untitled - Notepad" 更改为其他内容
- 无法在 GLFW 窗口标题中显示'ä'
- 只要我不包含一个标题,重新定义C++关键字合法吗