如何从新表单访问在 vsto word 功能区中创建的方法
How to access a method created in a vsto word ribbon from a new form
/您好,我正在为 word 2010 创建一个 vsto 加载项。此加载项包含一个按钮,单击该按钮会打开一个新表单供用户输入(使用几个文本框和标签和按钮)。理论是,当我单击“确定”按钮时,程序将获取文本框文本并调用在 vsto 加载项功能区 class 中找到的方法。出于某种原因(我意识到这可能是一个简单的错误,但不确定我哪里出错了),我无法使用确定按钮调用该方法(在 vsto 功能区 class 中找到)(引用中的问题它?)。以下是部分代码/
//色带代码
namespace somenamespace
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Word.Document document = Globals.ThisAddIn.Application.ActiveDocument; }
//This method is used to replace the generic text with the one that we need
//specifically for our document
public void MyMethod(string TextToReplace, string NewText)
{
Word.Find fnd = Globals.ThisAddIn.Application.Selection.Find;
fnd.ClearFormatting();
fnd.Replacement.ClearFormatting();
fnd.Forward = true;
fnd.Wrap = Word.WdFindWrap.wdFindContinue;
fnd.Text = TextToReplace;
fnd.Replacement.Text = NewText;
fnd.Execute(Replace: Word.WdReplace.wdReplaceAll);
}
private void buttonScopingApproval_Click(object sender, RibbonControlEventArgs e)
{
Info_Scoping info_Scoping = new Info_Scoping();
info_Scoping.Show();
}
}
//Info_Scoping 是将为用户输入显示的新 WPF 表单的名称,这是它的代码:
namespace moeRibbon
{
public partial class Info_Scoping : Form
{
public Info_Scoping()
{
InitializeComponent();
}
public void buttonOK_Click(object sender, EventArgs e)
{
Info_Scoping.ActiveForm.Hide();
RegNumber = textBox1.Text;
RegYear = textBox2.Text;
//I need to access the MyMethod() method created in the ribbon class from here, but intellisense doesn't recognize it.
}
public string RegNumber { get; set; }
public string RegYear { get; set; }
}
}
我相信你要找的是:
Globals.Ribbons.Ribbon1.MyMethod(string, string);
/您好,我正在为 word 2010 创建一个 vsto 加载项。此加载项包含一个按钮,单击该按钮会打开一个新表单供用户输入(使用几个文本框和标签和按钮)。理论是,当我单击“确定”按钮时,程序将获取文本框文本并调用在 vsto 加载项功能区 class 中找到的方法。出于某种原因(我意识到这可能是一个简单的错误,但不确定我哪里出错了),我无法使用确定按钮调用该方法(在 vsto 功能区 class 中找到)(引用中的问题它?)。以下是部分代码/
//色带代码
namespace somenamespace
{
public partial class Ribbon1
{
private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
{
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
Word.Document document = Globals.ThisAddIn.Application.ActiveDocument; }
//This method is used to replace the generic text with the one that we need
//specifically for our document
public void MyMethod(string TextToReplace, string NewText)
{
Word.Find fnd = Globals.ThisAddIn.Application.Selection.Find;
fnd.ClearFormatting();
fnd.Replacement.ClearFormatting();
fnd.Forward = true;
fnd.Wrap = Word.WdFindWrap.wdFindContinue;
fnd.Text = TextToReplace;
fnd.Replacement.Text = NewText;
fnd.Execute(Replace: Word.WdReplace.wdReplaceAll);
}
private void buttonScopingApproval_Click(object sender, RibbonControlEventArgs e)
{
Info_Scoping info_Scoping = new Info_Scoping();
info_Scoping.Show();
}
}
//Info_Scoping 是将为用户输入显示的新 WPF 表单的名称,这是它的代码:
namespace moeRibbon
{
public partial class Info_Scoping : Form
{
public Info_Scoping()
{
InitializeComponent();
}
public void buttonOK_Click(object sender, EventArgs e)
{
Info_Scoping.ActiveForm.Hide();
RegNumber = textBox1.Text;
RegYear = textBox2.Text;
//I need to access the MyMethod() method created in the ribbon class from here, but intellisense doesn't recognize it.
}
public string RegNumber { get; set; }
public string RegYear { get; set; }
}
}
我相信你要找的是:
Globals.Ribbons.Ribbon1.MyMethod(string, string);