十一、打印和打印机设置函数

十一、打印和打印机设置函数

打印函数用于在打印机上格式化输出数据。这组函数与各对象的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)

 

In a window that displays a database error message in a MultiLineEdit mle_message, the following script for a Print button prints a title with the date and time and the message:

long li_prt

li_prt = PrintOpen("Database Error")

Print(li_prt, "Database error - "+ String(Today(), "mm/dd/yyyy") &

      + " - " + String(Now(), "HH:MM:SS"))

Print(li_prt, " ")

Print(li_prt, mle_message.text)

PrintClose(li_prt)

 

2、PrintBitmap()

功  能:在打印区域的指定位置打印位图。

语  法:PrintBitmap ( printjobnumber, bitmap, x, y, width, height )

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

bitmap:string类型,指定要打印的位图文件的文件名;

x:integer类型,指定位图起始打印位置的x坐标,以千分之一英寸为单位;

y:integer类型,指定位图起始打印位置的y坐标,以千分之一英寸为单位;

width:integer类型,指定位图的打印宽度,以千分之一英寸为单位。如果该参数的值指定为0,那么按图像的原始宽度打印;

height:integer类型,指定位图的打印高度,以千分之一英寸为单位。如果该参数的值指定为0,那么按图像的原始高度打印。

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

用  法:执行PrintBitmap()函数后,打印光标的位置不变,依然停留在执行该函数前的位置上。

示  例:These statements define a new blank page and then print the bitmap in file d:\PB\BITMAP1.BMP in its original size at location 50,100:

long Job

// Define a new blank page.

Job = PrintOpen( )

// Print the bitmap in its original size.

PrintBitmap(Job, "d:\PB\BITMAP1.BMP", 50,100, 0,0)

// Send the page to the printer and close Job.

PrintClose(Job)

 

3、PrintCancel()

功  能:取消用PrintOpen()函数启动的打印作业。

语  法:PrintCancel ( printjobnumber )

参  数:printjobnumber:要取消的打印作业的作业号。

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

用  法:PrintCancel()函数取消指定的打印作业,删除相应的打印池文件,关闭打印作业,所以,应用程序执行了PrintCancel()函数之后,不需要再执行PrintClose()函数关闭打印作业了。

示  例:In this example, a script for a Print button opens a print job and then opens a window with a cancel button. If the user clicks on the cancel button, its script sets a global variable that indicates that the user wants to cancel the job. After each printing command in the Print button's script, the code checks the global variable and cancels the job if its value is TRUE.

The definition of the global variable is:

boolean gb_printcancel

The script for the Print button is:

long job, li

gb_printcancel = FALSE

job = PrintOpen("Test Page Breaks")

IF job < 1 THEN

MessageBox("Error", "Can't open a print job.")

RETURN

END IF

Open(w_printcancel)

PrintBitmap(Job, "d:\PB\bitmap1.bmp", 5, 10, 0, 0)

IF gb_printcancel = TRUE THEN

PrintCancel(job)

RETURN

END IF

... // Additional printing commands,

... // including checking gb_printcancel

PrintClose(job)

Close(w_printcancel)

The script for the cancel button in the second window is:

gb_printcancel = TRUE

Close(w_printcancel)

 

4、PrintClose()

功  能:关闭打印作业并把打印页面发送到打印机上。

语  法:PrintClose ( printjobnumber )

参  数:printjobnumber:要关闭的打印作业的作业号。

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

用  法:应用程序使用PrintOpen()函数启动打印作业后,必须使用PrintClose()在完成打印任务后关闭打印作业,或根据需要使用PrintCancel()函数取消打印作业。

示  例:This example opens a print job, which creates a blank page, prints a bitmap on the page, then sends the current page to the printer or spooler and closes the job:

ulong Job

// Begin a new job and a new page.

Job = PrintOpen( )

// Print the bitmap in its original size.

PrintBitmap(Job, d:\PB\BITMAP1, 5,10, 0,0)

// Send the page to the printer and close Job.

PrintClose(Job)

 

5、PrintDataWindow()

功  能:打印数据窗口控件的内容,用该函数可以在一个打印作业中打印多个数据窗口控件的内容,每个都从新的一页开始打印。

