Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Converting Points to Pixels

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Integration Management Part 2
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month12 days, 3 hours left to enroll

916 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