Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Converting Points to Pixels

Posted on 2004-08-29
5
Medium Priority
?
1,899 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 375 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 375 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

730 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