语  法:PrintDataWindow ( printjobnumber, dwcontrol )

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

dwcontrol:要打印其内容的数据窗口控件名或子数据窗口控件名。

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

用  法:应用程序通过多次执行PrintDataWindow()函数可以在一个打印作业中一次打印多个数据窗口的

内容,并且每个数据窗口都从新的一页开始打印。当数据窗口的表现风格为RichTextEdit时,数据窗口中的每一行都在新的一页上开始打印。

需要注意的是,PrintDataWindow()函数在打印数据窗口时使用数据窗口本身定义的字体以及风格,使用PrintDefineFont()和PrintSetFont()函数为当前作业定义的字体不起作用。

示  例:These statements send the contents of three DataWindow controls to the current printer in a single print job:

long job

job = PrintOpen( )

// Each DataWindow starts printing on a new page.

PrintDataWindow(job, dw_EmpHeader)

PrintDataWindow(job, dw_EmpDetail)

PrintDataWindow(job, dw_EmpDptSum)

PrintClose(job)

 

6、PrintDefineFont()

功  能:定义打印作业使用的字体,对每个打印作业PowerBuilder支持八种字体。

语  法:PrintDefineFont(printjobnumber,fontnumber,facename,height,weight,fontpitch,fontfamily,

italic,underline)

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

fontnumber:指定赋给当前定义字体的编号,有效值在1到8之间 facename:string类型,指定字体名称,该字体应该是你的打印机支持的字体,比如“宋体”;

height:Integer类型,使用正值指定字体的高度,以千分之一英寸为单位;使用负值指定字体点数,比如,-18代表18点。一般来说,使用点数更精确些;

weight:指定字体的磅数,正常字体为400磅,粗体为700磅;

fontpitch:FontPitch枚举类型,指定字体标准。有效取值为:

Default!  -- 缺省值;

Fixed!    -- 固定形式;

Variable! -- 可变形式;

fontfamily:FontFamily枚举类型,指定字体系列。有效取值为:

AnyFont!、Decorative!、Modern!、Roman!、Script!、Swiss!

italic:boolean类型,指定是否使用斜体样式。有效取值为:

TRUE -- 使用斜体样式;

FALSE -- 不使用斜体样式;

缺省值为FALSE;

underline:boolean类型,指定是否加下划线。有效取值为:

TRUE  -- 加下划线;

FALSE -- 不加下划线;

缺省值为FALSE。

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

用  法:在一个打印作业中,应用程序能够最多同时定义8种字体。当应用程序需要使用更多的字体时,可以在使用了某个字体号输出内容后使用PrintDefineFont()函数将该字体号对应的字体更换为其它字体。

示  例:These statements define a new blank page, and then define print font 1 for Job as Courier 10Cpi, 18 point, normal weight, default pitch, Decorative font, with no italic or underline:

long Job

Job = PrintOpen()

PrintDefineFont(Job, 1, "Courier 10Cpi", -18, 400, Default!, Decorative!, FALSE, FALSE)

 

7、PrintLine()

功  能:在当前打印页上绘出指定厚度的一条线。

语  法:PrintLine ( printjobnumber, x1, y1, x2, y2, thickness )

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

x1:integer类型,指定直线起点的x坐标,以千分之一英寸为单位;

y1:integer类型,指定直线起点的y坐标,以千分之一英寸为单位;

x2:integer类型,指定直线终点的x坐标,以千分之一英寸为单位;

y2:integer类型,指定直线终点的y坐标,以千分之一英寸为单位;

thickness:integer类型,指定直线的厚度,以千分之一英寸为单位。

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

用  法:应用程序执行了PrintLine()函数后,该函数并不改变打印光标的位置。

示  例:These statements start a new page in a print job and then print a line starting at 0,5 and ending at 7500,5 with a thickness of 10/1000 of an inch:

long Job

Job = PrintOpen( )

... // various print commands

// Start a new page.

PrintPage(Job)

// Print a line at the top of the page

PrintLine(Job,0,5,7500,5,10)

... // Other printing

PrintClose(Job)

 

8、PrintOpen()

功  能:启动打印作业并返回作业号。

语  法:PrintOpen ( { jobname } )

参  数:jobname:string类型,可选项,指定要打开打印作业的名称,该名称将显示在打印管理器窗口中。

