0
我需要從另一個函數改變testAppGUI的(testAppGUI是一個窗體)可見屬性。該函數在一個單獨的文件中,它不在一個類中。從另一個函數更改窗體「可見」屬性?
如果我嘗試做
testAppGUI::Visible = false;
我只是得到錯誤
C2597:非法引用非靜態成員 '系統:視窗:形式:控制::可見'
如果我嘗試創建對象的實例這樣
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
更確切地說,是怎麼做到的?你能給我一個鏈接,解釋如何?或者你能解釋一下嗎? – HalfEvil
@HalfEvil,請提供更多代碼。什麼是form1的定義爲,在那裏你想'Form1中::可見=假;'而來? – earlNameless
我提供更多的代碼,現在:) – HalfEvil