我在通过单击 c++ builder 中的按钮关闭 form1 和打开 form3 时遇到问题。
我已经尝试过这段代码:
#include "Welcome.h"
#include "Login.h"
void __fastcall TForm1::LoginButtonClick(TObject *Sender)
{
TForm1 *CurrentForm = new TForm1(this);
CurrentForm->Close();
TForm3 *NewForm = new TForm3(this);
NewForm->Show();
}
TForm1 *CurrentForm = new TForm1(this);
CurrentForm->Close();`
是代码中不起作用的部分。
我可以更改什么以使
form1
在单击按钮时关闭?
摆脱
CurrentForm
。您正在创建一个全新的表单,只是为了立即关闭它。您需要在 Close()
对象上调用 this
:
void __fastcall TForm1::LoginButtonClick(TObject *Sender)
{
Close(); // this->Close();
TForm3 *NewForm = new TForm3(this);
NewForm->Show();
}
请注意,
TForm1
通常是MainForm
的默认名称,如果您Close()
MainForm
,那么您的应用程序将退出。