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 Form mise en forme [Débutant]


Sujet :

VB.NET

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Septembre 2013
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2013
    Messages : 13
    Points : 9
    Points
    9
    Par défaut Impression Form mise en forme
    Bonjour à toutes et tous

    Je ne sais pas comment faire pour imprimer mon écran et qu'il contienne dans le page A4.

    J'ai créé un form dans lequel il y a des photos des label des textbox
    sa taille 1400 x 1000

    mais quand je fais :

    PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
    PrintForm1.Print(Me, PrintForm.PrintOption.FullWindow)

    je n'ai qu'un coin de la page.

    Mon but c'est quand je clique sur mon bouton imprimer je sorte sur une page l'ecran.

    Merci de votre aide

  2. #2
    Expert confirmé
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Points : 4 005
    Points
    4 005
    Billets dans le blog
    7
    Par défaut
    Bonjour alexworks,

    Tu veux imprimer ton écran ou bien la fenêtre active de ton application exactement ? (car ce n'est pas la même chose !)

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Septembre 2013
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2013
    Messages : 13
    Points : 9
    Points
    9
    Par défaut imp ecran
    l'écran serait bien
    la fenêtre active serait le top

  4. #4
    Expert confirmé
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Points : 4 005
    Points
    4 005
    Billets dans le blog
    7
    Par défaut
    ok pour la capture d'écran. Pour la fenêtre active il faudrait utiliser les fonctions API.

    Sinon pour ma part ne connaissant pas la classe d'impression alors je peux te recommander :

    - d'utiliser une capture d'écran ainsi tu pourras récupérer une image.
    - cette image obtenue pourra être redimensionnée pour tenir dans un format A4

    Fonction de capture :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    Public Function CaptureScreen() as Bitmap
      Dim bounds As Rectangle
            Dim screenshot As System.Drawing.Bitmap
            Dim graph As Graphics
            bounds = Screen.PrimaryScreen.Bounds
            screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
            graph = Graphics.FromImage(screenshot)
            graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
            graph.Dispose()
            Return screenshot
    End Sub
    Fonction de redimensionnement (qui respecte le ratio) :

    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
     
            Public Function GetRatioRedimPicture(ByVal Img As Bitmap, ByVal siz As Size) As Image
                Dim imgOrg As Bitmap
                Dim imgShow As Bitmap
                Dim g As Graphics
                Dim divideBy, divideByH, divideByW As Double
                imgOrg = Img
                divideByW = imgOrg.Width / siz.Width
                divideByH = imgOrg.Height / siz.Height
                If divideByW > 1 Or divideByH > 1 Then
                    If divideByW > divideByH Then
                        divideBy = divideByW
                    Else
                        divideBy = divideByH
                    End If
                    imgShow = New Bitmap(CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy))
                    imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
                    g = Graphics.FromImage(imgShow)
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
                    g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
                    g.DrawImage(imgOrg, New Rectangle(0, 0, CInt(CDbl(imgOrg.Width) / divideBy), CInt(CDbl(imgOrg.Height) / divideBy)), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
                    g.Dispose()
                Else
                    imgShow = New Bitmap(imgOrg.Width, imgOrg.Height)
                    imgShow.SetResolution(imgOrg.HorizontalResolution, imgOrg.VerticalResolution)
                    g = Graphics.FromImage(imgShow)
                    g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality
                    g.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
                    g.DrawImage(imgOrg, New Rectangle(0, 0, imgOrg.Width, imgOrg.Height), 0, 0, imgOrg.Width, imgOrg.Height, GraphicsUnit.Pixel)
                    g.Dispose()
                End If
                imgOrg.Dispose()
                Return imgShow
            End Function
    Comment capturer ton écran et l'enregistrer dans un fichier qui ne dépassera pas les dimensions A4 (21 x 29,7) ou 595 x 842 Pixels :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
      GetRatioRedimPicture(CaptureScreen(), New Size(595, 842)).Save("C:\" & New Random().Next.ToString & ".bmp", Imaging.ImageFormat.Bmp)
    A+

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Septembre 2013
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2013
    Messages : 13
    Points : 9
    Points
    9
    Par défaut
    Merci beaucoup

    l'imprim écran fonctionne a merveille
    mais le résultat ne fais pas très propre.

    je vais chercher du coté des fonction API que je ne connais pas du tout.

  6. #6
    Expert confirmé
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Points : 4 005
    Points
    4 005
    Billets dans le blog
    7
    Par défaut
    Ca ne mettra pas longtemps pour te mettre quelques réponses à dispo car le domaine de capture d'écran a déjà fait l'objet d'étude dans un de mes projets

    Donc voici grossomodo la capture de la fenêtre active (c'est mis en vrac mais penses à bien séparer les fonction s natives du reste du code, à découper les fonctions ...etc..... :

    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
     
        Public Enum Window_State
            SW_SHOWNORMAL = 1
            SW_SHOWMINIMIZED = 2
            SW_SHOWMAXIMIZED = 3
        End Enum
     
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure WINDOWPLACEMENT
            Public length As Integer
            Public flags As Integer
            Public showCmd As Integer
            Public ptMinPosition As System.Drawing.Point
            Public ptMaxPosition As System.Drawing.Point
            Public rcNormalPosition As System.Drawing.Rectangle
        End Structure
     
        <StructLayout(LayoutKind.Sequential)> _
        Public Structure RECT
            Public left As Integer
            Public top As Integer
            Public right As Integer
            Public bottom As Integer
        End Structure
        <DllImport("user32.dll")> _
        Public Shared Function GetForegroundWindow() As Integer
        End Function
        <DllImport("user32.dll")> _
        Public Shared Function GetDesktopWindow() As IntPtr
        End Function
        <DllImport("user32.dll")> _
        Public Shared Function GetWindowDC(hWnd As IntPtr) As IntPtr
        End Function
        <DllImport("user32.dll")> _
        Public Shared Function ReleaseDC(hWnd As IntPtr, hDC As IntPtr) As IntPtr
        End Function
        <DllImport("user32.dll")> _
        Public Shared Function GetWindowPlacement(hWnd As IntPtr, ByRef lpwndpl As WINDOWPLACEMENT) As Boolean
        End Function
        <DllImport("user32.dll")> _
        Public Shared Function GetWindowRect(hWnd As IntPtr, ByRef rect As RECT) As IntPtr
        End Function
     
     
        Public Function ScreenActivetWindow() As Bitmap
            Dim hWnd As Integer = GetForegroundWindow()
            Dim bounds As New RECT()
            GetWindowRect(CType(hWnd, IntPtr), bounds)
            Dim width As Integer = bounds.right - bounds.left
            Dim height As Integer = bounds.bottom - bounds.top
            Dim wp As New WINDOWPLACEMENT()
            GetWindowPlacement(CType(hWnd, IntPtr), wp)
            Dim x As Integer
            Dim y As Integer
     
            If wp.showCmd = CInt(Window_State.SW_SHOWMAXIMIZED) Then
                x = wp.ptMaxPosition.X
                y = wp.ptMaxPosition.Y
            Else
                x = wp.rcNormalPosition.X
                y = wp.rcNormalPosition.Y
            End If
     
            If (x + width) > Screen.PrimaryScreen.WorkingArea.Width Then
                width = width - ((x + width) - Screen.PrimaryScreen.WorkingArea.Width)
            End If
     
            If (y + height) > Screen.PrimaryScreen.WorkingArea.Height Then
                height = height - ((y + height) - Screen.PrimaryScreen.WorkingArea.Height)
            End If
     
            Dim ScreenBounds As New Rectangle(x, y, width, height)
            Dim Screenshot As New Bitmap(ScreenBounds.Width, ScreenBounds.Height, PixelFormat.Format32bppArgb)
            Dim ScreenGraph As Graphics = Graphics.FromImage(Screenshot)
            ScreenGraph.CopyFromScreen(ScreenBounds.X, ScreenBounds.Y, 0, 0, ScreenBounds.Size, CopyPixelOperation.SourceCopy)
            Return Screenshot
        End Function
    A+

  7. #7
    Expert confirmé
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Points : 4 005
    Points
    4 005
    Billets dans le blog
    7
    Par défaut
    Citation Envoyé par alexworks Voir le message
    Merci beaucoup

    l'imprim écran fonctionne a merveille
    mais le résultat ne fais pas très propre.

    je vais chercher du coté des fonction API que je ne connais pas du tout.
    loool..... avec les fonctions API ca rendra le même résultat car a final tu dois faire une capture.....

    Il faut que tu choisisses un autre format d'image non compressé tout simplement donc dans la fonction de capture (dans toute la fonction) il ne faut travailler qu'avec la classe image !
    Au final tu enregistres avec un format autre que : png, jpg et bmp (qui sont par défaut des types compressés) ou alors il te faudra choisir le jpeg avec la gestion d'un encoder pour définir la qualité à 100%.

    A+

  8. #8
    Futur Membre du Club
    Homme Profil pro
    Technicien maintenance
    Inscrit en
    Septembre 2013
    Messages
    13
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Technicien maintenance
    Secteur : Bâtiment

    Informations forums :
    Inscription : Septembre 2013
    Messages : 13
    Points : 9
    Points
    9
    Par défaut
    Voila j'ai mis ce code et sa marche impec

    Merci pour votre aide

    Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox2.Click


    CaptureScreen()
    PrintDocument1.Print()

    End Sub



    Private Declare Function BitBlt Lib "gdi32.dll" Alias "BitBlt" (ByVal _
    hdcDest As IntPtr, ByVal nXDest As Integer, ByVal nYDest As _
    Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal _
    hdcSrc As IntPtr, ByVal nXSrc As Integer, ByVal nYSrc As Integer, _
    ByVal dwRop As System.Int32) As Long
    Dim memoryImage As Bitmap
    Private Sub CaptureScreen()
    Dim mygraphics As Graphics = Me.CreateGraphics()
    Dim s As Size = Me.Size
    memoryImage = New Bitmap(s.Width, s.Height, mygraphics)
    Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
    Dim dc1 As IntPtr = mygraphics.GetHdc
    Dim dc2 As IntPtr = memoryGraphics.GetHdc
    BitBlt(dc2, 0, 0, Me.ClientRectangle.Width, _
    Me.ClientRectangle.Height, dc1, 0, 0, 13369376)
    mygraphics.ReleaseHdc(dc1)
    memoryGraphics.ReleaseHdc(dc2)
    End Sub
    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, _
    ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
    PrintDocument1.PrintPage
    e.Graphics.DrawImage(memoryImage, 0, 0)
    End Sub




  9. #9
    Membre expérimenté Avatar de callo
    Homme Profil pro
    Administrateur systèmes et réseaux
    Inscrit en
    Février 2004
    Messages
    887
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Togo

    Informations professionnelles :
    Activité : Administrateur systèmes et réseaux
    Secteur : Service public

    Informations forums :
    Inscription : Février 2004
    Messages : 887
    Points : 1 699
    Points
    1 699
    Par défaut
    Bonjour alexworks,
    Pour faciliter la lecture du code, prière utiliser la balise (bouton #) prévu à cet effet.
    N'oubliez pas le tag et

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Changer la mise en forme d'un form pendant un mailto
    Par Iron-Avenger dans le forum Général JavaScript
    Réponses: 8
    Dernier message: 03/12/2013, 19h03
  2. Impression de colonnes mises en forme (VB2005)
    Par Papy33 dans le forum VB.NET
    Réponses: 2
    Dernier message: 29/10/2007, 14h15
  3. mise en forme à l'impression
    Par DeFCrew dans le forum IHM
    Réponses: 8
    Dernier message: 16/10/2007, 15h56
  4. Mise en forme / mise en page
    Par alokkin dans le forum Jasper
    Réponses: 0
    Dernier message: 06/08/2007, 14h34

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