从另一个函数更改窗体"visible"属性?
Change a forms "visible" property from another function?
我需要从另一个函数更改testAppGUI的(testAppGUI是一种表单)的可见属性。该函数位于单独的文件中,不在类中。
如果我尝试做
testAppGUI::Visible = false;
我只是收到错误
C2597:非法引用非静态成员"系统::窗口::窗体::控件::可见"
如果我尝试像这样创建对象的实例
testAppGUI^ formProperty = gcnew testAppGUI;
然后做
formProperty->Visible = false; nothing happens?!
谁能解释一下如何做到这一点?
提前谢谢。
编辑:这是更多代码
在测试应用中.cpp
#include "stdafx.h"
#include "testAppGUI.h"
using namespace testApp;
[STAThreadAttribute]
int main(array<System::String ^> ^args)
{
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Application::Run(gcnew testAppGUI());
return 0;
}
在测试应用图形用户界面中
#pragma once
#include "HideAndShowGUI.h"
namespace testApp {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO;
public ref class testAppGUI : public System::Windows::Forms::Form
{
public:
testAppGUI(void)
{
InitializeComponent();
}
protected:
~testAppGUI()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
...
#pragma region Windows Form Designer generated code
void InitializeComponent(void)
{
...
}
#pragma endregion
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
hideGUI();
}
};
}
隐藏和显示GUI
.cpp#include "stdafx.h"
#include "testAppGUI.h"
using namespace testApp;
void hideGUI(){
//Hide the form, this function should be able to be called by all functions in the program. Not just from forms!
}
void showGUI(){
//Unhide/Show the form, this function should be able to be called by all functions in the program. Not just from forms!
}
hideGUI 和 showGUI 在 HideAndShowGUI.h 中声明
如果您已经有一个要隐藏的表单实例,则必须将对要更改属性的函数传递对该表单的引用。
您可以通过直接提供表单作为函数的参数来执行此操作,或者如果函数是类的成员,则可以将表单传递给类(和类的实例)(并将其存储为成员变量)。 其中哪一个更适合您取决于您的特定上下文,如果没有您的更多代码,我们就无法访问该上下文。
注意:您的第一个狙击手与第二个狙击手冲突:在第一个狙击中,您将form1
用作变量,在第二个狙击手中用作类型。 如果您已经有变量 form1
,则可以设置其属性:
form1->Visible = false;
相关文章:
- 如何导出包含具有"std::unique_ptr"值的"std::map"属性的
- C++概念:如何使用'concept'检查模板化结构的属性?
- 子目录是否继承属性,例如add_definitions,include_directories和父Cmakelist.t
- 通过指向指针数组的指针访问子类的属性
- MSVC是否支持C++11样式的属性而不是__declspec
- QML:修改在不同QML文件(而非main.QML)中定义的子对象的属性
- 类的C++属性似乎已重新初始化
- Qt Quick-如何仅从c++代码与qml属性交互
- 用概念检查属性的类型
- C++如何将同一类的实例作为属性
- 按多个属性排序
- 主函数参数的属性
- "perf_event_attr"结构的"read_format"属性的选项到底是什么?
- C++删除未使用的类属性会导致 std::logic_error
- 无法使用 SWIG 在 Python 中实例化C++类(获取属性错误)
- 使用内存地址访问结构的属性值
- C++调用具有 *this 属性的单个帮助程序函数
- C++ 在堆栈中包含多态属性的类对象存储
- C++ 命名参数习惯用语 - 未设置字符串属性
- 从另一个函数更改窗体"visible"属性?