设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 270|回复: 8
打印 上一主题 下一主题

[求助]有關打印機編程的問題

[复制链接]
跳转到指定楼层
1#
发表于 2002-7-29 19:38:00 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在ACCESS中,通過打印頁面設置可以詷整預打印報表的布局,
在其中都是以MM(不是meimei,是計量單位)來計算的.
哪麼在針對打印機對象的編寫中該怎樣計算哪?是以像素為單位嗎?
請高手指點計算方法,如5mm,在編程中就是多少,計算方法是什麼?
多多謝.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享分享 分享淘帖 订阅订阅
2#
 楼主| 发表于 2002-7-29 20:32:00 | 只看该作者
這個問題,高手請多指點.我沒有一點思路.多多謝.
3#
发表于 2002-7-29 21:48:00 | 只看该作者
PrtMip Property
               

You can use the PrtMip property in Visual Basic to set or return the device mode information specified for a form or report in the Print dialog box.

Setting

The PrtMip property setting is a 28-byte structure that maps to settings on the Margins tab for a form or report in the Page Setup dialog box.

The PrtMip property has the following members.

Member Description
LeftMargin, RightMargin, TopMargin, BottomMargin A Long that specifies the distance between the edge of the page and the item to be printed in twips.
DataOnly A Long that specifies the elements to be printed. When True (–1), prints only the data in a table or query in Datasheet view, form, or report, and suppresses labels, control borders, grid lines, and display graphics such as lines and boxes. When False (0), prints data, labels, and graphics.
ItemsAcross A Long that specifies the number of columns across for multiple-column reports or labels. This member is equivalent to the value of the Number Of Columns box under Grid Settings on the Columns tab of the Page Setup dialog box.
RowSpacing A Long that specifies the horizontal space between detail sections in units of 1/20 of a point.
ColumnSpacing A Long that specifies the vertical space between detail sections in twips.
DefaultSize A Long. When True, uses the size of the detail section in Design view. When False, uses the values specified by the ItemSizeWidth and ItemSizeHeight members.
ItemSizeWidth A Long that specifies the width of the detail section in twips. This member is equivalent to the value of the Width box under Column Size on the Columns tab of the Page Setup dialog box.
ItemSizeHeight A Long that specifies the height of the detail section twips. This member is equivalent to the value of the Height box under Column Size on the Columns tab of the Page Setup dialog box.
ItemLayout A Long that specifies horizontal (1953) or vertical (1954) layout of columns. This member is equivalent to Across, Then Down or Down, Then Across respectively under Column Layout on the Columns tab of the Page Setup dialog box.
FastPrint Reserved.
Datasheet Reserved.


The PrtMip property setting is read/write in Design view and read-only in other views.
PrtMip Property Example

The following PrtMip property example demonstrates how to set up the report with two horizontal columns.

Type str_PRTMIP
    strRGB As String * 28
End Type
Type type_PRTMIP
    xLeftMargin As Long
    yTopMargin As Long
    xRightMargin As Long
    yBotMargin As Long
    fDataOnly As Long
    xWidth As Long
    yHeight As Long
    fDefaultSize As Long
    cxColumns As Long
    yColumnSpacing As Long
    xRowSpacing As Long
    rItemLayout As Long
    fFastPrint As Long
    fDatasheet As Long
End Type

Sub PrtMipCols(strName As String)
    Dim PrtMipString As str_PRTMIP
    Dim PM As type_PRTMIP
    Dim rpt As Report
    Const PM_HORIZONTALCOLS = 1953
    Const PM_VERTICALCOLS = 1954
    DoCmd.OpenReport strName, acDesign
    Set rpt = Reports(strName)
    PrtMipString.strRGB = rpt.PrtMip
    LSet PM = PrtMipString
    ' Create two columns.
    PM.intColumns = 2
    ' Set 0.25 inch between rows.
    PM.intRowSpacing = 0.25 * 1440
    ' Set 0.5 inch between columns.
    PM.intColumnSpacing = 0.5 * 1440
    PM.intItemLayout = PM_HORIZONTALCOLS
   
    LSet PrtMipString = PM            ' Update property.
    rpt.PrtMip = PrtMipString.strRGB
End Sub
The next PrtMip property example shows how to set all margins to 1 inch.

Sub SetMarginsToDefault(strName As String)
    Dim PrtMipString As str_PRTMIP
    Dim PM As type_PRTMIP
    Dim rpt As Report
    DoCmd.OpenReport strName, acDesign
    Set rpt = Reports(strName)
    PrtMipString.strRGB = rpt.PrtMip
    LSet PM = PrtMipString
    PM.intLeftMargin = 1 * 1440    ' Set margins.
    PM.intTopMargin = 1 * 1440
    PM.intRightMargin = 1 * 1440
    PM.intBotMargin = 1 * 1440
    LSet PrtMipString = PM            ' Update property.
    rpt.PrtMip = PrtMipString.strRGB
End
4#
 楼主| 发表于 2002-7-29 23:44:00 | 只看该作者
