简体   繁体   中英

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

I'm fairly new to C# and 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#. 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. 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. How do I get the two to communicate like that? Thanks for the help.

Windows form:

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM