在同一解决方案中访问主表单 [英] Access to main form in same solution

查看:88
本文介绍了在同一解决方案中访问主表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



在我的解决方案中,我有四个项目(三个项目是创建Dll的类库)



我想访问主表单(如下面的贷款项目),在类库(人才)中,怎么做?



关注:贷款项目(是我的项目名称)不是类库。



贷款 - >主要项目(有主要形式)



班级图书馆:

人才

BAl

DAL







非常感谢。

Hi all

In my Solution , I have Four project(three of project is Class Library that Create Dll)

I wanna access to main form(as following in loan project ), in the the class library(talent) , how do it ?

attention: loan project(is my project name) is not the class library.

Loan -> main project (have main-form)

class library :
talent
BAl
DAL



thanks a lot.

推荐答案

不要。



即使尝试也存在问题,例如循环引用:因为你的主表单需要引用你的类库(为了访问你的人才代码,你不能在不设置循环引用的情况下将你的Main项目的引用添加到你的talent项目中,这意味着你的项目永远无法编译(因为对Main项目的任何更改)意味着人才需要重建,这导致主要需要重建,这意味着人才需要重建,等等。



从逻辑上讲,它错了同样 - 你的DLL根本不需要知道关于表示层的任何内容!如果有,你不能在以后更换图层,这是一个坏主意。



相反,请查看在表单处理的库中创建事件,以便在需要时向库提供信息。
Don't.

There are problems with even trying, such as circular references: since your Main form needs to reference your class library (in order to access your "talent" code) you can't add a reference to your Main project to your "talent" project without setting up a circular reference which would mean that your project could never compile (as any change to the Main project means the talent needs to be rebuilt, which causes the main to need rebuilding, which means that talent needs to be rebuilt, and so on.

And logically, it wrong as well - your DLL shouldn't need to know anything about the presentation layer at all! If it does, you can't replace a layer at a later date, which is a bad idea.

Instead, look at creating events in the library which the form handles to provide information to the library when it needs it.


这篇关于在同一解决方案中访问主表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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