如何将 Winform 添加到 WindowsFormsHost
我的主要项目在 WPF 下,在我的解决方案中,我有:
- winform ,名称为 Form1
- wpfForm ,名称为 MainWindow.xaml
我想完成这项工作:如果单击按钮,我会在 MainWindow 中显示 Form1 ,与 MDI 完全相同强>
My Main Project Is Under WPF, In My Solution I have:
- winform which name is Form1
- wpfForm which name is MainWindow.xaml
I want to do this job: if button clicked, I show the Form1 in MainWindow Exactly Like MDI
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
感谢您在这种情况下帮助我,您的回答对我很有帮助
但我找到了我的目标:
我只是想在 wpf windows 中使用 Windows 窗体(form1)(不是我的 Windows 窗体控件)
在我的表单代码中,我只是将 form1 的继承更改为 Usercontrol 而不是这样的 Form
,因此我可以在我的 Windosformshost 中使用此用户控件,因为我的表单现在是用户控件(干得好)
但我遇到了另一个问题,我的控件没有视觉风格,因此我在 msdn 中搜索,我从此链接得到了答案 visual_Problem 答案在 enable_visual
我的意思是,在 winformshot 托管我的 Windows 表单(来源是我的用户控件)之前,我应该编写以下代码:
感谢您的评论。
最好的问候,霍斯林。
Thanks for helping me in this case,your answers really help me
but i found my aim :
i just wanted to use windows form (form1) in to wpf windows (not my windows form controls )
in my form code,i just change the inheritance of form1 to Usercontrol instead of Form like this
therefor i can use this usercontrol in my windosformshost because my form is usercontrol now(nice job)
but i got another problem , my controls didn't have visual sytle , cause of that i search in msdn , i got the answer from this link visual_Problem and the answer was in enable_visual
i mean , before the winformshot host my windows form(ofcource my usercontrol) i should write this code :
Thanks for your comments.
Best Regards, Hothreeyn.
来自 MSDN: WindowsFormsHost 类
我认为您应该在 WPF 中处理 MDI 布局,然后在 WPF 子窗口中放置 WindowsFormsHost 控件,创建 Windows 窗体控件后,将其分配为 WindowsFormsHost 的子级。
from MSDN: WindowsFormsHost Class
I think you should handle the MDI layout in WPF and then inside the WPF child windows you put the WindowsFormsHost control and once you created the windows forms control you assign it as child of the WindowsFormsHost.
请参阅 MSDN 文档 WPF 中的
WindowsFormsHost
控件。文档底部有一个示例,展示了如何使用它将 WinForms 控件集成到 WPF 中。您需要做的就是将MaskedTextBox
更改为您的控件:Form1
。Refer to the MSDN Documentation for the
WindowsFormsHost
control in WPF. There is an example at the bottom of the documentation to show how it can be used to integrate WinForms control into WPF. All you will need to do is change theMaskedTextBox
to your control:Form1
.据我了解,您无法让整个 WinForm 与 WPF 进行互操作。您可以通过 WindowsFormHost 将 WinForm 控件放置在 WPF 表面上,但不能放置在窗体上。
如果您可以将 WinForm 表单的所有内容打包到 WinForm UserControl 中,那么您应该能够实现这一目标。
As I understand it, you can't get an entire WinForm to interoperate with WPF. You can place WinForm controls on WPF surfaces via the WindowsFormHost, but not a form.
If you can package all of the contents of your WinForm Form into a WinForm UserControl, than you should be able to pull this off.
通过使用
WindowsFormHost
控件,您可以在 WPF 中使用 Windows 窗体控件。您可以参考此链接。
Using
WindowsFormHost
control, you can use a Windows Forms control in WPF.you can refer this link.
WPF 没有对 MDI 的本机支持,您可以使用此 wpfmdi.codeplex.com 或更复杂的此 chronoswpf.codeplex.com
WPF has no native support for MDI, you can use this wpfmdi.codeplex.com or more complex this one chronoswpf.codeplex.com