tagCANDY CGI VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
[ツリー表示へ]  [ワード検索]  [Home]

タイトル Re^3: 印刷で用紙の横向きと縦向きをきりかえる
投稿日: 2008/03/06(Thu) 14:03
投稿者ひでと
追伸します。いただいたコードを元に下記の用に変更して実験したところ
思うような処理となりました。ありがとうございました。

Public Class Form1
    Dim Page As Integer
    Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Ret As DialogResult
        PrintPreviewDialog1.Document = Me.PrintDocument1
        Ret = PrintPreviewDialog1.ShowDialog()
    End Sub
    Private Sub PageSetting1(ByVal sender As Object, ByRef e As Printing.QueryPageSettingsEventArgs)
        'Dim sender As New System.Drawing.Printing.PrintDocument
        '通常使うプリンターのPageSettingsを取得
        Dim dftPSettings As New System.Drawing.Printing.PageSettings
        'dftPSettings = sender.PrinterSettings.DefaultPageSettings
        dftPSettings.Landscape = False
        With e.PageSettings
            .Landscape = False
            .Margins.Left = 20 * 39.37 / 10 - dftPSettings.HardMarginX
            .Margins.Right = 10 * 39.37 / 10 - dftPSettings.HardMarginX
            .Margins.Top = 10 * 39.37 / 10 - dftPSettings.HardMarginY
            .Margins.Bottom = 10 * 39.37 / 10 - dftPSettings.HardMarginY
        End With
    End Sub
    Private Sub PageSetting2(ByVal sender As Object, ByRef e As Printing.QueryPageSettingsEventArgs)
        'Dim sender As New System.Drawing.Printing.PrintDocument
        '通常使うプリンターのPageSettingsを取得
        Dim dftPSettings As New System.Drawing.Printing.PageSettings
        'dftPSettings = sender.PrinterSettings.DefaultPageSettings
        dftPSettings.Landscape = True
        With e.PageSettings
            .Landscape = True
            .Margins.Left = 10 * 39.37 / 10 - dftPSettings.HardMarginX
            .Margins.Right = 10 * 39.37 / 10 - dftPSettings.HardMarginX
            .Margins.Top = 20 * 39.37 / 10 - dftPSettings.HardMarginY
            .Margins.Bottom = 10 * 39.37 / 10 - dftPSettings.HardMarginY
        End With
    End Sub
    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim nFont As Font
        nFont = New Font("MS 明朝", 10)
        If Page = 0 Then
            e.Graphics.DrawString("ページ1", nFont, Brushes.Black, _
                e.PageSettings.Margins.Left + 10, e.PageSettings.Margins.Top + 10)
            e.HasMorePages = True
            Page = 1
        Else
            e.Graphics.DrawString("ページ2", nFont, Brushes.Black, _
               e.PageSettings.Margins.Left + 10, e.PageSettings.Margins.Top + 10)
            e.HasMorePages = False
            Page = 0
        End If
    End Sub

    Sub PrintDocument1_QueryPageSettings(ByVal sender As Object, ByVal e As Printing.QueryPageSettingsEventArgs) Handles PrintDocument1.QueryPageSettings
        With e.PageSettings
            '.PaperSize = New Printing.PaperSize("A4", 1169, 827)
            If Page = 0 Then
                PageSetting1(sender, e)
            Else
                .Landscape = True
            End If
        End With
    End Sub
End Class

- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。