如何从新表单访问在vsto单词功能区中创建的方法

时间:2017-12-14 20:12:09

标签: c# wpf vsto

/ 嗨,我正在为word 2010创建一个vsto加载项。这个加载项包含一个按钮,单击该按钮会打开一个用于输入的新表单(使用几个文本框和标签以及一个按钮) )。理论上,当我单击确定按钮时,程序将获取文本框文本并调用vsto加载项功能区类中的方法。出于某种原因(我意识到这可能是一个简单的错误,但不确定我哪里出错了),我无法使用OK按钮调用该方法(在vsto功能区类中找到)(引用它的问题?)。以下是代码 /

的一部分

// RIBBON的代码

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

}
}

1 个答案:

答案 0 :(得分:0)

我相信你要找的是:

Globals.Ribbons.Ribbon1.MyMethod(string, string);