2009-12-02 60 views

回答

0

您是否試圖從外部Word控制Word或者它是一個集成控件?

我想你想:Object oMissed = doc.Paragraphs[1].Range;

下面這段代碼是一個InlineShape,而不是形狀對象。 Shape對象用於文本包裝。

代碼:

using System;  
using System.Collections.Generic;  
using System.ComponentModel;  
using System.Data;  
using System.Drawing;  
using System.Linq;  
using System.Text;  
using System.Windows.Forms;  
using Word = Microsoft.Office.Interop.Word; 


namespace WordAddIn3 
{ 

    public partial class Form1 : Form 
    { 

     public Form1() 
     { 

      InitializeComponent(); 

     } 

     private void button1_Click(object sender, EventArgs e) 
     { 

      Word.Application wdApp = Globals.ThisAddIn.Application; 
      Word.Document doc = wdApp.ActiveDocument; 

      string fileName = "c:\\testimage.jpg"; //the picture file to be inserted 

      Object oMissed = doc.Paragraphs[1].Range; //the position you want to insert 
      Object oLinkToFile = false; //default 
      Object oSaveWithDocument = true;//default 

     doc.InlineShapes.AddPicture(fileName, ref oLinkToFile, ref oSaveWithDocument, ref oMissed); 
     } 

    } 



} 

微軟:HOWTO: How To Get 32-bit Scroll Position During Scroll Messages

同樣,你可能想看看這太問題上How do I get the scroll position from Microsoft Execl - 我才意識到有人問你..

+0

在期間滾動不會幫助我,我很害怕。在我的應用程序進入遊戲之前,用戶可能已經滾動了。我希望Execl的答案會導致Word的答案,但API看起來不夠完美。 – 2009-12-02 14:08:48

+0

Gotcha。看到我編輯的消息。 – 2009-12-02 14:13:40