返回值:Long。函数执行成功时返回打印作业号,发生错误时返回-1。如果任何参数的值为NULL,

PrintOpen()函数返回NULL。

用  法:应用程序执行PrintOpen()函数后,启动新的打印作业并走纸到下一页,同时将打印机缺省字体设置为该打印作业的字体。打印光标的位置位于打印区的左上角。其它同组的打印函数使用PrintOpen()函数返回的作业号来标识作业。

需要注意的是,使用PrintOpen()函数打开打印作业、使用同组的其它函数完成打印任务后,必须使用PrintClose()关闭打印作业,或根据需要使用PrintCancel()函数取消打印作业。

示  例:This example opens a job but does not give it a name:

ulong li_job

li_job = PrintOpen()

 

This example opens a job and gives it a name:

ulong li_job

li_job = PrintOpen("Phone List")

 

9、PrintOval()

功  能:在指定位置以指定线宽绘制椭圆或圆。

语  法:PrintOval ( printjobnumber, x, y, width, height, thickness )

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

x:integer类型,指定椭圆或圆外形框左上角的x坐标,以千分之一英寸为单位;

y:integer类型,指定椭圆或圆外形框左上角的y坐标,以千分之一英寸为单位;

width:integer类型,指定椭圆或圆外形框的宽度,以千分之一英寸为单位;

height:integer类型,指定椭圆或圆外形框的高度,以千分之一英寸为单位;

thickness:integer类型,指定椭圆或圆外边线的厚度,以千分之一英寸为单位。

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

用  法:应用程序执行了PrintOval()函数后,该函数并不改变打印光标的位置。PrintOval()函数绘出的椭圆或圆是实心的,也就是说,执行该函数后,椭圆或圆下面的文字或图像将完全被覆盖。如果想在椭圆或圆中输出文字或图形,那么应用程序应该首先绘制椭圆或圆,然后使用其它函数在椭圆或圆中输出文字或图形。

示  例:This example starts a print job with a new blank page, and then prints an oval that fits in a 1-inch square. The upper-left corner of the oval's bounding box is four inches from the top and three inches from the left edge of the print area. Because its height and width are equal, the oval is actually a circle:

long Job

// Define a new blank page.

Job = PrintOpen()

// Print an oval.

PrintOval(Job, 4000, 3000, 1000, 1000, 10)

... // Other printing

PrintClose(Job)

 

10、PrintPage()

功  能:将当前页发送给打印机或打印池并在当前打印作业中启动一个新的打印页。

语  法:PrintPage ( printjobnumber )

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

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

示  例:This example opens a print job with a new blank page, prints a bitmap on the page, and then sends the page to the printer and sets up a new blank page. Finally, the last Print statement prints the company name on the new page:

long Job

// Open a job with new blank page.

Job = PrintOpen()

// Print a bitmap on the page.

PrintBitmap(Job, "d:\PB\BITMAP1.BMP", 100,250, 0,0)

// Begin a new page.

PrintPage(Job)

// Print the company name on the new page.

Print(Job, "Sybase Corporation")

 

11、PrintRect()

功  能:在指定位置以指定线宽打印矩形。

语  法:PrintRect ( printjobnumber, x, y, width, height, thickness )

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

x:integer类型,指定矩形左上角的x坐标,以千分之一英寸为单位;

y:integer类型,指定矩形左上角的y坐标,以千分之一英寸为单位;

width:integer类型,指定矩形的宽度,以千分之一英寸为单位;

height:integer类型,指定矩形的高度,以千分之一英寸为单位;

thickness:integer类型,指定矩形边线的厚度,以千分之一英寸为单位。

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

用  法:应用程序执行了PrintRect()函数后,该函数并不改变打印光标的位置。PrintRect()函数绘出实心的矩形,也就是说,执行该函数后,矩形下面的文字或图像将完全被覆盖。如果想在矩形中输出文字或图形,那么应用程序应该首先绘制矩形,然后使用其它函数在矩形中输出文字或图形。

示  例:These statements open a print job with a new page and draw a 1-inch square with a line thickness of 1/8 of an inch. The square's upper left corner is four inches from the left and three inches from the top of the print area:

long Job

// Define a new blank page.

