[C ++] [windows forms]我无法连接类 [英] [C ++] [windows forms] I can not connect classes

查看:64
本文介绍了[C ++] [windows forms]我无法连接类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我是
我有一个MyForm.h类和一个Dialog.h类。

MyForm.h:



解决方案

在MyForm.h中尝试以下更改:


// #include" Dialog.h"  - 已评论,不需要


。 。 。


private:System :: Void menuSearch_Click(System :: Object ^ sender,System :: EventArgs ^ e);





在MyForm.cpp中添加:


System :: Void MyForm :: menuSearch_Click(System :: Object ^ sender,System :: EventArgs ^ e)

{

   Dialog ^ dialog = gcnew Dialog();

   dialog-> ShowDialog();

}





同时从Dialog.cpp中删除 WinMain 。 (假设 MyForm 是主要形式)。 该程序中应该是一个
WinMain



如果你想从 Dialog 访问 MyForm ,那么而不是
'gcnew MyForm'
使用从 Dialog 传递的参数,如下所示(在
menuSearch_Click 中):


  ;  Dialog ^ dialog = gcnew Dialog();

   dialog-> ShowDialog(this);


btnSearch_Click


<跨度>&NBSP;&NBSP; MyForm ^ myForm =(MyForm ^)所有者;







Hello,
I have a class MyForm.h and a class Dialog.h.
MyForm.h:


解决方案

Try the following changes in MyForm.h:

// #include "Dialog.h" -- commented, not needed

. . .

private: System::Void menuSearch_Click( System::Object ^ sender, System::EventArgs ^ e );


In MyForm.cpp add this:

System::Void MyForm::menuSearch_Click( System::Object ^ sender, System::EventArgs ^ e )
{
   Dialog ^ dialog = gcnew Dialog();
   dialog->ShowDialog();
}


Also remove WinMain from Dialog.cpp. (Assuming MyForm is the main form). It should be a single WinMain in the program.

If you want to access MyForm from Dialog, then instead of ‘gcnew MyForm’ use a parameter passed from Dialog, something like this (in menuSearch_Click):

   Dialog ^ dialog = gcnew Dialog();
   dialog->ShowDialog( this );

In btnSearch_Click:

   MyForm ^ myForm = (MyForm^)Owner;




这篇关于[C ++] [windows forms]我无法连接类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