Solved

Converting Points to Pixels

Posted on 2004-08-29
5
1,763 Views
Last Modified: 2008-01-09
Specifically, MS Word returns Points when you retrieve the window width & height.  I need to convert it into pixels so I can position my form relative to the MS Word document.  

OR… If you know how to retrieve the window Top, Left, Height, & Width from Word in pixels; that would remove my need for the conversion.  This must work with all versions of MS Word (Word 97 and newer).

Thanks
0
Comment
Question by:chilltemp
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 4

Expert Comment

by:Daniellus83
ID: 11929314
I think I understand you problem, but can you give me (/us) some code where you'd retrieve e.g. the MS Word Points... This would spare us a lot figuring out...
0
 
LVL 2

Accepted Solution

by:
cfry001 earned 125 total points
ID: 11929416
I am a little unsure whether you are using VBA from Word or VB.Net or what but ...
If you are using .Net, the function you need is Microsoft.VisualBasic.Compatibility.VB6.TwipsPerPixelX (and Y) A Twip is 1/20 of a point, so from there the conversion is straight forward.
0
 
LVL 28

Assisted Solution

by:iboutchkine
iboutchkine earned 125 total points
ID: 11930304
1 Twip = 1/20 Point
1 Point = 1/72 Inch
1 Twip = 1/1440 Inch
0
 

Author Comment

by:chilltemp
ID: 11931195
Thanks.  For some reason I wasn’t able to use the Microsoft.VisualBasic.Compatibility library.  But you got me thinking from a slightly different point of view, and I did a search for “Pixels per inch”.  That search returned: http://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21042559.html

  Dim WordApp As Object
  Dim TheDoc As Object
  WordApp = CreateObject("Word.Application")
  TheDoc = WordApp.Documents.Open(DocLocalFile)

  Dim WordRec As System.Drawing.Rectangle
  WordRec = New System.Drawing.Rectangle( _
      TheDoc.ActiveWindow.Application.Left, TheDoc.ActiveWindow.Application.Top, _
      TheDoc.ActiveWindow.Application.Width, TheDoc.ActiveWindow.Application.Height)


**** New Code: ****

  Dim G As Graphics
  G = CreateGraphics()
  WordRec = New System.Drawing.Rectangle( _
      TheDoc.ActiveWindow.Application.Left / 72 * G.DpiX, _
      TheDoc.ActiveWindow.Application.Top / 72 * G.DpiY, _
      TheDoc.ActiveWindow.Application.Width / 72 * G.DpiX, _
      TheDoc.ActiveWindow.Application.Height / 72 * G.DpiY)
0
 
LVL 2

Expert Comment

by:cfry001
ID: 11937317
Yeah, that looks like a better way of doing it ...
I had heard that Twips were no longer used in .Net but didn't know what they were replaced with. You probably just need to add a reference to your project to get access to the compatibility library I think it is called the Visual Basic .Net compatibility library in the list of references. could come in handy if you are an ex-vb6 programmer or are converting VB6 code.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question