3. 在Project1中新建一个窗体Form1,窗体上添加一个Data控件Data1,一个MSFlexGrid控件MSFGrid1,7个TextBox和两个命令按钮CmdPrnt1、CmdPrnt2。设置Data控件的属性:
.. DatabaseName="Standards.mdb"
..RecordSourse="SN"
MSFGrid1属性:
.DataSource="Data1"
Text1属性:
.DataSource="Data1"
.DataField="标准号"
Text2~Text7类同。
CmdPrnt1、CmdPrnt2分别为打印单条记录和多条记录的按钮。
实例1:文字串定位折行打印在口岸联检部门中应用非常广泛。下述例子是用CmdPrnt1的Click事件代码实现了对文字串定位折行打印:
Private Sub CmdPrnt1_Click()
Dim str As String, str1 As String ,txt As String
Dim strx As Integer, stry As Integer,i As Integer
strx = 200
stry = 0
txt = Space(20) + "中国出入境检验检疫标准目录检索STEMS 2000"
Printer.FontName = "黑体"
dd = prnt11(strx, stry, 10, txt, 50)
stry = stry + rowlab * 240
Printer.Line (0, stry)-(9000, stry)
Printer.FontName = "宋体"
txt = "标准号:" + Space(2) + Trim(Text1) + Space(3) +
"发布日期:" + Trim(Text4) + Space(3) + "实施日期:"
+ Trim(Text6) + Space(3) + "修定日期:" + Trim(Text5) ’+ Chr(13)
stry = stry + 240
dd = prnt11(strx, stry, 10, txt, 70)
stry = stry + rowlab * 240
txt = "代替标准:"
dd = prnt11(strx, stry, 10, txt, 10)
dd = prnt11(strx + 1000, stry, 10, Trim(Text7), 60)
stry = stry + rowlab * 240
txt = "标准名称:"
dd = prnt11(strx, stry, 10, txt, 10)
dd = prnt11(strx + 1000, stry, 10, Trim(Text4), 38)
stry = stry + rowlab * 240
txt = "英文名称:"
dd = prnt11(strx, stry, 10, txt, 10)
dd = prnt11(strx + 1000, stry, 10, Text5, 72)
Printer.EndDoc
End Sub
注: Prnt11函数原形:prnt11(X As Integer, Y As Integer, Font As Single, Txt As String, Val As Integer),其各参数含义如下:
X、Y为待打印字符串左上角起始座标;
Font为字体大小;
Txt为待打印字符串;
Val为字符串打印折行长度。