简体   繁体   中英

System.Windows.Window.Activate() cannot implement Microsoft.Office.Interop.Word.Window.Activate() because it does not have the matching return type?

//Error occurred at line 1:cannot implement'Microsoft.Office.Interop.Word.Window.Activate()' //because it does not have the matching return type of 'void'. //Someone help me fix this error

public partial class Window1 : Window 
{
    public Window1()
    {
        InitializeComponent();
    }

    private void btnSelectWord_Click(object sender, RoutedEventArgs e)
    {
        // Initialize an OpenFileDialog 
        OpenFileDialog openFileDialog = new OpenFileDialog();


        // Set filter and RestoreDirectory 
        openFileDialog.RestoreDirectory = true;
        openFileDialog.Filter = "Word documents(*.doc;*.docx)|*.doc;*.docx";


        bool? result = openFileDialog.ShowDialog();
        if (result == true)
        {
            if (openFileDialog.FileName.Length > 0)
            {
                txbSelectedWordFile.Text = openFileDialog.FileName;
            }
        } 
    }

This problem can be caused by the two namespaces Microsoft.Office.Interop.Word and System.Windows . Try the following to help the compiler to choose the correct type:

public partial class Window1 : System.Windows.Window

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM