I was just a bit confused about something sorry. If you have two classes, Ribbon1 and ThisAddIN below. How can I call Example()?
- All are in the same namespace..

public partial class Ribbon1
    {

        private void button1_Click_1(object sender, RibbonControlEventArgs e)
        {
            //Call Example() from ThisAddIn Class
            Example();
        }
    }


public partial class ThisAddIn
    {
        public void Example()
        {
        //Do x,y,z etc
        }
    }

Obviously I've tried running something like:

ThisAddIn test = new ThisAddIn();
test.Example();

I think i'm missing something basic as I don't really work with multiple classes. Mybe this would work?! I just want to know the most appropriate way to do this really..

public partial class Ribbon1 : ThisAddIn
    {

        private void button1_Click_1(object sender, RibbonControlEventArgs e)
        {
            //Call Example() from ThisAddIn Class
            ThisAddIn.Example();
        }
    }


public partial class ThisAddIn
    {
        public void Example()
        {
        //Do x,y,z etc
        }
    }

Thank you

Recommended Answers

All 2 Replies

Unless the method is static, you need an object to call it on. How you go about accessing the method (static, instance, inheritance, etc...) really depends on your design. How do these two classes relate and interact in your application?

You were almost there, tou just needed a line of code (using the first way):

public partial class Ribbon1
    {
 
        private void button1_Click_1(object sender, RibbonControlEventArgs e)
        {
            ThisAddIn test = new ThisAddIn();
            test.Example();

    
        }
    }
 
 
public partial class ThisAddIn
    {
        public void Example()
        {
            //Do x,y,z etc
        }
    }

Regards

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.