【问题标题】:Using "System::Windows::Forms::DialogResult::OK" to go back to previous form使用“System::Windows::Forms::DialogResult::OK”返回上一个表单
【发布时间】:2021-07-15 06:48:24
【问题描述】:

我有两个单独的表格 list_of_students_page 和 testing。

我在 list_of_students_page 中有一个按钮,点击它会打开测试表格。我在测试表单中创建了一个按钮以返回 list_of_students_page。

在测试表单中运行按钮时,单击两次即可工作。

我在 Visual Studio 中使用 C++/CLI Windows 窗体。

list_of_students_page.h

private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {

CppCLR_WinformsProjekt1::testing^ testing_f = gcnew CppCLR_WinformsProjekt1::testing;
this->Hide();
testing_f->ShowDialog();
if (testing_f->ShowDialog() == System::Windows::Forms::DialogResult::OK)
{
    this->Show();
}
}

测试.h

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
    this->DialogResult = System::Windows::Forms::DialogResult::OK;
    this->Close();
}

为什么会发生这种情况,我应该如何解决这个问题?

【问题讨论】:

  • 删除 Close() 调用,分配 DialogResult 属性即可关闭对话框。

标签: c++ visual-studio winforms visual-c++ c++-cli


【解决方案1】:

你有:

testing_f->ShowDialog();
if (testing_f->ShowDialog() == System::Windows::Forms::DialogResult::OK)

独立的 ShowDialog 调用并没有什么意义,它确实解释了为什么你必须点击两次按钮(它实际上是不同的对话框实例,它只是出现得太快,你看不到)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 2012-07-31
    • 1970-01-01
    • 1970-01-01
    • 2011-09-09
    • 1970-01-01
    相关资源
    最近更新 更多