| レポート:均等割付による印刷(テキストボックス指定) |
|
対象バージョン : 97
最終更新日 : 1998/08/25 (オリジナル作成日:1998/03/03)
概 要
レポート上に貼り付けられているテキストボックスコントロールの表示範囲に合せて均等割付による印字を行います。
解 説
引数として指定されたテキストボックスコントロールに設定されている各プロパティから値を得て、Report
オブジェクトの Print
メソッドを利用し、引数として指定されたテキストボックスコントロールの位置に均等割付印字する汎用
Sub プロシージャです。
引数に指定されたテキストボックスは、このプロシージャにより
Visible を False と設定され、実際には印刷されません。
引数に指定されたテキストボックスからフォントに関して引用するプロパティは次のとおりです。
構 文
Call KintoWariT(ControlName)
| 引 数 | 内 容 |
|---|---|
| ControlName | レポート上に貼り付けてあるテキストボックスのコントロール名を指定します。 |
Sub プロシージャ
Public Sub KintoWariT(argctl As TextBox)
Dim rpt As Report
Dim sngX As Single
Dim sngY As Single
Dim sngValueLen As Single
Dim sngLimit As Single
Dim sngChrLen As Single
Dim sngPrinted As Single
Dim intChrPos As Integer
Dim stChr As String
Dim sngGap As Single
Dim blDirection As Boolean ' True:横, False:縦
Dim txt As Control
If IsNull(argctl) Then Exit Sub
Set rpt = argctl.Parent
rpt.FontName = argctl.FontName
rpt.FontSize = argctl.FontSize
rpt.FontBold = argctl.FontBold
rpt.FontItalic = argctl.FontItalic
rpt.ForeColor = argctl.ForeColor
argctl.Visible = False
blDirection = argctl.Width > argctl.Height
sngX = argctl.Left
sngY = argctl.Top
If blDirection Then
sngLimit = argctl.Width
sngValueLen = rpt.TextWidth(argctl)
Else
sngLimit = argctl.Height
sngValueLen = rpt.TextHeight(argctl) * Len(argctl)
End If
' 印字指示幅より印刷文字列の方が長い場合、印字可能文字まで印刷
If sngValueLen > sngLimit Then
For intChrPos = 1 To Len(argctl)
stChr = Mid(argctl, intChrPos, 1)
If blDirection Then
sngChrLen = rpt.TextWidth(stChr)
Else
sngChrLen = rpt.TextHeight(stChr)
End If
If sngPrinted + sngChrLen > sngLimit Then Exit For
rpt.CurrentX = sngX
rpt.CurrentY = sngY
rpt.Print stChr;
If blDirection Then
sngX = sngX + sngChrLen
Else
sngY = sngY + sngChrLen
End If
sngPrinted = sngPrinted + sngChrLen
Next
Exit Sub
End If
' 文字間隔計算
If Len(argctl) > 1 Then
sngGap = (sngLimit - sngValueLen) / (Len(argctl) - 1)
End If
For intChrPos = 1 To Len(argctl)
stChr = Mid(argctl, intChrPos, 1)
rpt.CurrentX = sngX
rpt.CurrentY = sngY
rpt.Print stChr
If blDirection Then
sngX = sngX + rpt.TextWidth(stChr) + sngGap
Else
sngY = sngY + rpt.TextHeight(stChr) + sngGap
End If
Next
End Sub
使用例
レポートの詳細セクションの "OnFormat/フォーマット時" のイベントプロシージャで、次のように設定します。
Private Sub 詳細_Format(Cancel As Integer, FormatCount As Integer) Call KintoWariT([コントロール名]) End Sub
補 足
更新履歴