简体   繁体   English

非静态字段所需的对象引用

[英]Object reference required for non-static field

I am getting this error message in this context: 我在这种情况下收到此错误消息:

int left = 0;
            int top = 0;
            int width = 0;
            int height = 0;
            Word.Range rng2 = rng;
            Microsoft.Office.Interop.Word.Window.GetPoint(out left, out top, out width, out height, rng);

How can I fix it? 我该如何解决?

Window is non static, you need to create a new instance of it in order to use it. 窗口是非静态的,您需要创建它的新实例才能使用它。

 //using Word = Microsoft.Office.Interop.Word;
                Word.Application application = this.Application;

                //Not sure how you create your application object, just including this incase you're not using VSTO
                //Word.Application application =
                //(Word.Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Word.Application");
                //OR
                //Word.Application application = new Word.Application();

                Word.Range rng = application.ActiveDocument.Range();
                int left,top,width,height = 0;
                Word.Range rng2 = rng;
                application.ActiveWindow.GetPoint(out left, out top, out width, out height, rng);

OR 要么

Microsoft.Office.Interop.Word.Window window = application.ActiveWindow;
            window.GetPoint(out left, out top, out width, out height, rng);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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