首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VC >

Form1中使用其它种的方法

2013-10-12 
Form1中使用其它类的方法Form1.h文件中:namespace Test {public ref class Form1 : public System::Window

Form1中使用其它类的方法




Form1.h文件中:
namespace Test {
     public ref class Form1 : public System::Windows::Forms::Form
     {
     private: static String^ string;

     public:static System::String^ getForm1String(){
            return string;
}

     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
    string = textBox1->Text;
    ttest::client^ testclient = gcnew ttest::client();
    textBox2->Text = testclient->getclientstring();
}
      };
}

在stdafx.h文件中:

#include "Form1.h"
namespace ttest {
public ref class client{

public:System::String^ getFormString(){
   return Test::Form1::getForm1String();
   }
};
}


现在做的程序遇到和这个一样的问题,我不知道该怎么解决,编辑提示错误(只有Form1.h中有错误):
error C2653: “ttest”: 不是类或命名空间名称
error C2065: “client”: 未声明的标识符
error C2065: “testclient”: 未声明的标识符
error C2653: “ttest”: 不是类或命名空间名称
error C2061: 语法错误 : 标识符“client”
error C2065: “testclient”: 未声明的标识符
error C2227: “->getclientstring”的左边必须指向类/结构/联合/泛型类型

这几个错误都是不识别ttest这个类倒至的,但我在Form1中,编码的时候,明明当输入ttest这个命名空间,加::后会出现client这个类,也就是编码的时候能识别,编辑不识别,无果,请大神请教!



自定义类 FORM1类 函数使用
[解决办法]
非静态成员函数自然要通过相应的句柄来调用了,可以把main函数中Application::Run(gcnew Form1());的gcnew Form1()另外保存,比如gcroot<Form1^> f = gcnew Form1();,然后就可以调用f->setXXX();了
无法解析的标记说明你的函数实现跟函数声明对应不上,可以检查看看函数名、命名空间是否有拼写错误
[解决办法]
Application->OpenForms["Form1"]->成员

热点排行