我需要从另一个函数更改 testAppGUI(testAppGUI 是一个表单)的可见属性。该函数在一个单独的文件中,它不在一个类中。
如果我尝试做
testAppGUI::Visible = false;
我只是得到错误
C2597:非法引用非静态成员 'System::Windows::Forms::Control::Visible'
如果我尝试像这样创建对象的实例
testAppGUI^ formProperty = gcnew testAppGUI;
然后做
formProperty->Visible = false; nothing happens?!
任何人都可以解释如何做到这一点?
提前致谢。
编辑:这是更多代码
在 testApp.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;
}
在 testAppGUI.h
#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();
}
};
}
HideAndShowGUI.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 中声明