码迷,mamicode.com
首页 > Windows程序 > 详细

在类库或winform项目中打开另一个winform项目的窗体

时间:2014-11-12 16:21:43      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:winform   style   blog   http   color   ar   sp   for   文件   

 假设类库或winform项目为A,另一个winform项目为B.那麽在A中添加一个接口,里面有一个Show方法,然后在B中写一个类b继承这个接口,并重写这个方法,具体内容为弹出某个窗体.然后在A中另一个类a中实例化B中的b类,并把它赋给A中的接口,然后调用接口的Show方法就可以弹出B中指定的窗体.

     需要注意的是项目A和项目B需要互相引入对方的EXE或DLL文件.

转自:http://blog.csdn.net/a1027/article/details/2766396

以下为代码部分:

 1 namespace His
 2 {
 3   public interface IShow
 4   {
 5     void Show();
 6   }
 7 }
8 namespace EMRApp 9 { 10 public class CShow:IShow 11 { 12 public void Show() 13 { 14 Form frm = new Form(); 15 frm.Text = "测试EMRAPP窗口"; 16 frm.Show(); 17 } 18 } 19 } 20 21 namespace His 22 { 23 public class CTransfShow 24 { 25 public void aaa() 26 { 27 IShow ish = new CShow(); 28 ish.Show(); //here 29 } 30 } 31 }

namespace His
{
  public partial class Form1 : Form
  {
    public Form1()
    {
    InitializeComponent();
    }
    private void Form1_Load(object sender, EventArgs e)
    {
      CTransfShow ct = new CTransfShow();
      ct.aaa();
    }
  }
}

 

在类库或winform项目中打开另一个winform项目的窗体

标签:winform   style   blog   http   color   ar   sp   for   文件   

原文地址:http://www.cnblogs.com/yexiaoyanzi/p/4092410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!