Job = PrintOpen()

// Print the rectangle on the page.

PrintRect(Job, 4000,3000, 1000,1000, 125)

... // Other printing

PrintClose(Job)

 

12、PrintRoundRect()

功  能:在指定位置以指定线宽打印圆角矩形。

语  法:PrintRoundRect(printjobnumber,x,y,width,height,xradius,yradius,thickness)

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

x:integer类型,指定圆角矩形左上角的x坐标,以千分之一英寸为单位;

y:integer类型,指定圆角矩形左上角的y坐标,以千分之一英寸为单位;

width:integer类型,指定圆角矩形的宽度,以千分之一英寸为单位;

height:integer类型,指定圆角矩形的高度,以千分之一英寸为单位;

xradius:integer类型,指定圆角矩形圆角部分的x半径,以千分之一英寸为单位;

yradius:integer类型,指定圆角矩形圆角部分的y半径,以千分之一英寸为单位;

thickness:integer类型,指定圆角矩形边线的厚度,以千分之一英寸为单位。

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

用  法:应用程序执行了PrintRoundRect()函数后,该函数并不改变打印光标的位置。PrintRoundRect()函数绘出实心的圆角矩形,也就是说,执行该函数后,圆角矩形下面的文字或图像将完全被覆盖。如果想在圆角矩形中输出文字或图形,那么应用程序应该首先绘制圆角矩形,然后使用其它函数在圆角矩形中输出文字或图形。

示  例:This example starts a new print job, which begins a new page, and prints a rectangle with rounded corners as a page border. Then it closes the print job, which sends the page to the printer. The rectangle is 6 1/4 inches wide by 9 inches high and its upper corner is one inch from the top and one inch from the left edge of the print area. The border has a line thickness of 1/8 of an inch and the corner radius is 300:

long Job

// Define a new blank page.

Job = PrintOpen()

// Print a RoundRectangle on the page.

PrintRoundRect(Job, 1000,1000, 6250,9000,300,300, 125)

// Send the page to the printer.

PrintClose(Job)

13、PrintScreen()

功  能:在打印作业中打印屏幕图像。

语  法:PrintScreen ( printjobnumber, x, y {, width, height } )

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

x:integer类型,指定要打印屏幕图像左上角在打印页上的x坐标,以千分之一英寸为单位;

y:integer类型,指定要打印屏幕图像左上角在打印页上的y坐标,以千分之一英寸为单位;

width:integer类型,可选项,指定屏幕图像的打印宽度,以千分之一英寸为单位。如果省略了该参数,那么PowerBuilder按屏幕的原始宽度打印屏幕图像。如果指定了该参数,必须同时指定height参数;

height:integer类型,可选项,指定屏幕图像的打印高度,以千分之一英寸为单位。如果省略了该参数,那么PowerBuilder按屏幕的原始高度打印屏幕图像。

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

示  例:This statement prints the current screen image in its original size at location 500, 1000:

long Job

Job = PrintOpen()

PrintScreen(Job, 500,1000)

PrintClose(Job)

 

14、PrintSend()

功  能:直接向打印机发送任意字符串,通常用于发送打印机的控制代码。

语  法:PrintSend ( printjobnumber, string {, zerochar } )

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

string:string类型,指定发送到打印机的字符串。在该字符串中,使用非打印字符的ASCII码值表示非打印字符;

zerochar:integer类型,可选项,指定在string参数中用于表示数值0的ASCII码值。有效取值在1到255之间。

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

用  法:应用程序使用PrintSend()函数可以直接向打印机发送控制序列(换码序列),比如,设置打印文字的浓淡、打印页的四周空白等。不同类型的打印机使用不同的控制序列,你需要翻一翻你的打印机手册。

由于PowerBuilder使用数值0(即ASCII码为0的字符)结束每个字符串,因此,如果打印控制序列中包含了数值0,应用程序需要使用其它字符在参数string中替代数值0,并用zerochar参数指明这个替代字符。一般来说,应该选择一个打印机控制序列中不使用的字符作为0值字符的替代字符。

