打印和打印机设置函数

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

打印和打印机设置函数

打印函数用于在打印机上格式化输出数据。这组函数与各对象的Print()函数有所不同,程序在使用这组函数时,需要使用PrintOpen()函数打开一个打印作业,然后根据需要执行这组函数中的一个或多个函数,最后使用PrintClose()函数关闭打印作业。

打印机设置函数用于得到当前的打印机名称,设置应用程序使用的打印机,得到系统中包含的所有打印机,显示打印机设置对话框等。

1、Print()

功能:以当前字体在打开的打印作业中打印一行或多行文本。

语法:Print(printjobnumber,{tab1,}string{,tab2})

参数:printjobnumber:用PrintOpen()函数打开的打印作业号;

tab1:Integer类型,可选项,指定文本开始打印的位置,在开始打印字符串之前将打印光标移动到该位置,从打印区的左边界开始计算,以千分之一英寸为单位。如果打印光标已经位于指定位置、或打印光标已经超过了指定位置、或省略了该参数,那么,Print()函数从打印光标的当前位置开始打印string:string类型,指定要打印的字符串。如果字符串中包括回车换行字符(~r~n),那么该字符串将被分成多行输出,但是,除第一行之外,其它行忽略tab1参数指定的起始打印位置;

tab2:Integer类型,可选项,指定字符串打印结束后打印光标移动到的位置,从打印区的左边界开始计算,以千分之一英寸为单位。如果打印光标已经超过了指定位置,那么Print()函数忽略该参数,打印光标位于已打印字符串的尾部。如果省略了该参数,Print()函数把打印光标移动到下一行的起始位置;

返回值:Integer。函数执行成功时返回1,发生错误时返回-1。如果任何参数的值为NULL,Print()函数返回NULL。

用法:在打印作业中,PowerBuilder使用打印光标来跟踪打印位置。打印光标保存了即将打印区域左上角的坐标。使用Print()函数打印文本后,PowerBuilder自动更新打印光标。

PowerBuilder使用行距来决定打印出的两行文本之间的距离,行距与字符的高度成比例,缺省的行距是字符高度的1.2倍。使用PrintSetSpacing()函数可以改变行距。当Print()函数在下一行打印输出时,它把打印光标的x坐标设置为0、y坐标增加当前行距指示的数值。

由于每打印一行时Print()函数都自动调整打印光标的y坐标位置,因此,该函数会自动处理分页,因此,应用程序没有必要调用PrintPage()函数进行分页。

打印区由纸张的物理尺寸和边界空白决定,PrintSend()函数能够发送具体打印机的ESC控制序列,使用这个函数可以改变边界空白的大小。

另外,在打印开始之前,使用PrintDefineFont()和PrintSetFont()函数可以改变Print()使用的字体。

示例:This example opens a print job, prints the string Sybase Corporation in the default font, and then starts a new line:

long Job

// Define a blank page and assign the job an ID

Job = PrintOpen( )

// Print the string and then start a new line

Print(Job, "Sybase Corporation")

...

PrintClose(Job)

This example opens a print job, prints the string Sybase Corporation in the default font, tabs 5 inches from the left edge of the print area but does not start a new line:

long Job

// Define a blank page and assign the job an ID

Job = PrintOpen( )

// Print the string but do not start a new line

Print(Job, "Sybase Corporation", 5000)

...

PrintClose(Job)

The first Print statement below tabs half an inch from the left edge of the print area, prints the string Sybase Corporation, and then starts a new line. The second Print statement tabs one inch from the left edge of the print area, prints the string Directors:, and then starts a new line:

long Job

// Define a blank page and assign the job an ID

Job = PrintOpen( )

// Print the string and start a new line

Print(Job, 500, "Sybase Corporation")

// Tab 1 inch from the left edge and print

Print(Job, 1000, "Directors:")

...

PrintClose(Job)

The first Print statement below tabs half an inch from the left edge of the print area prints the string Sybase Corporation, and then tabs 6 inches from the left edge of the print area but does not start a new line. The second Print statement prints the current date and then starts a new line:

long Job

// Define a blank page and assign the job an ID

Job = PrintOpen( )

// Print string and tab 6 inches from the left edge

Print(Job, 500, "Sybase Corporation", 6000)

// Print the current date on the same line

Print(Job, String(Today()))

...

PrintClose(Job)

相关文档
最新文档