Régler les propriétés d'impression vb.net

Résolu
Sofiadev - 3 janv. 2013 à 10:27
 Sofiadev - 3 janv. 2013 à 19:27
Bonjour,
Je souhaite imprimer des parties spécifiques de ma forme vb.net, j'ai déjà utilisé un petit code:
  PrintForm1.Print()


mais il m'imprime qu'une partie que la partie gauche et vue que j'ai une grande fenêtre avec beaucoup de graphes, je voulez afficher la fenêtre de propriétés d'impression pour que l'utilisateur puisse régler la plage et l'imprimante voulue etc.
Merci pour votre aide

4 réponses

Utilisateur anonyme
3 janv. 2013 à 13:45
Bonjour,

Il y a un article (en anglais) ici avec des codes exemples sur l'utilisation ce composant.
3
cs_Le Pivert Messages postés 7903 Date d'inscription jeudi 13 septembre 2007 Statut Contributeur Dernière intervention 11 mars 2024 137
3 janv. 2013 à 18:07
Bonjour,

Je peux te proposer de divisiser ton Form en 4, avec 4 Panels où tu mettrais tes controles. Ensuite tu ferais une capture de contrôle en fonction de la zone qui t'interesse.

Dans un module mettre ce code:

 
Option Strict On
Imports System.Drawing.Imaging
Module Capture_Bitmap
    Private Declare Auto Function BitBlt Lib "gdi32.dll" _
    (ByVal pHdc As IntPtr, ByVal iX As Integer, _
    ByVal iY As Integer, ByVal iWidth As Integer, _
    ByVal iHeight As Integer, ByVal pHdcSource As IntPtr, _
    ByVal iXSource As Integer, ByVal iYSource As Integer, _
    ByVal dw As System.Int32) As Boolean
    Private Const SRC As Integer = &HCC0020

Public Sub ConvertPanel_BMP(ByVal pnl As Panel, ByVal sFilePath As String, ByVal format As String)
        pnl.Refresh()
        pnl.Select()
        Dim g As Graphics = pnl.CreateGraphics
        Dim ibitMap As New Bitmap(pnl.ClientSize.Width, pnl.ClientSize.Height, g)
        Dim iBitMap_gr As Graphics = Graphics.FromImage(ibitMap)
        Dim iBitMap_hdc As IntPtr = iBitMap_gr.GetHdc
        Dim me_hdc As IntPtr = g.GetHdc
        BitBlt(iBitMap_hdc, 0, 0, pnl.ClientSize.Width, pnl.ClientSize.Height, me_hdc, 0, 0, SRC)
        g.ReleaseHdc(me_hdc)
        iBitMap_gr.ReleaseHdc(iBitMap_hdc)
        If sFilePath = "" Then Exit Sub
        Select Case format
            Case ".bmp"
                ibitMap.Save(sFilePath, ImageFormat.Bmp)
            Case ".jpg"
                ibitMap.Save(sFilePath, ImageFormat.Jpeg)
            Case ".gif"
                ibitMap.Save(sFilePath, ImageFormat.Gif)
            Case ".png"
                ibitMap.Save(sFilePath, ImageFormat.Png)
            Case ".tif"
                ibitMap.Save(sFilePath, ImageFormat.Tiff)
            Case Else
                ibitMap.Save(sFilePath, ImageFormat.Jpeg)
        End Select
    End Sub

  End Module


Dans des buttons en fonction du panel choisi (zone):

  Dim sFilePath As String
        Dim ext As String
        Dim sfd As New SaveFileDialog
        With sfd
            .Title = "Enregistrer l'image"
            .FileName = "Capture"
            .Filter = "JPeg Files (*.jpg,*.jpeg)|*.jpg;*.jpeg|Bitmap Files (*.bmp)|*.bmp|Gif Files (*.gif)|*.gif|Tif Files (*.tif)|*.tif|Png Files (*.png)|*.png"
            .FilterIndex = 1
            If .ShowDialog() = Windows.Forms.DialogResult.OK Then
                sFilePath = .FileName 'chemin de l'image enregistrée
                ext = GetExtension(sFilePath) 'extension seule
                                                ConvertPanel_BMP(Panel1, sFilePath, ext)'mettre le panel correspondant
                           Else
                MessageBox.Show("Opération annulée par l'utilisateur!", "Enregistrement image", MessageBoxButtons.OK, MessageBoxIcon.Information)
                Exit Sub
            End If
            .Dispose()
        End With
    


Pour récupérer l'extension mettre en haut:

Option Strict On
Imports System.IO.Path


et ceci:

 ' extension seule
    Public Function FileNameExtension(ByVal Chaine As String) As String
        Return GetExtension(Chaine)
    End Function




Pour plus amples informations voir cette source:

http://www.vbfrance.com/codes/CAPTURE-CONTROLES_54783.aspx

@+ Le Pivert
3
Utilisateur anonyme
3 janv. 2013 à 13:54
sur l'utilisation de ce composant
0
Bonjour,
Je vous remercie pour vos réponses, j'arrive à afficher la fenêtre des propriétés de l'imprimante, ainsi contrôler la partie que je veux imprimer
Merci
0
Rejoignez-nous