当前位置:编程学习 > C#/ASP.NET >>

如何在后台生成一个System.Windows.Forms.RichTextBox,并且显示在一个Border里?

下面代码不行:

 System.Windows.Forms.RichTextBox rtb=new  System.Windows.Forms.RichTextBox();
 this.border.Child=rtb;


--------------------编程问答-------------------- 这是在WPF下调用WinForms的RichTextBox的例子。

原来,挺简单的,不过估计很多人不知道:


首先,添加引用:右击References-->.NET-->System.Windows.Forms;

接着,添加引用:右击References-->Browse-->C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.0\Framework\v3.0\WindowsFormsIntegration.dll

然后,在后代代码中写上:


System.Windows.Forms.Integration.WindowsFormsHost host = new System.Windows.Forms.Integration.WindowsFormsHost();
System.Windows.Forms.RichTextBox rtb = new System.Windows.Forms.RichTextBox();
host.Child = rtb;
this.border.Child = host;




补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,