方眼紙印刷 <TOP>
納品書・請求書などの書式を設定し印刷する場合、該当サイズの方眼紙を作成し寸法(mm)を決めています。
適当な大きさのフォームにComboBox、PictureBox、TextBox、BmpButtonを貼り付けます。
コンボボックス内の目的サイズの用紙を選択すると、そのサイズに見合った大きさのフォームが表示され、プリンタアイコンをクリックすると方眼紙が印刷されます。
使用するプリンタの印字範囲を判断することができ、方眼紙上に線を引き書式を設定します。
A4用紙印刷されたGRID上で納品書の印刷書式を設定。点線1o、実線10o(図では点線2o)
例:
ZL = 170 'left
ZR = 1930 'right
ZT = 310 'top
ZB = 770 'bottom
ZC = 20 'radius
PRT1.SETDRAWWIDTH 3
PRT1.line (ZL+ZC,ZT )-(ZR-ZC,ZT
) ' ━━
PRT1.circle(ZL+ZC,ZT+ZC),ZC,,,.5,.75
'┏
PRT1.circle(ZR-ZC,ZT+ZC),ZC,,,.75,0
' ┓
PRT1.line (ZL ,ZT+ZC)-(ZL
,ZB-ZC) '┃
PRT1.circle(ZL+ZC,ZB-ZC),ZC,,,.25,.5
'┗
PRT1.line (ZL+ZC,ZB )-(ZR
,ZB) ' ━━
ZB = 850 : ZR = 1930
PRT1.line (ZR ,ZT+ZC)-(ZR
,ZB-ZC) ' ┃
PRT1.circle(ZR-ZC,ZB-ZC),ZC,,,0,.25
' ┛
ZL = 950
PRT1.line (ZL+ZC,ZB )-(ZR-ZC,ZB
) ' ━━
PRT1.circle(ZL+ZC,ZB-ZC),ZC,,,.25,.5
' ┗
ZT = 770
PRT1.line (ZL ,ZT)-(ZL,ZB-ZC)
' ┃
PRT1.SETDRAWWIDTH 0
'================================================================ '= 方眼紙印刷 '= (Gridline.bas) '================================================================ #include "Windows.bi" Var Shared Picture1 As Object Var Shared Combo1 As Object Var Shared Text1 As Object Var Shared BmpButton1 As Object Var Shared Prt As Object PrinterObject Prt Combo1.Attach GetDlgItem("Combo1") : Combo1.SetFontSize 14 Text1.Attach GetDlgItem("Text1") : Text1.SetFontSize 14 Picture1.Attach GetDlgItem("Picture1") BmpButton1.Attach GetDlgItem("BmpButton1") SetFontSize 14 Var Shared pSize(14, 4) As String Var Shared CrLf As String Var Shared PaperNum As Integer Var Shared FrmWidth As Integer Var Shared FrmHeight As Integer Var Shared DispWidth As Integer Var SHared DispHeight As Integer Var Shared Prm As PrintParam '================================================================ '= '================================================================ Declare Sub MainForm_Start edecl () Sub MainForm_Start () If PrevInstance Then A% = MessageBox(GetWindowText,"このプログラムは実行中です。", 0, 0) : End End If FrmWidth = GetClientWidth FrmHeight = GetClientHeight DispWidth = GetDeviceCaps(8) DispHeight = GetDeviceCaps(10) MoveWindow (DispWidth - FrmWidth) / 2, (DispHeight - FrmHeight - 26) / 2 ShowWindow -1 CrLf = Chr$(13, 10) BmpButton1.EnableWindow 0 '------------------------------ '各サイズ読込 '------------------------------ ' 幅 高 data "88", "1", "1285", "1820", "B6(128.5×182)縦方向" data "88", "2", "1820", "1285", "B6(182×128.5)横方向" data "13", "1", "1820", "2570", "B5(182×257)縦方向" data "13", "2", "2570", "1820", "B5(257×182)横方向" data "12", "1", "2570", "3640", "B4(257×364)縦方向" data "12", "2", "3640", "2570", "B4(364×257)横方向" data "70", "1", "1050", "1485", "A6(105×148.5)縦方向" 'ハガキ(1000×1480) data "70", "2", "1485", "1050", "A6(148.5×105)横方向" 'ハガキ(1480×1000) data "11", "1", "1485", "2100", "A5(148.5×210)縦方向" data "11", "2", "2100", "1485", "A5(210×148.5)横方向" data " 9", "1", "2100", "2970", "A4(210×297)縦方向" data " 9", "2", "2970", "2100", "A4(297×210)横方向" data " 8", "1", "2970", "4200", "A3(297×420)縦方向" data " 8", "2", "4200", "2970", "A3(420×297)横方向" For i% = 1 To 14 For j% = 0 To 4 Read pSize(i%, j%) Next Combo1.AddString pSize(i%, 4) Next End Sub '================================================================ '= 用紙描画 '================================================================ Declare Sub Draw edecl () Sub Draw SetMapMode 1 SetFontSize 7 For x% = 4 To Val(pSize(PaperNum,2)) / 5 - 5 Step 4 If x% Mod 20 = 4 Then Col% = 1 Else Col% = 14 Line(x%, 4)-(x%, Val(pSize(PaperNum, 3)) / 5 - 5),, Col% Next For y% = 4 To Val(pSize(PaperNum, 3)) / 5 - 5 Step 4 If y% Mod 20 = 4 Then Col% = 1 Else Col% = 14 Line(4, y%)-(Val(pSize(PaperNum, 2)) / 5 - 5, y%),, Col% Next End Sub '================================================================ '= 用紙選択 '================================================================ Declare Sub Combo1_Change edecl () Sub Combo1_Change() Text1.ShowWindow 0 BmpButton1.EnableWindow -1 PaperNum = Combo1.GetCursel + 1 SetWindowSize Val(pSize(PaperNum, 2)) / 5 + 25, Val(pSize(PaperNum, 3)) / 5 + 70 FrmWidth = GetClientWidth FrmHeight = GetClientHeight DispWidth = GetDeviceCaps(8) DispHeight = GetDeviceCaps(10) MoveWindow (DispWidth - FrmWidth) / 2, (DispHeight - FrmHeight - 26) / 2 Picture1.ShowWindow -1 Picture1.Cls Picture1.SetWindowSize Val(pSize(PaperNum, 2)) / 5, Val(pSize(PaperNum, 3)) / 5 Picture1.Draw End Sub '================================================================ '= 印字 '================================================================ Declare Sub BmpButton1_ON edecl() sub BmpButton1_ON() Prt.SetupPrinterMode "SetupPrinter:", Val(pSize(PaperNum, 0)), Val(pSize(PaperNum, 1)) If Prt.PrintDlg(Prm) = 0 Then Exit Sub Prt.SetMapMode 2 Prt.StartDoc "Sample" Prt.StartPage Prt.SetFontSize 7 Prt.SetFontName "MS ゴシック" For x% = 0 To Val(pSize(PaperNum,2)) Step 10 If x% Mod 100 = 0 Then If x% Mod 100 = 0 Then Prt.Symbol(x% - 25, 10), Format$(x%, "####"), 1, 1 Prt.Line(x%, 0)-(x%, Val(pSize(PaperNum, 3))),,,, Solid Else Prt.Line(x%, 0)-(x%, Val(pSize(PaperNum, 3))),,,, Dot End If Next For y% = 0 To Val(pSize(PaperNum, 3)) Step 10 If y% Mod 100 = 0 Then If y% Mod 100 = 0 Then Prt.Symbol(0, y% - 13), Format$(y%, "####"), 1, 1 Prt.Line(0, y%)-(Val(pSize(PaperNum, 2)), y%),,,, Solid Else Prt.Line(0, y%)-(Val(pSize(PaperNum, 2)), y%),,,, Dot End If Next Prt.EndPage Prt.EndDoc Prt.ClosePrinter End Sub '================================================================ '= 終了処理 '================================================================ Declare Sub MainForm_QueryClose edecl (Cancel%, ByVal Mode%) sub MainForm_QueryClose(Cancel%, ByVal Mode%) Cancel% = MessageBox(GetWindowText, "終了しますか", 1, 1 ) If Cancel% = 0 Then End End Sub '================================================================ '= '================================================================ While 1 Waitevent Wend Stop End