简体   繁体   English

您如何从Visual Studio中的其他项目/命名空间/解决方案访问数据/功能?

[英]How do you access data/functions from a different project/namespace/solution in Visual Studio?

I'm fairly new to C# and asp.NET. 我是C#和ASP.NET的新手。 I was wondering if it's possible (and if so, how) to access data/functions from a different project in Visual Studio using C#. 我想知道是否有可能(如果可以,如何)使用C#从Visual Studio中的其他项目访问数据/功能。 I've got two separate projects in VS, one used as an Outlook Add-In, and the other is used as a windows form that displays data from a database and Outlook in a gridview. 我在VS中有两个独立的项目,一个用作Outlook加载项,另一个用作Windows窗体,用于在gridview中显示来自数据库和Outlook的数据。 My goal is to have a button in the ribbon, when clicked, open a windows form outside of Outlook, or at least use the data in the windows form in a form in Outlook. 我的目标是在功能区中有一个按钮,当单击该按钮时,请在Outlook外部打开Windows窗体,或者至少在Outlook窗体中使用Windows窗体中的数据。 How do I get the two to communicate like that? 我如何让两者像这样交流? Thanks for the help. 谢谢您的帮助。

Windows form: Windows表格:

namespace DarwinTask
{
    public partial class frmSearch : Form
    {
        public frmSearch()
        {

Outlook: 外表:

namespace DarwinOutlook
{
    public class DarwinRibbon : Office.IRibbonExtensibility
    {
        public void SearchDarwin(Office.IRibbonControl control)
        {
            if (control.Id == "SearchDarwin")
            {
                //Search function that opens frmSearch            
            }
        }

If you need to access a class / function in another project. 如果您需要访问另一个项目中的类/函数。 Right click the project you want to be able to access it from and add reference. 右键单击要访问的项目,然后添加引用。 Then select the target project with the desired class / function. 然后选择具有所需类/功能的目标项目。 This can either be a dll or another project loaded in your solution. 这可以是一个dll或您的解决方案中加载的另一个项目。

Stick it out you'll get there eventually! 坚持下去,您最终会到达那里!

To access functions and data members of another project say ProjectA in ProjectB , simply add dll of ProjectA in the reference of ProjectB and write " using ProjectA" along with other assembly references where you want to access the data members. 要访问另一个项目的功能和数据成员,例如在ProjectB中添加ProjectA,只需在ProjectB的引用中添加ProjectA的dll,然后在要访问数据成员的地方,将“ using ProjectA”连同其他程序集引用一起写入即可。

When ProjectA is not a dll, add this project in the solution explorer along with ProjectB, and add reference of this project, then again write "using ProjectA", where you want to access its public data members and methods. 当ProjectA不是dll时,将该项目与ProjectB一起添加到解决方案资源管理器中,并添加该项目的引用,然后再次编写“ using ProjectA”,以在其中访问其公共数据成员和方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从C#项目的构建事件中访问Visual Studio解决方案级平台? - How can you access the Visual Studio solution level platform from a C# project's build event? 如何在Visual Studio解决方案中限制对一个项目的访问? - How to limit access to one project in a solution in Visual Studio? 如何从Visual Studio C#中的不同解决方案启动另一个项目? - How to launch another project from a different solution in Visual Studio C#? Visual Studio可扩展性,如何枚举解决方案中的项目? - Visual Studio Extensibility, How do you enumerate the projects in a solution? Visual Studio - Intellisense 无法识别同一解决方案中另一个项目中的命名空间 - Visual Studio - Intellisense not recognizing namespace in another project within same solution 如何从 Visual Studio 解决方案/项目中读取文件? - How to read file from Visual Studio solution/project? 如何从Visual Studio中的项目解决方案中删除其他构建文件 - How to Delete Additional build files from the Project Solution in visual studio 如何从 Visual Studio Package 项目中获取当前的解决方案名称? - How to get the current solution name from a Visual Studio Package project? 如何在 Visual Studio 中管理多个 AWS Lambda 函数? - How do you manage multiple AWS Lambda functions in Visual Studio? 你如何打包视觉工作室aws无服务器项目? - How do you package up a visual studio aws serverless project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM