Solved

Converting Points to Pixels

Posted on 2004-08-29
5
1,564 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
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now