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

VB.NET Discussion :

Impression d'un objet"Pannel"


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    1
    Inscrit en
    Décembre 2011
    Messages
    9
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : 1
    Secteur : Industrie

    Informations forums :
    Inscription : Décembre 2011
    Messages : 9
    Par défaut Impression d'un objet"Pannel"
    j'ai réalisé une forme qui contient un Pannel, et un bouton print
    je veux si on appui sur le bouton print il aura impression du pannel et son contenu
    j'ai essayer plusieurs code mais rien
    merciii

  2. #2
    Modérateur
    Avatar de Sankasssss
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2006
    Messages
    1 842
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 842
    Par défaut
    Bonsoir,

    en vous basant sur le code de ce cours, vous devriez y arriver.

  3. #3
    Membre Expert Avatar de hunteshiva
    Homme Profil pro
    Chef de projet en SSII
    Inscrit en
    Février 2010
    Messages
    1 069
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Gironde (Aquitaine)

    Informations professionnelles :
    Activité : Chef de projet en SSII
    Secteur : Industrie

    Informations forums :
    Inscription : Février 2010
    Messages : 1 069
    Par défaut
    Bonjour,

    en écrivant "vb.net imprimer panel" sur
    tu a la solution dés le premier lien

    Sinon, pour dessiner une fenêtre dans une image, il y a la fonction DrawToBitmap qui est disponible pour n'importe quel contrôle.
    a tester quand même et dit moi si ça a marché

  4. #4
    Membre émérite

    Homme Profil pro
    Inscrit en
    Mars 2012
    Messages
    691
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Israël

    Informations forums :
    Inscription : Mars 2012
    Messages : 691
    Par défaut
    Salut

    une class pour imprimer un control de ta form ou toute ta form

    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
      mports System.Drawing.Printing
    Public Class ClassImpression
        Private myimage As Bitmap
        Private thectrl As Control
     
        Private Function Capturectrl(ByVal ctrl As Control) As Bitmap
            Dim memoryImage As Bitmap
            Dim memoryGraphics As Graphics
            memoryImage = Nothing
            Dim mygraphics As Graphics = ctrl.CreateGraphics()
            Dim s As Size = ctrl.Size
            If TypeOf ctrl Is Form AndAlso DirectCast(ctrl, Form).FormBorderStyle <> FormBorderStyle.None Then
                memoryImage = New Bitmap(s.Width - 10, s.Height - (SystemInformation.FrameBorderSize.Width + 6 + SystemInformation.CaptionHeight), mygraphics)
                memoryGraphics = Graphics.FromImage(memoryImage)
                memoryGraphics.CopyFromScreen(0, (SystemInformation.FrameBorderSize.Width + 0 + SystemInformation.CaptionHeight), 0, 0, New Size(memoryImage.Width, memoryImage.Height), CopyPixelOperation.SourceCopy)
            Else
                memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
                memoryGraphics = Graphics.FromImage(memoryImage)
                memoryGraphics.CopyFromScreen(ctrl.Left, ctrl.Top, 0, 0, New Size(memoryImage.Width, memoryImage.Height), CopyPixelOperation.SourceCopy)
            End If
            Return memoryImage
        End Function
        Public Function GetPreview() As Bitmap
            Return Capturectrl(thectrl)
        End Function
        Public Sub printdoc()
            Try
                Dim prtd As New PrintDialog
     
                'document à imprimer
                Dim doc As New PrintDocument
                myimage = Capturectrl(thectrl)
                AddHandler doc.PrintPage, AddressOf printform
                'paramètres de page
                Dim ps As New PageSettings
                ps.Landscape = False
                doc.DefaultPageSettings = ps
                'indique à la prévisualisation le document à montrer
                prtd.Document = doc
                If prtd.ShowDialog = DialogResult.OK Then
                    prtd.Document.Print()
                End If
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
     
        Private Sub printform(ByVal sender As Object, ByVal e As PrintPageEventArgs)
            Try
                e.Graphics.DrawImage(myimage, 0, 0)
                e.HasMorePages = False
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
     
        Public Sub New(ByVal ctrl As Control)
            thectrl = ctrl
        End Sub
    End Class
    pour utiliser
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     Dim printer As New ClassImpression(mypanel)
            printer.printdoc()

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