none
Adding a winform to OutLookAddIn project? RRS feed

  • Question

  • Im working on a OutLookAddIn Project and for a particualr scenario i added a winform to the outllookaddin project, so when the user first loads the project the winform opens up...After entering his UserId and Password and clicking the submit button i want to call a method that is in the class 'ThisAddIn' but im not able to access the method from windows form class, im getting the error as ''OutlookAddIn1.ThisAddIn' does not contain a constructor that takes 0 arguments''....how can i get rid of this...just posting some sample code below..

        public partial class ThisAddIn
        {
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
        }

        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
        }


        public void Validate()
        {
            MessageBox.Show("Success");
        }
       }

    My Winform class from where i want to access the method 'Validate

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }

    In the button1_Click event i want t0 access the method validate, so need some advice from experts here..


    Saturday, August 24, 2013 5:08 PM

Answers

  • Hi,

    You can write code like below:

    public static void Validate()
        {
            MessageBox.Show("Success");
        }
    
    private void button1_Click(object sender, EventArgs e)
        {
    ThisAddIn. Validate();
        }
    

    BTW, why did you put your validate method in the add-in class rather than Form1? Does the user first loads the project means the add-in loads? How do you show the WinForm, I didn’t see the code in ThisAddIn_Startup method.

    Tuesday, August 27, 2013 12:35 AM

All replies

  • Are you calling ThisAddIn.Validate()? How are you trying to call the method?

    Ken Slovak MVP - Outlook

    Monday, August 26, 2013 5:46 PM
    Moderator
  • Hi,

    You can write code like below:

    public static void Validate()
        {
            MessageBox.Show("Success");
        }
    
    private void button1_Click(object sender, EventArgs e)
        {
    ThisAddIn. Validate();
        }
    

    BTW, why did you put your validate method in the add-in class rather than Form1? Does the user first loads the project means the add-in loads? How do you show the WinForm, I didn’t see the code in ThisAddIn_Startup method.

    Tuesday, August 27, 2013 12:35 AM