通常情况下,按下述次序组织打印作业:

  1. 使用PrintOpen()函数打开打印作业;
  2. 使用PrintSend()函数设置打印机特性,比如打印方向、四周空白等;
  3. 使用PrintDefineFont()和PrintSetFont()函数设置该打印作业使用的字体;
  4. 使用该组的其它函数打印输出文字或图形5. 执行PrintClose()函数关闭打印作业。
  •   例:This example opens a print job and sends an escape sequence to a printer in IBM Proprinter mode to change the margins. There is no need to designate a character to represent zero:

long Job

// Open a print job.

Job = PrintOpen()

/* Send the escape sequence.

1B is the escape character in hexadecimal.

X indicates that you are changing the margins.

030 sets the left margin to 30 character spaces.

040 sets the right margin to 40 character spaces.

*/

PrintSend(Job," ~ h1BX ~ 030 ~ 040")

... // Print text or DataWindow

// Send the job to the printer or spooler.

PrintClose(Job)

       

This example opens a print job and sends an escape sequence to a printer in IBM Proprinter mode to change the margins. The decimal ASCII code 255 represents zero:

long Job

// Open a print job.

Job = PrintOpen()

/* Send the escape sequence.

1B is the escape character, in hexadecimal.

X indicates that you are changing the margins.

255 sets the left margin to 0.

040 sets the right margin to 40 character spaces.

*/

PrintSend(Job, "~h1BX~255~040", 255)

PrintDataWindow(Job, dw_1)

// Send the job to the printer or spooler.

PrintClose(Job)

 

15、PrintSetFont()

功  能:设置当前打印作业使用的字体。

语  法:PrintSetFont ( printjobnumber, fontnumber )

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

fontnumber:指定该打印作业使用字体的字体编号,该编号与PrintDefineFont()函数中定义的编号应该对应,字体编号的有效取值在1到8之间,0表示使用打印机的缺省字体。

返回值:Integer。函数执行成功时返回当前字体的高度,发生错误时返回-1。如果任何参数的值为NULL,PrintSetFont()函数返回NULL。

示  例:This example starts a new print job and specifies that font number 2 is Courier, 18 point, bold, default pitch, in modern font, with no italic or underline. The PrintSetFont statement sets the current font to font 2. Then the Print statement prints the company name:

long Job

// Start a new print job and a new page.

Job = PrintOpen()

// Define the font for Job.

PrintDefineFont(Job, 2, "Courier 10Cps" , 250, 700, Default!, Modern!, FALSE, FALSE)

// Set the font for Job.

PrintSetFont(Job, 2)

// Print the company name in the specified font.

Print(Job,"Sybase Corporation")

 

16、PrintSetSpacing()

功  能:设置行间距因子,打印函数将使用该因子来决定行间距。

语  法:PrintSetSpacing ( printjobnumber, spacingfactor )

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

spacingfactor:指定行间距因子,用字符高度的倍数表示,缺省值为1.2。

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

用  法:在PowerBuilder应用程序中,行间距与字符的高度成正比,缺省值为字符高度的1.2倍。当Print组函数生成新行时,系统自动把打印光标的x坐标位置设置为0,y坐标位置在原有基础上增加当前行距值。使用PrintSetSpacing()函数可以改变当前打印作业的行距。

示  例:These statements start a new print job and set the vertical spacing factor to 1.5 (one and a half spacing):

long Job

// Define a new blank page.

Job = PrintOpen()

// Set the spacing factor.

PrintSetSpacing(Job, 1.5)

 

17、PrintSetup()

功  能:打开打印机设置对话框。

语  法:PrintSetup ( )

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

用  法:当系统中安装了多种打印机时,在Windows中PrintSetup()函数选择计算机的对话框,单击“Setup”按钮设置打印机各种特性。如果系统中只有一个打印机,则直接打开该打印机的打印设置对话框。需要注意的是,在Windows95和Windows NT 3.51以后的版本中,使用PrintSetup()函数设置的打印机设置只对当前应用起作用,并不影响其它应用的打印机设置。对Windows 3.1来说,使用PrintSetup()函数设置的打印机设置影响系统中的所有应用。

示  例:These statements call the Printer Setup dialog box for the current system printer and then start a new print job:

long Job

// Call the printer setup program.

PrintSetup()

// Start a job and a new page.

Job = PrintOpen()

 

18、PrintText()

功  能:在指定位置打印一行文本。

