在运行时将 Tframe 添加到另一个 Tframe
我有 2 个 tframe 和一个添加按钮。我试图在按下按钮时将一个 tframe 添加到另一个 tframe 上。但由于我们的原因,我的代码似乎无法工作。它没有像预期的那样添加框架。没有错误或运行,它编译并运行,但是当我按下按钮时它什么也不做。当我向滚动框添加 tframe 时,它就开始工作了,我所做的就是更改要添加的 tframe 的位置。
TFrame2 的代码
void __fastcall TFrame2::AddFrame()
{
int temp = 0;
TFrame1* NewFrame1 = new TFrame1(this);
NewFrame1 ->Parent=this;
TComponentEnumerator * ParentEnum = GetEnumerator();
while(ParentEnum->MoveNext())
{
temp++;
}
NewFrame1 ->SetIndex(temp);
NewFrame1 ->Name = "Frame" + IntToStr(temp);
NewFrame1 ->Top = ( NewFrame1 ->Height ) * (temp);
}
这是我用于 TFrame1 本身的代码
void __fastcall TFrame1 ::SetIndex(int temp)
{
this->temp= temp;
}
int __fastcall TFrame1 ::GetIndex()
{
return this->temp;
}
a lil bg info:我必须将 tframe 添加到另一个 tframe 的原因是这样我可以将一组组件添加到另一组组件上,我不知道任何其他组件方法来做到这一点。后来我将 tframe2 添加到主窗体中。
i have 2 tframes, and an add button. I am trying to add one tframe onto the other when the button is press. but for w.e reason my code can't seem to work. it's not adding the frame like it's suppose to. there is no errors or running, it compiles and runs, but when i press the button it does nothing. i got it to work when i added a tframe to a scrollbox, and all i did was change the location for the tframe to be added.
code for TFrame2
void __fastcall TFrame2::AddFrame()
{
int temp = 0;
TFrame1* NewFrame1 = new TFrame1(this);
NewFrame1 ->Parent=this;
TComponentEnumerator * ParentEnum = GetEnumerator();
while(ParentEnum->MoveNext())
{
temp++;
}
NewFrame1 ->SetIndex(temp);
NewFrame1 ->Name = "Frame" + IntToStr(temp);
NewFrame1 ->Top = ( NewFrame1 ->Height ) * (temp);
}
this is the code i use for TFrame1 itself
void __fastcall TFrame1 ::SetIndex(int temp)
{
this->temp= temp;
}
int __fastcall TFrame1 ::GetIndex()
{
return this->temp;
}
a lil bg info: the reason i have to add tframe to another tframe, is so i can add a group of components onto another group of components, i didn't know any other way to do it. later on i add tframe2 onto the main form.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据您显示的代码,唯一可能出错的事情是您将子框架的
Top
属性设置为超过其父框架的Height
属性的值这样您就不会看到子框架出现在屏幕上,即使它确实存在于内存中。Given the code you have shown, the only thing that could be going wrong is if you are setting the child frame's
Top
property to a value that exceeds theHeight
property of its parent frame so that you would not see the child frame appear onscreen even though it does exist in memory.