Solved

Converting Points to Pixels

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
help with issues with ReportViewer in VS2015 5 37
vb.net checkbox 7 41
Help with LINQ and XML 10 26
VB.NET Repostiory Pattern 7 8
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
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…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Edureka is one of the fastest growing and most effective online learning sites.  We are here to help you succeed.

911 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

16 Experts available now in Live!

Get 1:1 Help Now