IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Windows Forms Discussion :

imprimer un formulaire sur vb


Sujet :

Windows Forms

  1. #1
    Candidat au Club
    Inscrit en
    Janvier 2010
    Messages
    3
    Détails du profil
    Informations forums :
    Inscription : Janvier 2010
    Messages : 3
    Points : 4
    Points
    4
    Par défaut imprimer un formulaire sur vb
    Salut tout le monde
    Je cherche comment faire pour imprimer un formulaire pour compléter mon projet. J'ai pas trouvé de solution.
    Pourriez vous me mettre sur la piste de facon a ce que je puisse réaliser cela?
    Un petit exemple serait aussi le bienvenu.
    Merci d'avance.

  2. #2
    Membre régulier
    Inscrit en
    Juin 2006
    Messages
    84
    Détails du profil
    Informations forums :
    Inscription : Juin 2006
    Messages : 84
    Points : 70
    Points
    70
    Par défaut
    Bonjour à tous regarde ce bout de code
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    Public Class Form1
        Inherits System.Windows.Forms.Form
        Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
        Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
     
        Public Const SWP_HIDEWINDOW As Integer = &H80
        Public Const SWP_SHOWWINDOW As Integer = &H40
     
     
     
        Dim TaskBarHwnd As Integer
     
    #Region " Code généré par le Concepteur Windows Form "
     
        Public Sub New()
            MyBase.New()
     
            'Cet appel est requis par le Concepteur Windows Form.
            InitializeComponent()
            Application.EnableVisualStyles()
            'Ajoutez une initialisation quelconque après l'appel InitializeComponent()
     
        End Sub
     
        'La méthode substituée Dispose du formulaire pour nettoyer la liste des composants.
        Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
            If disposing Then
                If Not (components Is Nothing) Then
                    components.Dispose()
                End If
            End If
            MyBase.Dispose(disposing)
        End Sub
     
        'Requis par le Concepteur Windows Form
        Private components As System.ComponentModel.IContainer
     
        'REMARQUE*: la procédure suivante est requise par le Concepteur Windows Form
        'Elle peut être modifiée en utilisant le Concepteur Windows Form.  
        'Ne la modifiez pas en utilisant l'éditeur de code.
        Friend WithEvents Button1 As System.Windows.Forms.Button
        Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
        Friend WithEvents ComboBox1 As System.Windows.Forms.ComboBox
        Friend WithEvents PictureBox1 As System.Windows.Forms.PictureBox
        Friend WithEvents Label1 As System.Windows.Forms.Label
        Friend WithEvents RadioButton1 As System.Windows.Forms.RadioButton
        Friend WithEvents Button2 As System.Windows.Forms.Button
        Friend WithEvents ListBox1 As System.Windows.Forms.ListBox
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
            Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
            Me.Button1 = New System.Windows.Forms.Button
            Me.TextBox1 = New System.Windows.Forms.TextBox
            Me.ComboBox1 = New System.Windows.Forms.ComboBox
            Me.PictureBox1 = New System.Windows.Forms.PictureBox
            Me.Label1 = New System.Windows.Forms.Label
            Me.RadioButton1 = New System.Windows.Forms.RadioButton
            Me.Button2 = New System.Windows.Forms.Button
            Me.ListBox1 = New System.Windows.Forms.ListBox
            Me.SuspendLayout()
            '
            'Button1
            '
            Me.Button1.Image = CType(resources.GetObject("Button1.Image"), System.Drawing.Image)
            Me.Button1.ImageAlign = System.Drawing.ContentAlignment.TopRight
            Me.Button1.Location = New System.Drawing.Point(238, 220)
            Me.Button1.Name = "Button1"
            Me.Button1.Size = New System.Drawing.Size(90, 28)
            Me.Button1.TabIndex = 0
            Me.Button1.Text = "Button1"
            Me.Button1.TextAlign = System.Drawing.ContentAlignment.TopLeft
            '
            'TextBox1
            '
            Me.TextBox1.ForeColor = System.Drawing.Color.Black
            Me.TextBox1.Location = New System.Drawing.Point(238, 36)
            Me.TextBox1.Name = "TextBox1"
            Me.TextBox1.Size = New System.Drawing.Size(188, 22)
            Me.TextBox1.TabIndex = 1
            Me.TextBox1.Text = "TextBox1"
            '
            'ComboBox1
            '
            Me.ComboBox1.Location = New System.Drawing.Point(84, 70)
            Me.ComboBox1.Name = "ComboBox1"
            Me.ComboBox1.Size = New System.Drawing.Size(214, 24)
            Me.ComboBox1.TabIndex = 2
            Me.ComboBox1.Text = "ComboBox1"
            '
            'PictureBox1
            '
            Me.PictureBox1.Image = CType(resources.GetObject("PictureBox1.Image"), System.Drawing.Image)
            Me.PictureBox1.Location = New System.Drawing.Point(8, 168)
            Me.PictureBox1.Name = "PictureBox1"
            Me.PictureBox1.Size = New System.Drawing.Size(130, 90)
            Me.PictureBox1.TabIndex = 3
            Me.PictureBox1.TabStop = False
            '
            'Label1
            '
            Me.Label1.Location = New System.Drawing.Point(74, 38)
            Me.Label1.Name = "Label1"
            Me.Label1.Size = New System.Drawing.Size(158, 22)
            Me.Label1.TabIndex = 4
            Me.Label1.Text = "Label1"
            '
            'RadioButton1
            '
            Me.RadioButton1.Location = New System.Drawing.Point(350, 130)
            Me.RadioButton1.Name = "RadioButton1"
            Me.RadioButton1.Size = New System.Drawing.Size(82, 26)
            Me.RadioButton1.TabIndex = 5
            Me.RadioButton1.Text = "RadioButton1"
            '
            'Button2
            '
            Me.Button2.Location = New System.Drawing.Point(358, 218)
            Me.Button2.Name = "Button2"
            Me.Button2.Size = New System.Drawing.Size(86, 34)
            Me.Button2.TabIndex = 6
            Me.Button2.Text = "Hide"
            '
            'ListBox1
            '
            Me.ListBox1.ItemHeight = 16
            Me.ListBox1.Items.AddRange(New Object() {"Salut", "Demain", "Soit"})
            Me.ListBox1.Location = New System.Drawing.Point(76, 112)
            Me.ListBox1.Name = "ListBox1"
            Me.ListBox1.Size = New System.Drawing.Size(234, 52)
            Me.ListBox1.TabIndex = 7
            '
            'Form1
            '
            Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
            Me.ClientSize = New System.Drawing.Size(468, 260)
            Me.Controls.Add(Me.ListBox1)
            Me.Controls.Add(Me.Button2)
            Me.Controls.Add(Me.RadioButton1)
            Me.Controls.Add(Me.Label1)
            Me.Controls.Add(Me.PictureBox1)
            Me.Controls.Add(Me.ComboBox1)
            Me.Controls.Add(Me.TextBox1)
            Me.Controls.Add(Me.Button1)
            Me.Name = "Form1"
            Me.Text = "Form1"
            Me.ResumeLayout(False)
     
        End Sub
     
    #End Region
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ' si boite autour des controles textbox, combobox True sinon false
            ' param la Form, Cadre Oui ou non, Boutton Oui ou Non)
            Dim fp As New PrintForm.FormPrinting(Me, True, False)
            fp.Print()
        End Sub
     
        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
     
            TaskBarHwnd = FindWindow("Shell_traywnd", "")
     
            If Button2.Text = "Hide" Then
                SetWindowPos(TaskBarHwnd, 0&, 0&, 0&, 0&, 0&, SWP_HIDEWINDOW)
     
                Button2.Text = "Show"
                Me.Refresh()
            Else
                SetWindowPos(TaskBarHwnd, 0&, 0&, 0&, 0&, 0&, SWP_SHOWWINDOW)
     
                Button2.Text = "Hide"
            End If
     
        End Sub
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
        End Sub
    End Class
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    Option Strict Off
    Imports System.drawing
    Imports System.drawing.Printing
    Imports System.Windows.Forms
     
     
    Public Class FormPrinting
     
        Public TextBoxBoxed As Boolean = False ' boîte autour des textbox
        Public TabControlBoxed As Boolean = True ' Boite autour des tabcontrols
        Public LabelInBold As Boolean = True ' Print all labels in bold
        Public Orientation As OrientationENum = OrientationENum.Automatic ' choix de l'orientation (Automatic, Protrait or Landscape)
        Public PrintPreview As Boolean = True ' enabled Print preview instead of direct printing
     
        Public Enum OrientationENum
            Automatic = 1
            Portrait = 2
            Lanscape = 3
        End Enum
     
     
        Private _printFont As Font
        Private _Pen As New Pen(Color.Black)
        Private _Pen1 As New Pen(Color.Blue, 2)
        Private _Brush As Brush
        Private _f As System.Windows.forms.Form
        Private _TextBoxLikeControl As New ArrayList
        Private _yForm As Single
        Private _xform As Single
        Private tbBoxed As Boolean
        Private _bBouton As Boolean
     
        Public Sub New(ByVal f As System.Windows.forms.Form, ByVal tbBoxed As Boolean, ByVal bBouton As Boolean)
            _f = f
            AddTextBoxLikeControl("ComboBox")
            AddTextBoxLikeControl("DateTimePicker")
            AddTextBoxLikeControl("DateTimeSlicker")
            tbBoxed = tbBoxed
            TextBoxBoxed = tbBoxed
            _bBouton = bBouton
        End Sub
     
        Public Sub AddTextBoxLikeControl(ByVal stringType As String)
            _TextBoxLikeControl.Add(stringType)
        End Sub
     
        Public Sub Print()
            Try
                Dim pd As New PrintDocument
                pd.DocumentName = _f.Text
                ' Calculate la position de la form pour impression
                Select Case Orientation
                    Case OrientationENum.Automatic
                        If _f.Size.Width > (pd.DefaultPageSettings.Bounds.Width - pd.DefaultPageSettings.Margins.Right - pd.DefaultPageSettings.Margins.Left) Then
                            pd.DefaultPageSettings.Landscape() = True
                        End If
                    Case OrientationENum.Lanscape
                        pd.DefaultPageSettings.Landscape() = True
                    Case OrientationENum.Portrait
                        pd.DefaultPageSettings.Landscape() = False
                End Select
                _yForm = pd.DefaultPageSettings.Margins.Top
                _xform = CInt((pd.DefaultPageSettings.Bounds.Width - _f.Size.Width) / 2)
                AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage
                If PrintPreview Then
                    Dim pp As New PrintPreviewDialog
                    pp.Document = pd
                    pp.WindowState = FormWindowState.Maximized
                    pp.ShowDialog()
                Else
                    pd.Print()
                End If
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End Sub
     
        Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
            _printFont = New Font(_f.Font.Name, CSng(_f.Font.Size * 1.2), FontStyle.Bold)
            ev.Graphics.DrawString(_f.Text, _printFont, Brushes.Black, _xform, _yForm)
            _yForm += _printFont.GetHeight(ev.Graphics)
            _Pen = New Pen(Color.Black, 2)
            _yForm += 1
            Dim points As PointF() = {New PointF(_xform, _yForm), New PointF(_xform + _f.Size.Width, _yForm)}
            Dim rect As New Rectangle(_xform, _yForm, _f.Size.Width, _f.Size.Height)
            'ev.Graphics.DrawLines(_Pen, points)
            ev.Graphics.FillRectangle(Brushes.WhiteSmoke, rect)
            ev.Graphics.DrawRectangle(_Pen1, rect)
     
            _yForm += _Pen.Width + 1
     
            ' Print chaque controle de la form
            PrintControls(_f, ev, _xform, _yForm)
        End Sub
     
        Public Sub PrintControl(ByVal c As System.Windows.forms.Control, ByVal ev As PrintPageEventArgs, ByVal x As Single, ByVal y As Single)
            If c.Visible = True Then
                PrintOneControl(c, ev, x, y) ' Myself
                PrintControls(c, ev, x, y) 'Contained controls
            End If
        End Sub
     
        Public Sub PrintControls(ByVal c As System.Windows.forms.Control, ByVal ev As PrintPageEventArgs, ByVal x As Single, ByVal y As Single)
            For Each cIn As Control In c.Controls
                PrintControl(cIn, ev, x + cIn.Location.X, y + cIn.Location.Y)
            Next
        End Sub
     
        Public Sub PrintOneControl(ByVal c As System.Windows.forms.Control, ByVal ev As PrintPageEventArgs, ByVal x As Single, ByVal y As Single)
            ' Silver color est disable
            If c.Enabled Then
                _Pen = New Pen(Color.Black)
                _Brush = Brushes.Black
            Else
                _Pen = New Pen(Color.Silver)
                _Brush = Brushes.Silver
            End If
     
            Dim s As String = c.GetType.ToString
            Dim founded As Boolean = False
     
            ' check si c'est un text box
            If s.IndexOf("TextBox") >= 0 Then
                Try
                    Dim tb As TextBox = c
                    founded = True
                    PrintText(c, ev, x, y, TextBoxBoxed, tb.Font.Bold, Not tb.Multiline And TextBoxBoxed, tb.TextAlign)
                Catch ex As Exception
                    ' N'est pas un TextBox
                End Try
            End If
            If s.IndexOf("Button") >= 0 And _bBouton Then
                Dim talign As Integer
                Try
                    Dim tb As Button = c
                    founded = True
                    If tb.TextAlign = ContentAlignment.TopLeft Then
                        talign = 255
                    Else
                        talign = tb.TextAlign
                    End If
                    PrintText(c, ev, x, y, TextBoxBoxed, tb.Font.Bold, False, talign)
                    PrintCadre(c, ev, x, y, c.Width, c.Height)
                Catch ex As Exception
                    ' N'est pas un TextBox
                End Try
            End If
            If s.IndexOf("ListBox") >= 0 Then
     
                Try
                    Dim i As Integer
                    Dim tb As ListBox = c
                    Dim stringSize As New SizeF
     
                    founded = True
                    For i = 0 To tb.Items.Count
                        Dim sligne As String
                        stringSize = ev.Graphics.MeasureString(sligne, tb.font)
                        sligne = tb.Items.item(i)
                        y = y + stringSize.Height
                        PrintList(sligne, c, ev, x, y, tb.Font.Bold)
     
                    Next
                Catch ex As Exception
                    ' N'est pas un TextBox
                End Try
     
            End If
            ' check si ce n'est pas un textbox
            If Not founded Then
                For Each sType As String In _TextBoxLikeControl
                    If s.IndexOf(sType) >= 0 Then
     
                        PrintText(c, ev, x, y, TextBoxBoxed, False, TextBoxBoxed, HorizontalAlignment.Left)
                        founded = True
                        Exit For
                    End If
                Next
            End If
     
            'Procede pour les autres contrôles
            If Not founded Then
                Select Case c.GetType.ToString
     
                    Case "System.Windows.Forms.Label"
                        Dim ha As HorizontalAlignment
                        Dim ss As String = c.Text
                        Dim ha2 As ContentAlignment = CType(c, Label).TextAlign
                        Select Case CType(c, Label).TextAlign
     
                            Case ContentAlignment.BottomLeft
                                ha = HorizontalAlignment.Left
                            Case ContentAlignment.TopLeft
                                ha = HorizontalAlignment.Left
                            Case ContentAlignment.MiddleLeft
                                ha = HorizontalAlignment.Left
     
                            Case ContentAlignment.BottomCenter
                                ha = HorizontalAlignment.Center
                            Case ContentAlignment.TopCenter
                                ha = HorizontalAlignment.Center
                            Case ContentAlignment.MiddleCenter
                                ha = HorizontalAlignment.Center
     
                            Case ContentAlignment.BottomRight
                                ha = HorizontalAlignment.Right
                            Case ContentAlignment.TopRight
                                ha = HorizontalAlignment.Right
                            Case ContentAlignment.MiddleRight
                                ha = HorizontalAlignment.Right
                        End Select
                        PrintText(c, ev, x, y, False, LabelInBold, False, ha)
     
                    Case "System.Windows.Forms.CheckBox"
                        _printFont = New Font(c.Font.Name, c.Font.Size)
                        Dim w As Single = _printFont.GetHeight(ev.Graphics)
                        ev.Graphics.DrawRectangle(_Pen, x, y, w, w)
                        If CType(c, CheckBox).Checked Then
                            Dim d As Single = 3
                            Dim points1 As PointF() = {New PointF(x + d, y + d), New PointF(x + w - d, y + w - d)}
                            ev.Graphics.DrawLines(_Pen, points1)
                            Dim points2 As PointF() = {New PointF(x + w - d, y + d), New PointF(x + d, y + w - d)}
                            ev.Graphics.DrawLines(_Pen, points2)
                        End If
                        PrintText(c, ev, x + CInt((w * 1.4)), y - 2, False, False, False, HorizontalAlignment.Left)
                    Case "System.Windows.Forms.RadioButton"
     
                        _printFont = New Font(c.Font.Name, c.Font.Size)
                        Dim w As Single = _printFont.GetHeight(ev.Graphics)
                        ev.Graphics.DrawEllipse(_Pen, x, y, w, w)
                        If CType(c, RadioButton).Checked Then
                            Dim d As Single = 3
                            ev.Graphics.FillEllipse(_Brush, x + d, y + d, w - d - d, w - d - d)
                        End If
                        PrintText(c, ev, x + CInt((w * 1.4)), y - 2, False, False, False, HorizontalAlignment.Left)
                    Case "System.Windows.Forms.Panel"
     
                        If CType(c, System.Windows.Forms.Panel).BorderStyle <> BorderStyle.None Then
                            If CType(c, System.Windows.Forms.Panel).BorderStyle = BorderStyle.Fixed3D Then
                                _Pen = New Pen(Color.Silver)
                            End If
                            ev.Graphics.DrawRectangle(_Pen, x, y, c.Width, c.Height)
                        End If
     
                    Case "System.Windows.Forms.GroupBox"
                        _Pen = New Pen(Color.Silver)
                        Dim w As Single = _printFont.GetHeight(ev.Graphics)
                        ev.Graphics.DrawRectangle(_Pen, x, y + w - w, c.Width, c.Height - w + w)
                        PrintText(c, ev, x + w, y, False, True, False, HorizontalAlignment.Left)
     
                    Case "System.Windows.Forms.TabControl"
                        Dim tc As System.Windows.Forms.TabControl = c
                        _Pen = New Pen(Color.Gray)
                        If TabControlBoxed Then
                            ev.Graphics.DrawRectangle(_Pen, x, y, c.Width, c.Height)
                        End If
                        Dim points As PointF() = {New PointF(x, y + tc.ItemSize.Height), New PointF(x + tc.Width, y + tc.ItemSize.Height)}
                        ev.Graphics.DrawLines(_Pen, points)
                        Dim tp As System.Windows.forms.TabPage = tc.SelectedTab
                        'Nom du TabPage
                        _printFont = New Font(c.Font.Name, c.Font.Size, FontStyle.Bold)
                        ev.Graphics.DrawString(tp.Text, _printFont, Brushes.Black, x, y + (tc.ItemSize.Height - _printFont.GetHeight(ev.Graphics)) / 2)
     
                    Case "System.Windows.Forms.PictureBox"
                        Dim pic As PictureBox = c
                        ev.Graphics.DrawImage(pic.Image, x, y, c.Width, c.Height)
     
     
                End Select
            End If
        End Sub
     
        Public Sub PrintText(ByVal c As System.Windows.forms.Control, ByVal ev As PrintPageEventArgs, ByVal x As Single, ByVal y As Single, ByVal tbBoxed As Boolean, ByVal inBold As Boolean, ByVal verticalCentering As Boolean, ByVal hAlignment As HorizontalAlignment)
            Dim r As RectangleF
            r.X = x
            r.Y = y
            r.Width = c.Width
            r.Height = c.Height
     
            'Box
            If tbBoxed Then
                ev.Graphics.DrawRectangle(_Pen, r.X, r.Y, r.Width, r.Height)
            End If
     
            'Text
            If inBold Then
                _printFont = New Font(c.Font.Name, c.Font.Size, FontStyle.Bold)
            Else
                _printFont = New Font(c.Font.Name, c.Font.Size)
            End If
     
            If verticalCentering Then
                Dim fontHeight As Single = _printFont.GetHeight(ev.Graphics)
                Dim deltaHeight As Single = (r.Height - fontHeight) / 2
                r.Y += deltaHeight
            Else
                r.Y += 2
            End If
     
            Dim drawFormat As New StringFormat
            Select Case hAlignment
                Case HorizontalAlignment.Left
                    drawFormat.Alignment = StringAlignment.Near
                Case HorizontalAlignment.Center
                    drawFormat.Alignment = StringAlignment.Center
                Case HorizontalAlignment.Right
                    drawFormat.Alignment = StringAlignment.Far
                Case 64
                    drawFormat.Alignment = StringAlignment.Far
                    r.Y = r.Y + CInt(r.Height / 2) - CInt(_printFont.Height / 2)
                Case 32
                    drawFormat.Alignment = StringAlignment.Center
                    r.Y = r.Y + CInt(r.Height / 2) - CInt(_printFont.Height / 2)
                Case 512
                    drawFormat.Alignment = StringAlignment.Center
                    r.Y = r.Y + CInt(r.Height / 2) - 2
                Case 4  ' top right
                    drawFormat.Alignment = StringAlignment.Far
                Case 1024 ' bottom right
                    drawFormat.Alignment = StringAlignment.Far
                    r.Y = r.Y + CInt(r.Height / 2) - CInt(_printFont.Height / 2)
                Case 16 ' midle left
                    drawFormat.Alignment = StringAlignment.Near
                    r.Y = r.Y + 2
                Case 256 ' middle left
                    drawFormat.Alignment = StringAlignment.Near
                    r.Y = r.Y + CInt(r.Height / 2) - 2
                Case 255
                    drawFormat.Alignment = StringAlignment.Near
            End Select
            ev.Graphics.DrawString(c.Text, _printFont, _Brush, r, drawFormat)
        End Sub
     
        Public Sub PrintList(ByVal ctext As String, ByVal c As System.Windows.forms.Control, ByVal ev As PrintPageEventArgs, ByVal x As Single, ByVal y As Single, ByVal inBold As Boolean)
            Dim r As RectangleF
            r.X = x
            r.Y = y
            r.Width = c.Width
            r.Height = c.Height
     
            'Box
     
     
            'Text
            If inBold Then
                _printFont = New Font(c.Font.Name, c.Font.Size, FontStyle.Bold)
            Else
                _printFont = New Font(c.Font.Name, c.Font.Size)
            End If
     
     
     
            Dim drawFormat As New StringFormat
            drawFormat.Alignment = StringAlignment.Near
     
            ev.Graphics.DrawString(ctext, _printFont, _Brush, r, drawFormat)
        End Sub
     
        Public Sub PrintCadre(ByVal c As System.Windows.forms.Control, ByVal ev As PrintPageEventArgs, ByVal x As Single, ByVal y As Single, ByVal w As Integer, ByVal h As Integer)
            Dim r As RectangleF
            r.X = x
            r.Y = y
            r.Width = w
            r.Height = h
            'Box
            ev.Graphics.DrawRectangle(_Pen, r.X, r.Y, r.Width, r.Height)
        End Sub
    End Class
    Fichiers attachés Fichiers attachés

Discussions similaires

  1. [AC-2013] imprimer plusieurs page sur sélection nombre d'un formulaire
    Par jetsteph57 dans le forum Access
    Réponses: 0
    Dernier message: 31/05/2015, 13h28
  2. [XL-2003] Imprimer un grand formulaire sur deux pages
    Par pikameuh dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 07/07/2011, 09h41
  3. Réponses: 6
    Dernier message: 29/10/2010, 17h26
  4. imprimer formulaire sur une page
    Par the big ben 5 dans le forum Access
    Réponses: 1
    Dernier message: 16/08/2006, 20h33
  5. Réponses: 2
    Dernier message: 14/02/2006, 16h31

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo