问题描述
我在winform中放一按健:buttonGo,编成库,供MFC调对此对话框(面板),现在按下winform中按健:buttonGo,会执行MFC中的CMFCDlg::OnClickButtonGo了。。。但我想也执行buttonGo_MouseUp,要如何做委托??我试了很多都不行。(即是我想要捕捉buttonGo的按下后的松开)谢谢!以下是我用MFC调用C#winform的做法://C#winform中,做成库供MFC调用1.建C#winform库的项目:WinFormB,面板中放一按健:buttonGo2.Designer.cs中:publicSystem.Windows.Forms.ButtonbuttonGo;(此句改成:public)//--------------------------------------------------------//MFCDlg项目属性中:1.(配置属性->常规->公共语言运行支持:)选:公共语言运行时支持(/clr)2.(通用属性->引用)添加浏览新引用WinFormB.dll//MFCDlg对话框设计中:工具箱拉入一个控件statiText:IDC_STATIC_BOTTOM//MFCDlg对话框.H中:BEGIN_DELEGATE_MAP(CPipeVideoDlg)EVENT_DELEGATE_ENTRY(OnClickButtonGo,System::Object^,System::EventArgs^)END_DELEGATE_MAP()CWinFormsControl<WinFormB::UserControl1>m_CtrlStaticBottom;//声明自建public:voidOnClickButtonGo(System::Object^sender,System::EventArgs^e);//MFCDlg对话框.cpp中:加入:voidCMFCDlg::DoDataExchange(CDataExchange*pDX)//记住不是About的{CDialog::DoDataExchange(pDX);DDX_ManagedControl(pDX,IDC_STATIC_BOTTOM,m_CtrlStaticBottom);}在OnInitDialog()中加入:m_CtrlStaticBottom.GetControl()->buttonGo->Click+=MAKE_DELEGATE(System::EventHandler,OnClickButtonGo);//自建:voidCMFCDlg::OnClickButtonGo(System::Object^sender,System::EventArgs^e){AfxMessageBox("Go");}
解决方案
本帖最后由 keith_cheung 于 2015-08-27 11:24:48 编辑
解决方案二:
m_CtrlStaticBottom.GetControl()->buttonGo->Click+=MAKE_DELEGATE(System::EventHandler,OnClickButtonGo);楼主你要绑定MouseUp也稍微开动下脑筋啊
解决方案三:
引用1楼shingoscar的回复:
m_CtrlStaticBottom.GetControl()->buttonGo->Click+=MAKE_DELEGATE(System::EventHandler,OnClickButtonGo);楼主你要绑定MouseUp也稍微开动下脑筋啊
这个只是Click的,我改过了,成mouse_up,key_up之类,后面的都有改动,但就不成功,才来问。(key_up也能成功)
解决方案四:
我这样做好了:
解决方案五:
m_CtrlStaticLeft.GetControl()->buttonPower->Click+=MAKE_DELEGATE(System::EventHandler,OnClickButton);m_CtrlStaticLeft.GetControl()->buttonZoomWide->MouseDown+=MAKE_DELEGATE(System::Windows::Forms::MouseEventHandler,OnMouseDownButton);m_CtrlStaticLeft.GetControl()->buttonZoomWide->MouseUp+=MAKE_DELEGATE(System::Windows::Forms::MouseEventHandler,OnMouseUpButton);来人可以结贴了。。。