C++ 如何使用按钮在表单之间导航?
我试图创建一个简单的记录存储应用程序,但由于一些愚蠢的原因,C++在添加记录后拒绝让我导航到默认的FrMVIEW .H窗体。 这是我试图执行的代码:C++ 如何使用按钮在表单之间导航?,c++,winforms,visual-studio-2012,managed,openform,C++,Winforms,Visual Studio 2012,Managed,Openform,我试图创建一个简单的记录存储应用程序,但由于一些愚蠢的原因,C++在添加记录后拒绝让我导航到默认的FrMVIEW .H窗体。 这是我试图执行的代码: System::Windows::Forms::DialogResult Result = MessageBox::Show(this,String::Format("Record Added for user {0}, Add another?", txtstaffname),"title", MessageBoxButtons::YesNo,
System::Windows::Forms::DialogResult Result = MessageBox::Show(this,String::Format("Record Added for user {0}, Add another?", txtstaffname),"title", MessageBoxButtons::YesNo, MessageBoxIcon::Information);
if(System::Windows::Forms::DialogResult::Yes == Result)
{
//Do something
}
else
{
this->Close;
frmview::Show;
}
当我尝试执行调试器时,出现以下异常:
11 IntelliSense: a pointer-to-member is not valid for a managed class $PROJECTDIR$\frmnew.h 444 12 Application1
现在,我尝试返回的表单是View Records表单,它也用于返回当前的Add Records(frmnew.h)表单,我在两个表单上都包含了以下标题:
frmview.h(查看记录):
frmadd.h(添加记录):
我的计算机系统运行Windows 8.1,并且已安装Visual Studio 2012(.NET 4.5)
<>如果是我,我会使用C++或VB.NET,但是作为我们作业的一部分,我们必须使用C++。
任何帮助都会很好,谢谢。我认为您在双重包容方面遇到了问题。 您正在包括“frmadd.h”,它将包括“frmview.h”等等,无休止地进行 如果需要将某些数据从第二个表单保存到第一个表单,可以使用
属性
在表单中安全导航。
希望这有帮助
注:我认为
Show
方法需要括号:Show()
没有看到更多的代码来确定我不得不假设的问题,因此多解决方案的答案是:
如果存在多个包含问题,则只有在以前未包含的情况下才定义/包含的预处理器指令应能解决该问题:
将.h文件中的全部内容包装到
#pragma once
#ifndef HEADERFILENAMEHERE_H
#define HEADERFILENAMEHERE_H
//.....
original header file contents here
//.....
#endif
但是,根据您输出的错误,我认为您使用的语法是错误的:
看来你需要打电话
frmview->Show(this);
而不是
frmview::Show;
另一种可能性是,您可能需要重新构造代码,使其更符合以下要求:
//SecondForm.cpp
#include "StdAfx.h"
#include "FirstForm.h"
#include "SecondForm.h"
System::Void CppWinform::SecondForm::button1_Click(System::Object^ sender, System::EventArgs^ e)
{
FirstForm^ firstForm = gcnew FirstForm();
firstForm->Show();
this->Hide();
}
System::Void CppWinform::FirstForm::button1_Click(System::Object^ sender, System::EventArgs^ e) {
SecondForm^ secondForm = gcnew SecondForm();
secondForm->Show();
this->Hide();
}
让我知道你进展如何,如果你需要更多信息,我很乐意帮助:)
frmview::Show;
//SecondForm.cpp
#include "StdAfx.h"
#include "FirstForm.h"
#include "SecondForm.h"
System::Void CppWinform::SecondForm::button1_Click(System::Object^ sender, System::EventArgs^ e)
{
FirstForm^ firstForm = gcnew FirstForm();
firstForm->Show();
this->Hide();
}
System::Void CppWinform::FirstForm::button1_Click(System::Object^ sender, System::EventArgs^ e) {
SecondForm^ secondForm = gcnew SecondForm();
secondForm->Show();
this->Hide();
}