开发者

How do I get the scroll position from Microsoft Word

开发者 https://www.devze.com 2022-12-13 13:12 出处:网络
I want to position an image on the page the user is looking at, however I cannot find how to get the currentl开发者_JAVA百科y visible page/scroll in pixels.

I want to position an image on the page the user is looking at, however I cannot find how to get the currentl开发者_JAVA百科y visible page/scroll in pixels.

Anybody know which object and property could give me that?


Are you trying to control Word from outside Word or is it an integrated control?

I think you want: Object oMissed = doc.Paragraphs[1].Range;

This code below is for an InlineShape, not Shape object. Shape object is for text-wrapping.

Code:

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

   }



}

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

Similarly, you may want to look at this SO question on How do I get the scroll position from Microsoft Execl -- which I just realized was asked by you..

0

精彩评论

暂无评论...
验证码 换一张
取 消