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 :

[VB.NET] code pour afficher apercu avant impression


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    121
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 121
    Par défaut [VB.NET] code pour afficher apercu avant impression
    Bonjour,
    je cherche le code pour pouvoir afficher un aperçu avant impression pour un editeur de texte avec richtextbox prenant en compte images,couleur et propriétés de police ,...
    et tout cela en VB.NET
    lool
    donc si vous savez ou je peux trouver cela dans un tutorial,aide,forum ,source ou autre
    mercii
    ++

  2. #2
    Membre confirmé
    Profil pro
    Inscrit en
    Décembre 2005
    Messages
    121
    Détails du profil
    Informations personnelles :
    Âge : 49
    Localisation : France

    Informations forums :
    Inscription : Décembre 2005
    Messages : 121
    Par défaut
    Bon alors attention je vous envoie le code
    je comprends pas pourquoi lorsque je lance l'apercu avant impression j'ai le message comme quoi il n'y a aucune page a imprimer (je rappelle que j'utilise un component richeditbox heritant du cointrole richtextbox que jajoute a ma form)

    CODE DE MON COMPONENT RICHEDITBOX
    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
    369
    370
    371
    372
    373
    374
    375
     
    Imports System
    imports System.Windows.Forms
    imports System.Drawing
    imports System.Runtime.InteropServices
    imports System.Drawing.Printing
     
    Public Class RichEditBox
        Inherits System.Windows.Forms.RichTextBox
     
        ' Methods
     
        Private Sub _Print(ByVal showPrintDialog As Boolean)
            Dim _DialogResult As DialogResult = DialogResult.OK
            If showPrintDialog Then
                Dim _PrintDialog As New PrintDialog
                _PrintDialog.Document = Me._PrintDocument
                _DialogResult = _PrintDialog.ShowDialog
            End If
            If (_DialogResult = DialogResult.OK) Then
                Me._PrintDocument.Print()
            End If
        End Sub
     
     
     
        Private Sub _PrintDocumentBeginPrint(ByVal sender As Object, ByVal e As PrintEventArgs)
            Me._FirstChar = 0
        End Sub
     
     
        Private Sub _PrintDocumentEndPrint(ByVal sender As Object, ByVal e As PrintEventArgs)
            Me.FormatRangeDone()
        End Sub
     
        Private Sub _PrintDocumentPrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
            Me._FirstChar = Me.FormatRanger(False, e, Me._FirstChar, Me.TextLength)
            If (Me._FirstChar < Me.TextLength) Then
                e.HasMorePages = True
            Else
                e.HasMorePages = False
            End If
        End Sub
     
        Private Function FormatRanger(ByVal measureOnly As Boolean, ByVal e As Printing.PrintPageEventArgs, ByVal charFrom As Integer, ByVal charTo As Integer) As Integer
            Dim cr As CHARRANGE
            Dim rc As RECT
            Dim rcPage As RECT
            Dim fr As FORMATRANGE
            cr.cpMin = charFrom
            cr.cpMax = charTo
            rc.top = Me.HundredthInchToTwips(e.MarginBounds.Top)
            rc.bottom = Me.HundredthInchToTwips(e.MarginBounds.Bottom)
            rc.left = Me.HundredthInchToTwips(e.MarginBounds.Left)
            rc.right = Me.HundredthInchToTwips(e.MarginBounds.Right)
            rcPage.top = Me.HundredthInchToTwips(e.PageBounds.Top)
            rcPage.bottom = Me.HundredthInchToTwips(e.PageBounds.Bottom)
            rcPage.left = Me.HundredthInchToTwips(e.PageBounds.Left)
            rcPage.right = Me.HundredthInchToTwips(e.PageBounds.Right)
            Dim hdc As IntPtr = e.Graphics.GetHdc
            fr.chrg = cr
            fr.hdc = hdc
            fr.hdcTarget = hdc
            fr.rc = rc
            fr.rcPage = rcPage
            Dim wpar As New IntPtr
            Dim lpar As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(fr))
            Marshal.StructureToPtr(fr, lpar, False)
            Dim res As IntPtr = WindowsAPI.SendMessage(MyBase.Handle, 1081, wpar, lpar)
            Marshal.FreeCoTaskMem(lpar)
            e.Graphics.ReleaseHdc(hdc)
            Return res.ToInt32
        End Function
        Private Sub FormatRangeDone()
            Dim wpar As New IntPtr(0)
            Dim lpar As New IntPtr(0)
            WindowsAPI.SendMessage(MyBase.Handle, 1081, wpar, lpar)
        End Sub
     
     
     
     
        Private Sub Initialize()
            Me._PrintDocument = New PrintDocument
            AddHandler Me._PrintDocument.BeginPrint, New PrintEventHandler(AddressOf Me._PrintDocumentBeginPrint)
            AddHandler Me._PrintDocument.PrintPage, New PrintPageEventHandler(AddressOf Me._PrintDocumentPrintPage)
            AddHandler Me._PrintDocument.EndPrint, New PrintEventHandler(AddressOf Me._PrintDocumentEndPrint)
        End Sub
     
     
        Public Sub Print()
            Me._Print(False)
        End Sub
     
     
     
        Public Sub Print(ByVal showPrintDialog As Boolean)
            Me._Print(showPrintDialog)
        End Sub
     
     
     
        Private Function SetTargetDevice(ByVal g As Graphics, ByVal lineLen As Integer) As Boolean
            Dim wpar As IntPtr = g.GetHdc
            Dim lpar As New IntPtr(Me.HundredthInchToTwips(lineLen))
            Dim res As IntPtr = WindowsAPI.SendMessage(MyBase.Handle, 1096, wpar, lpar)
            g.ReleaseHdc(wpar)
            Return (res.ToInt32 <> 0)
        End Function
     
     
     
        ' Properties
        Public ReadOnly Property Document() As PrintDocument
            Get
                Return Me._PrintDocument
            End Get
        End Property
     
     
     
        Public Property PageSettings() As PageSettings
            Get
                Return Me._PrintDocument.DefaultPageSettings
            End Get
            Set(ByVal value As PageSettings)
                Me._PrintDocument.DefaultPageSettings = value
            End Set
        End Property
     
     
     
        ' Fields
        Private _FirstChar As Integer
        Private _PrintDocument As PrintDocument
        Private Const EM_FORMATRANGE As Integer = 1081
        Private Const EM_SETTARGETDEVICE As Integer = 1096
     
     
     
        <StructLayout(LayoutKind.Sequential)> _
    Public Structure CHARRANGE
            ' Fields
            Public cpMax As Integer
            Public cpMin As Integer
        End Structure
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure RECT
            ' Fields
            Public bottom As Integer
            Public left As Integer
            Public right As Integer
            Public top As Integer
        End Structure
     
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure FORMATRANGE
            ' Fields
            Public chrg As CHARRANGE
            Public hdc As IntPtr
            Public hdcTarget As IntPtr
            Public rc As RECT
            Public rcPage As RECT
        End Structure
        Private Function HundredthInchToTwips(ByVal n As Integer) As Integer
            Return CInt((n * 14.4))
        End Function
     
        Public Enum Msg
            ' Fields
            WM_ACTIVATE = 6
            WM_ACTIVATEAPP = 28
            WM_AFXFIRST = 864
            WM_AFXLAST = 895
            WM_APP = 32768
            WM_ASKCBFORMATNAME = 780
            WM_CANCELJOURNAL = 75
            WM_CANCELMODE = 31
            WM_CAPTURECHANGED = 533
            WM_CHANGECBCHAIN = 781
            WM_CHAR = 258
            WM_CHARTOITEM = 47
            WM_CHILDACTIVATE = 34
            WM_CLEAR = 771
            WM_CLOSE = 16
            WM_COMMAND = 273
            WM_COMMNOTIFY = 68
            WM_COMPACTING = 65
            WM_COMPAREITEM = 57
            WM_CONTEXTMENU = 123
            WM_COPY = 769
            WM_COPYDATA = 74
            WM_CREATE = 1
            WM_CTLCOLOR = 25
            WM_CTLCOLORBTN = 309
            WM_CTLCOLORDLG = 310
            WM_CTLCOLOREDIT = 307
            WM_CTLCOLORLISTBOX = 308
            WM_CTLCOLORMSGBOX = 306
            WM_CTLCOLORSCROLLBAR = 311
            WM_CTLCOLORSTATIC = 312
            WM_CUT = 768
            WM_DEADCHAR = 259
            WM_DELETEITEM = 45
            WM_DESTROY = 2
            WM_DESTROYCLIPBOARD = 775
            WM_DEVICECHANGE = 537
            WM_DEVMODECHANGE = 27
            WM_DISPLAYCHANGE = 126
            WM_DRAWCLIPBOARD = 776
            WM_DRAWITEM = 43
            WM_DROPFILES = 563
            WM_ENABLE = 10
            WM_ENDSESSION = 22
            WM_ENTERIDLE = 289
            WM_ENTERMENULOOP = 529
            WM_ENTERSIZEMOVE = 561
            WM_ERASEBKGND = 20
            WM_EXITMENULOOP = 530
            WM_EXITSIZEMOVE = 562
            WM_FONTCHANGE = 29
            WM_GETDLGCODE = 135
            WM_GETFONT = 49
            WM_GETHOTKEY = 51
            WM_GETICON = 127
            WM_GETMINMAXINFO = 36
            WM_GETOBJECT = 61
            WM_GETTEXT = 13
            WM_GETTEXTLENGTH = 14
            WM_HANDHELDFIRST = 856
            WM_HANDHELDLAST = 863
            WM_HELP = 83
            WM_HOTKEY = 786
            WM_HSCROLL = 276
            WM_HSCROLLCLIPBOARD = 782
            WM_ICONERASEBKGND = 39
            WM_IME_CHAR = 646
            WM_IME_COMPOSITION = 271
            WM_IME_COMPOSITIONFULL = 644
            WM_IME_CONTROL = 643
            WM_IME_ENDCOMPOSITION = 270
            WM_IME_KEYDOWN = 656
            WM_IME_KEYLAST = 271
            WM_IME_KEYUP = 657
            WM_IME_NOTIFY = 642
            WM_IME_REQUEST = 648
            WM_IME_SELECT = 645
            WM_IME_SETCONTEXT = 641
            WM_IME_STARTCOMPOSITION = 269
            WM_INITDIALOG = 272
            WM_INITMENU = 278
            WM_INITMENUPOPUP = 279
            WM_INPUTLANGCHANGE = 81
            WM_INPUTLANGCHANGEREQUEST = 80
            WM_KEYDOWN = 256
            WM_KEYLAST = 264
            WM_KEYUP = 257
            WM_KILLFOCUS = 8
            WM_LBUTTONDBLCLK = 515
            WM_LBUTTONDOWN = 513
            WM_LBUTTONUP = 514
            WM_MBUTTONDBLCLK = 521
            WM_MBUTTONDOWN = 519
            WM_MBUTTONUP = 520
            WM_MDIACTIVATE = 546
            WM_MDICASCADE = 551
            WM_MDICREATE = 544
            WM_MDIDESTROY = 545
            WM_MDIGETACTIVE = 553
            WM_MDIICONARRANGE = 552
            WM_MDIMAXIMIZE = 549
            WM_MDINEXT = 548
            WM_MDIREFRESHMENU = 564
            WM_MDIRESTORE = 547
            WM_MDISETMENU = 560
            WM_MDITILE = 550
            WM_MEASUREITEM = 44
            WM_MENUCHAR = 288
            WM_MENUCOMMAND = 294
            WM_MENUDRAG = 291
            WM_MENUGETOBJECT = 292
            WM_MENURBUTTONUP = 290
            WM_MENUSELECT = 287
            WM_MOUSEACTIVATE = 33
            WM_MOUSEHOVER = 673
            WM_MOUSELEAVE = 675
            WM_MOUSEMOVE = 512
            WM_MOUSEWHEEL = 522
            WM_MOVE = 3
            WM_MOVING = 534
            WM_NCACTIVATE = 134
            WM_NCCALCSIZE = 131
            WM_NCCREATE = 129
            WM_NCDESTROY = 130
            WM_NCHITTEST = 132
            WM_NCLBUTTONDBLCLK = 163
            WM_NCLBUTTONDOWN = 161
            WM_NCLBUTTONUP = 162
            WM_NCMBUTTONDBLCLK = 169
            WM_NCMBUTTONDOWN = 167
            WM_NCMBUTTONUP = 168
            WM_NCMOUSEMOVE = 160
            WM_NCPAINT = 133
            WM_NCRBUTTONDBLCLK = 166
            WM_NCRBUTTONDOWN = 164
            WM_NCRBUTTONUP = 165
            WM_NEXTDLGCTL = 40
            WM_NEXTMENU = 531
            WM_NOTIFY = 78
            WM_NOTIFYFORMAT = 85
            WM_NULL = 0
            WM_PAINT = 15
            WM_PAINTCLIPBOARD = 777
            WM_PAINTICON = 38
            WM_PALETTECHANGED = 785
            WM_PALETTEISCHANGING = 784
            WM_PARENTNOTIFY = 528
            WM_PASTE = 770
            WM_PENWINFIRST = 896
            WM_PENWINLAST = 911
            WM_POWER = 72
            WM_PRINT = 791
            WM_PRINTCLIENT = 792
            WM_QUERYDRAGICON = 55
            WM_QUERYENDSESSION = 17
            WM_QUERYNEWPALETTE = 783
            WM_QUERYOPEN = 19
            WM_QUEUESYNC = 35
            WM_QUIT = 18
            WM_RBUTTONDBLCLK = 518
            WM_RBUTTONDOWN = 516
            WM_RBUTTONUP = 517
            WM_REFLECT = 8192
            WM_RENDERALLFORMATS = 774
            WM_RENDERFORMAT = 773
            WM_SETCURSOR = 32
            WM_SETFOCUS = 7
            WM_SETFONT = 48
            WM_SETHOTKEY = 50
            WM_SETICON = 128
            WM_SETREDRAW = 11
            WM_SETTEXT = 12
            WM_SETTINGCHANGE = 26
            WM_SHOWWINDOW = 24
            WM_SIZE = 5
            WM_SIZECLIPBOARD = 779
            WM_SIZING = 532
            WM_SPOOLERSTATUS = 42
            WM_STYLECHANGED = 125
            WM_STYLECHANGING = 124
            WM_SYNCPAINT = 136
            WM_SYSCHAR = 262
            WM_SYSCOLORCHANGE = 21
            WM_SYSCOMMAND = 274
            WM_SYSDEADCHAR = 263
            WM_SYSKEYDOWN = 260
            WM_SYSKEYUP = 261
            WM_TCARD = 82
            WM_TIMECHANGE = 30
            WM_TIMER = 275
            WM_UNDO = 772
            WM_UNINITMENUPOPUP = 293
            WM_USER = 1024
            WM_USERCHANGED = 84
            WM_VKEYTOITEM = 46
            WM_VSCROLL = 277
            WM_VSCROLLCLIPBOARD = 778
            WM_WINDOWPOSCHANGED = 71
            WM_WINDOWPOSCHANGING = 70
            WM_WININICHANGE = 26
        End Enum
     
     
     
    End Class

    CODE MENU DE MA FORM APPELANT APERCU
    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
    Public Class Form1
     
        Dim richedit1 As RichEditBox
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     
            Try
                richedit1 = New RichEditBox
     
                richedit1.Dock = DockStyle.Bottom
                Me.Controls.Add(richedit1)
            Catch ex As Exception
     
            End Try
     
        End Sub
     
        Private Sub AperçuavantimpressionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AperçuavantimpressionToolStripMenuItem.Click
            Dim _PrintPreviewDialog As PrintPreviewDialog = New PrintPreviewDialog()
            _PrintPreviewDialog.Document = Me.richedit1.Document
            _PrintPreviewDialog.ShowDialog()
        End Sub
    End Class
    a moins que ca vienne des declarations de mes api
    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
    Public Class WindowsAPI
        ' Methods
        Private Sub New()
     
        End Sub
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer
        End Function
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As IntPtr) As IntPtr
     
     
        End Function
        <DllImport("user32.dll", CharSet:=CharSet.Auto)> _
        Public Shared Function SendMessage(ByVal hWnd As IntPtr, ByVal msg As Integer, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As IntPtr
     
        End Function
     
    End Class
    le code logiquement est quasiment bon
    il doit y avoir un detail ... roo mince looll
    aidez moi peut etre que je ne trouverai po avant
    ++

Discussions similaires

  1. [OL-2003] Code pour afficher le Pop-Up d'impression lors de l'exécution d'une macro
    Par Dailyplanet dans le forum VBA Outlook
    Réponses: 4
    Dernier message: 05/10/2009, 09h14
  2. code pour afficher sur listview en dao
    Par sanfour_walhan dans le forum VB 6 et antérieur
    Réponses: 1
    Dernier message: 07/12/2006, 21h22
  3. creer un apercu avant impression d'un StringGrid
    Par blondelle dans le forum C++Builder
    Réponses: 28
    Dernier message: 09/08/2006, 22h57
  4. Problème entre "apercu avant impression" et "impression"
    Par mariemor64 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 18/07/2006, 11h57
  5. Recherche un script code pour afficher la charge serveur
    Par kevinf dans le forum EDI, CMS, Outils, Scripts et API
    Réponses: 8
    Dernier message: 02/06/2006, 21h01

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