LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default How to initialize the column width from pixels. Pixel to Char conversion

Hi,

Programmatically I try to initialize the column width from a pixel
value I have. I found a conversion function but doesn't function quite
accurate. In below code, GetScreenXPI returns 96 on my computer. My
default width is 8.43 char (64 pixel). PioxToCharX in this case would
return 8 char for 64 pixels. What am I missing? Any help would be
appreciated.

Reto
www.xcellery.com

' Conversion code
'*********************

Public Const TWIPS_PER_INCH = 1440 ' number TWIP units per
inch
Public Const TWIPS_PER_CHAR_X = 120 ' number TWIP units per
logical character

Public Function PixToCharX(ByVal pixels As Long) As Long
PixToCharX = ((pixels / GetScreenXDPI) * TWIPS_PER_INCH) /
TWIPS_PER_CHAR_X
End Function

Function GetScreenXDPI() As Long
Dim hdc As Long
hdc = CreateICA("DISPLAY", vbNullString, vbNullString, 0)
If (hdc < 0) Then
GetScreenXDPI = GetDeviceCaps(hdc, 88) 'screen res x
DeleteDC (hdc)
End If
End Function

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can we change units of column width to pixels? sappi Excel Discussion (Misc queries) 1 March 10th 09 05:18 AM
column pixels vs column width Marc C Excel Discussion (Misc queries) 2 March 20th 08 11:21 PM
How to initialize the column width from pixels. Pixel to Char conversion [email protected] Excel Programming 0 April 19th 06 07:47 PM
with same font and pixel number different column width Christian Setting up and Configuration of Excel 0 February 1st 05 04:41 PM
Column width in pixels how? robbie de sutter Excel Programming 2 August 20th 03 08:41 AM


All times are GMT +1. The time now is 02:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"