catt:多謝,您快把整個幫助文件都復制下來了.這個好復雜,
看來按屏幕像素計算好麻煩,這個打有沒有簡單易懂的.
5#
发表于 2002-7-29 23:53:00 | 只看该作者
我就喜欢看Help文件,有很多东西可以用.你又打错字了,我都不明白"這個打有沒有簡單易懂的".
6#
 楼主| 发表于 2002-7-30 00:46:00 | 只看该作者
不好意思我是用拼音的,下次一定學五筆,我的幫助文件和你的一樣.
我剛纔試了試,在哪來的基礎上都*1400,有點不太正確.
0.5mm*1400)
高手指點,我還是搞不定.
[此贴子已经被HG于2002-7-29 16:46:17编辑过]

7#
发表于 2002-7-30 16:36:00 | 只看该作者
set all margins to 1 inch: 1 * 1440
8#
发表于 2002-7-30 17:01:00 | 只看该作者
Microsoft Knowledge Base Article - Q210590
ACC2000: How to Convert Twips to Pixels
The information in this article applies to:
Microsoft Access 2000

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and a Microsoft Access project (.adp).


Summary
Because Microsoft Access stores dimension/location properties as twips, in certain cases you may have to convert twips to pixels, such as when you call a Windows API function. This article shows you how to do this.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes that you are familiar with the programming language being demonstrated and the tools used to create and debug procedures.
More Information
You can use the following ConvertTwipsToPixels() function to convert twips to pixels. Note that pixels are not always square (the height and width are not the same); therefore, it is necessary to pass in the desired "direction" to use (horizontal or vertical).
Create a new module and type the following in the Declarations section:
Option Explicit

Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, _
  ByVal hdc As Long) As Long
Declare Function GetDeviceCaps Lib "gdi32" (ByVal hdc As Long, _
  ByVal nIndex As Long) As Long

Const WU_LOGPIXELSX = 88
Const WU_LOGPIXELSY = 90
NOTE: You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.
Type the following procedure:
Function ConvertTwipsToPixels (lngTwips as Long, _
   lngDirection as long) As Long

   'Handle to device
   Dim lngDC as long                        
   Dim lngPixelsPerInch as Long
   Const nTwipsPerInch = 1440
   lngDC = GetDC(0)
   
   If (lngDirection = 0) Then       'Horizontal
      lngPixelsPerInch = GetDeviceCaps(lngDC, WU_LOGPIXELSX)
   Else                            'Vertical
      lngPixelsPerInch = GetDeviceCaps(lngDC, WU_LOGPIXELSY)
   End If
   lngDC = ReleaseDC(0, lngDC)
   ConvertTwipsToPixels = (lngTwips / nTwipsPerInch) * lngPixelsPerInch

End Function
To call this function, pass the number of twips you want to convert, and another parameter indicating the horizontal or vertical measurement (0 for horizontal, non-zero for vertical). The following is a sample call:
Function ShowConvert()
   Dim lngOldTwips As Long
   lngOldTwips = 2377
   ShowConvert = ConvertTwipsToPixels(lngOldTwips, 0)
End Function
First Published: Nov 25 1998 5:20AM
Keywords: kbProgramming kbdta kbinfo inf  
Twips and other units
Twips are often used as screen units in ActiveX controls.
1 pica = 1/6 inch
1 point = 1/12 pica
1 twip = 1/20 point
1 twip = 1/567 centimeter
The number of twips per pixel depends on hardware. The next example calculates this for a display monitor (in the current resolution).

{windows.i}

/* 1 twip = 1/1440 inch */

&GLOB LOGPIXELSX  88
&GLOB LOGPIXELSY  90

  DEFINE VARIABLE hdc             AS INTEGER NO-UNDO.
  DEFINE VARIABLE ReturnValue     AS INTEGER NO-UNDO.
  DEFINE VARIABLE PixelsPerInchX  AS INTEGER NO-UNDO.
  DEFINE VARIABLE PixelsPerInchY  AS INTEGER NO-UNDO.

  RUN GetDC IN hpApi (INPUT DEFAULT-WINDOW:HWND,
                      OUTPUT hdc).

  RUN GetDeviceCaps IN hpApi (INPUT hdc,
                              INPUT {&LOGPIXELSX},
                              OUTPUT PixelsPerInchX).

  RUN GetDeviceCaps IN hpApi (INPUT hdc,
                              INPUT {&LOGPIXELSY},
                              OUTPUT PixelsPerInchY).

  RUN ReleaseDC IN hpApi (INPUT DEFAULT-WINDOW:HWND,
                          INPUT hdc,
      
9#
 楼主| 发表于 2002-7-30 20:57:00 | 只看该作者
多謝.catt,我為什麼要對打印機編碼哪?是因為用戶不願自己調整.
因為有幾個報表有點復雜.但只是多增了幾列,須調一下塊大小,和列間距之類的
這些我不想搞的太復雜,在一個也沒時間去搞哪麼復雜.(哪報表中心的哪種)
catt,和各位高手,給點簡單的代碼,學一學.多多謝.
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-11 18:16 , Processed in 0.097361 second(s), 32 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表