-1

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

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Xml.Linq;
    using Outlook = Microsoft.Office.Interop.Outlook;
    using Office = Microsoft.Office.Core;
    using System.Windows.Forms;

    namespace OutlookAddIn1
    {
    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");
    }



    #region VSTO generated code

    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InternalStartup()
    {
        this.Startup += new System.EventHandler(ThisAddIn_Startup);
        this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
    }

    #endregion
}

}

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

  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Windows.Forms;


  namespace OutlookAddIn1
  {
  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..

4

1 回答 1

1

执行以下操作,首先创建 的新实例ThisAddin class,然后从新的Validate method中调用。ThisAddin classcreated instance

改变:

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

        private void button1_Click(object sender, EventArgs e)
        {

        }
    }

至:

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

            private void button1_Click(object sender, EventArgs e)
            {
                ThisAddin ta = new ThisAddin();
                ta.Validate();
            }
        }

将 ThisAddin 类从:

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");
    }
}

至:

public partial class ThisAddIn
    {
    //constructor
    public 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");
    }

笔记:

确保类被放置在相同的`Namespace: Namespaces description

于 2013-08-24T17:05:53.273 回答