C# 在OutLookAddIn项目中集成windows窗体并调用OutLookAddIn类窗体winform?
我正在处理一个OutLookAddIn项目,对于一个特定的场景,我在OutLookAddIn项目中添加了一个winform,因此,当用户首次加载项目时,winform将打开…在输入他的用户ID和密码并单击submit按钮后,我想调用类“ThisAddIn”中的方法,但我无法从windows form类访问该方法,我得到的错误是“OutlookAddIn1.ThisAddIn”不包含接受0个参数的构造函数“…我如何才能消除此错误…只需在下面发布一些示例代码C# 在OutLookAddIn项目中集成windows窗体并调用OutLookAddIn类窗体winform?,c#,winforms,outlook-addin,C#,Winforms,Outlook Addin,我正在处理一个OutLookAddIn项目,对于一个特定的场景,我在OutLookAddIn项目中添加了一个winform,因此,当用户首次加载项目时,winform将打开…在输入他的用户ID和密码并单击submit按钮后,我想调用类“ThisAddIn”中的方法,但我无法从windows form类访问该方法,我得到的错误是“OutlookAddIn1.ThisAddIn”不包含接受0个参数的构造函数“…我如何才能消除此错误…只需在下面发布一些示例代码 using System;
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
}
在button1\u Click事件中,我希望访问方法验证,因此需要这里的专家提供一些建议。执行以下操作,首先创建
ThisAddin类的新实例
,然后从新创建的实例
调用ThisAddin类
中的验证方法
更改:
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();
}
}
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");
}
至:
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();
}
}
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");
}
将ThisAddin类更改为:
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();
}
}
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");
}
至:
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();
}
}
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");
}
注意:
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();
}
}
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");
}
确保将这些类放置在相同的名称空间中:
执行以下操作:ThisAddin ta=new ThisAddin();ta.Validate();将此代码放在button1_Click事件中。这是我所厌倦的第一种方法,但这里的问题是编译时错误“OutlookAddIn1.ThisAddIn”不包含接受0个参数的构造函数“……经过6小时的努力才解决了这个问题,所以最后将其发布在这里,以便我可以得到一些帮助这应该可以工作,因为您没有向Validate方法发送任何参数,并且Validate方法不需要任何参数。是否确实调用了正确的验证方法?您可以尝试在button1_click事件中右键单击Validate,然后选择“转到定义”吗?如果您指向正确的“Validate”方法,那么应该可以转到。这里的第一个问题是,在类型ThisAddIn th=new ThisAddIn();…中,我无法创建类“ThisAddIn”的实例;。。我收到编译错误,因为'OutlookAddIn1.ThisAddIn'不包含接受0个参数的构造函数'…啊,我想我明白了,您的ThisAddIn类在同一命名空间中吗?它就在“public partial class”文本的正上方。是的,我的ThisAddin类和Form1类都位于同一名称空间OutlookAddIn1。。