语  法:PrintText ( printjobnumber, string, x, y {, fontnumber } )

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

string:string类型,指定要打印的文本;

x:integer类型,指定文本开始打印位置的x坐标,以千分之一英寸为单位;

y:integer类型,指定文本开始打印位置的y坐标,以千分之一英寸为单位;

fontnumber:可选参数,指定打印文本使用的字体号,该编号由PrintDefineFont()函数确定。省略该参数时,以打印作业的当前字体打印文本。

返回值:Integer。函数执行成功时返回文本打印后打印光标的x位置,即参数x的值加上打印文本的宽度。发生错误时返回-1。如果任何参数的值为NULL,PrintText()函数返回NULL。

示  例:These statements start a new print job and then print PowerBuilder in the current font 3.7 inches from the left edge at the top of the page (location 3700,10):

long Job

// Define a new blank page.

Job = PrintOpen()

// Print the text.

PrintText(Job,"PowerBuilder", 3700, 10)

... // Other printing

PrintClose(Job)

       

The following statements define a new blank page and then print Confidential in bold (as defined for font number 3), centered at the top of the page:

long Job

// Start a new job and a new page.

Job = PrintOpen()

// Define the font.

PrintDefineFont(Job, 3,"Courier 10Cps", 250,700,Default!, AnyFont!, FALSE, FALSE)

// Print the text.

PrintText(Job, "Confidential", 3700, 10, 3)

... // Other printing

PrintClose(Job)

       

This example prints four lines of text in the middle of the page. The coordinates for PrintText establish a new vertical position for the print cursor, which the subsequent Print functions use and increment. The first Print function uses the x coordinate returned by PrintText to continue the first line. The rest of the Print functions print additional lines of text, after tabbing to the x coordinate used initially by PrintText. In this example, each Print function increments the y coordinate so that the following Print function starts a new line:

long Job

// Start a new job and a new page.

Job = PrintOpen()

// Print the text.

x =  PrintText(Job,"The material ", 2000, 4000)

Print(Job, x, " in this report")

Print(Job, 2000, "is confidential and should not")

Print(Job, 2000, "be disclosed to anyone who")

Print(Job, 2000, "is not at this meeting.")

... // Other printing

PrintClose(Job)

 

19、PrintWidth()

功  能:确定一个字符串在指定打印作业中按当前字体所占的宽度,以千分之一英寸为单位。

语  法:PrintWidth ( printjobnumber, string )

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

string:string类型,指定要决定其打印宽度的字符串。

返回值:Integer。函数执行成功时返回按当前字体计算的字符串打印宽度,以千分之一英寸为单位,发生错误时返回-1。如果任何参数的值为NULL,PrintWidth()函数返回NULL。

示  例:These statements define a new blank page and then set W to the length of the string PowerBuilder in the current font and then use the length to position the next text line:

long Job

int W

// Start a new print job.

Job = PrintOpen()

// Determine the width of the text.

W = PrintWidth(Job,"PowerBuilder")

// Use the width to get the next print position.

Print(Job, W - 500, "Features List")

 

20、PrintX()

功  能:返回打印光标的x坐标位置。

语  法:PrintX ( printjobnumber )

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

返回值:Integer。函数执行成功时返回打印光标的x坐标位置,以千分之一英寸为单位,发生错误时返回-1。如果任何参数的值为NULL,PrintX()函数返回NULL。

示  例:These statements set LocX to the x coordinate of the cursor and print End of Report an inch beyond that location:

integer LocX

long Job

Job = PrintOpen()

... //Print statements

LocX = PrintX(Job)

Print(LocX+1000, "End of Report")

 

21、PrintY()

功  能:返回打印光标的y坐标位置。

语  法:PrintY ( printjobnumber )

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

返回值:Integer。函数执行成功时返回打印光标的y坐标位置,以千分之一英寸为单位,发生错误时返回-1。如果任何参数的值为NULL,PrintY()函数返回NULL。

示  例:These statements print a bitmap one inch below the location of the print cursor:

integer LocX, LocY

long Job

Job = PrintOpen()

... //Print statements

LocX = PrintX(Job)

LocY = PrintY(Job) + 1000

PrintBitmap(Job, "CORP.BMP", LocX, LocY, 1000,1000)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值