在OutLookAddIn项目中集成一个windows窗体,并调用OutLookAddIn类窗体winform

本文关键字:窗体 OutLookAddIn windows 调用 winform 一个 项目 集成 | 更新日期: 2023-09-27 18:28:49

我正在处理一个OutLookAddIn项目,对于一个特定的场景,我向OutLookAddIn项目添加了一个winform,所以当用户第一次加载项目时,winform会打开。。。在输入了他的UserId和Password并单击提交按钮后,我想调用类"ThisAddIn"中的一个方法,但我无法从windows窗体类访问该方法,我得到的错误是"OutlookAddIn1.ThisAddIn"不包含接受0个参数的构造函数。。。。我怎样才能摆脱这个。。。只是在下面张贴一些示例代码

    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
}

}

我的Winform类,我想从那里访问方法"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)
    {

    }
   }
  }

在按钮1_Click事件中,我想访问方法validate,因此需要这里的专家提供一些建议。。

在OutLookAddIn项目中集成一个windows窗体,并调用OutLookAddIn类窗体winform

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

更改:

    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:命名空间描述