[英]Dynamically add panel control to a dynamic tabsheet (C++ Builder Rad Studio)?
I have a problem getting the tabPage->Name
value, because it will generate when user click the button, first block of my code will create new tabsheet inside PageControl3
and then I use the static int tabNumber;
我在获取
tabPage->Name
值时遇到问题,因为它将在用户单击按钮时生成,我的代码的第一块将在PageControl3
内创建新的选项卡,然后使用static int tabNumber;
by if
condition to generate the tabPage->Caption
and then I use the caption for tabPage->Name
dynamically. 通过
if
条件生成tabPage->Caption
,然后动态使用tabPage->Name
的标题。
I need the name of that tabsheet to pass it on the Error line. 我需要该选项卡的名称才能在错误行上传递它。
static int tabNumber;
if (tabNumber >= 1) ++tabNumber;
else tabNumber = 1;
PageControl3->Visible = true;
TTabSheet *tabPage = new TTabSheet(PageControl3);
tabPage->PageControl = PageControl3;
tabPage->Caption = UnicodeString("Untitled") + IntToStr(tabNumber);
tabPage->Name = UnicodeString("ts") + tabPage->Caption;
The second part of my code should create new TPanel
inside current tabpage->Name
that was created in the above part of my code, BUT it wont work. 我的代码的第二部分应该在当前的
tabpage->Name
内部创建新的TPanel
,该tabpage->Name
是在我的代码的以上部分中创建的,但是它将无法正常工作。
TPanel *panelPage = new TPanel(tabPage->Name); // Error Line
panelPage->Align = alClient;
panelPage->Name = UnicodeString("panel") + tabPage->Caption;
Error massage: 错误信息:
[bcc32 Error] mainUnit.cpp(50): E2285 Could not find a match for 'TPanel::TPanel(const UnicodeString)'
So I not know how to access the tabPage->Name
value, because that was create dynamically? 所以我不知道如何访问
tabPage->Name
值,因为那是动态创建的?
DB Baxter The constructor requires a component variable/object and not a string with the text of the name. DB Baxter构造函数需要一个组件变量/对象,而不是带有名称文本的字符串。 Such as TPanel *panelPage = new TPanel(tabPage);
如TPanel * panelPage = new TPanel(tabPage); Will that work for you?
那对你有用吗? Do you need to make the panel's parent tabPage?
您需要制作面板的父tabPage吗?
By helping DB Baxter, I think the correct and complete answer for create dynamic TPanel
inside the dynamic TTabSheet
will requires a component variable/object and then for displaying the TPanel
we should use the whatever->show();
通过帮助DB巴克斯特,我认为创建动态的正确和完整的答案
TPanel
动态内TTabSheet
将需要一个组件变量/对象,然后显示TPanel
我们应该用whatever->show();
command, the full code can bee like this: 命令,完整的代码可以像这样:
static int tabNumber = 0;
if (tabNumber >= 1) {
++tabNumber;
} else {
tabNumber = 1;
PageControl3->Visible = true;
}
// create new tab sheet inside PageControl3
TTabSheet *tabSheet = new TTabSheet(PageControl3);
tabSheet->PageControl = PageControl3;
tabSheet->Caption = UnicodeString("Untitled") + IntToStr(tabNumber);
tabSheet->Name = UnicodeString("ts") + tabSheet->Caption;
// create new panel inside the current tab sheet
TPanel *panelBox = new TPanel(tabSheet);
panelBox->Parent = tabSheet;
panelBox->Align = alClient;
panelBox->Name = UnicodeString("panelPage") + IntToStr(tabNumber);
panelBox->BevelOuter = bvNone;
panelBox->ShowCaption = true;
panelBox->Caption = UnicodeString("panel") + tabSheet->Caption;
panelBox->Show();
I hope this code can help anyone to generate the dynamic tab sheet with panel, by the way if you want add some frame to it the following code should use: 我希望这段代码可以帮助任何人生成带有面板的动态标签页,顺便说一句,如果您想为其添加一些框架,则应使用以下代码:
// adding the registration frame to the panel
TregFrame *newRegistration = new TregFrame(panelBox);
newRegistration->Parent = panelBox;
newRegistration->Align = alClient;
Note: don't forget to include your frame in your working file, for example #include "registrationFrame.h"
. 注意:不要忘记在您的工作文件中包含框架,例如
#include "registrationFrame.h"
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.