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 sur zebra (avec les drivers)


Sujet :

VB.NET

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 362
    Points : 64
    Points
    64
    Par défaut impression sur zebra (avec les drivers)
    bonjour,

    J'ai un tit bout de code qui me sert de visualisation de ce qui va etre imprimé sur une Zebra TLP2844
    C'est une form contenant:
    * une picturebox (picContainer) dans laquel on a une visalisation de l'etiquette a imprimé (picZLPview)
    * un zoom + ou - (cmdAction2 et cmdAction3)
    * une textbox (txtetiquette0) pour la largeur de l'etiquette
    * une textbox (txtetiquette1) pour la hauteur de l'etiquette

    Voici le code de la 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
    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
     
    Option Explicit On
    Imports System.Drawing.Printing
    Public Class Form1
     
        Public sngZPLZoom As Double
     
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            picZPLView.Image = Nothing
            sngZPLZoom = 6
            picZPLView.Width = (Convert.ToDouble(txtetiquette0.Text) * sngZPLZoom) + &H2
            picZPLView.Height = (Convert.ToDouble(txtetiquette1.Text) * sngZPLZoom) + &H6
            Call Form_Resize()
        End Sub
     
        Private Sub Form_Resize()
            Dim lngX As Long
            Dim lngY As Long
            Dim lngI As Long
            Dim lngJ As Long
            Dim sngI As Single
            Dim x, y As Single
     
            If Me.WindowState <> 1 Then
                lngX = Me.Width
                lngY = Me.Height
                picContainer.Width = lngX - 35
                picContainer.Height = lngY - 135
     
                Dim fond As Bitmap = New Bitmap(picContainer.Width, picContainer.Height)
                picContainer.Image = fond
                Dim ft As Font = New Font("arial", 10, FontStyle.Bold)
                Dim g As Graphics = Graphics.FromImage(picContainer.Image)
     
     
                picZPLView.Left = picContainer.Left + ((picContainer.Width - picZPLView.Width) / 2)
                picZPLView.Top = picContainer.Top + ((picContainer.Height - picZPLView.Height) / 2)
                picContainer.Image = Nothing
     
                g.DrawLine(Pens.DarkSeaGreen, (picZPLView.Left - picContainer.Left), 0, (picZPLView.Left - picContainer.Left), picContainer.Height)
                g.DrawLine(Pens.DarkSeaGreen, (picZPLView.Left + picZPLView.Width - picContainer.Left) - 1, 0, (picZPLView.Left + picZPLView.Width - picContainer.Left) - 1, picContainer.Height)
                g.DrawLine(Pens.DarkSeaGreen, 0, (picZPLView.Top - picContainer.Top), picContainer.Width, (picZPLView.Top - picContainer.Top))
                g.DrawLine(Pens.DarkSeaGreen, 0, (picZPLView.Top + picZPLView.Height - picContainer.Top) - 1, picContainer.Width, (picZPLView.Top + picZPLView.Height - picContainer.Top) - 1)
     
                lngI = 0
                For sngI = ((picZPLView.Width) / txtetiquette0.Text) To picZPLView.Width - 1 Step ((picZPLView.Width) / txtetiquette0.Text)
                    lngI = lngI + 1
                    If lngI < 10 Then
                        If lngI <> 5 Then
                            g.DrawLine(Pens.Blue, picZPLView.Left + sngI - picContainer.Left, picZPLView.Top - 4 - picContainer.Top, picZPLView.Left + sngI - picContainer.Left, picZPLView.Top - picContainer.Top)
                            g.DrawLine(Pens.Blue, picZPLView.Left + sngI - picContainer.Left, picZPLView.Top + picZPLView.Height - picContainer.Top, picZPLView.Left + sngI - picContainer.Left, (picZPLView.Top + picZPLView.Height) + 4 - picContainer.Top)
                        Else
                            g.DrawLine(Pens.Blue, picZPLView.Left + sngI - picContainer.Left, picZPLView.Top - 8 - picContainer.Top, picZPLView.Left + sngI - picContainer.Left, picZPLView.Top - picContainer.Top)
                            g.DrawLine(Pens.Blue, picZPLView.Left + sngI - picContainer.Left, picZPLView.Top + picZPLView.Height - picContainer.Top, picZPLView.Left + sngI - picContainer.Left, (picZPLView.Top + picZPLView.Height) + 8 - picContainer.Top)
                        End If
                    Else
                        lngI = 0
                        lngJ = lngJ + 10
                        g.DrawLine(Pens.Blue, picZPLView.Left + sngI - picContainer.Left, picZPLView.Top - 18 - picContainer.Top, picZPLView.Left + sngI - picContainer.Left, picZPLView.Top - picContainer.Top)
                        g.DrawLine(Pens.Blue, picZPLView.Left + sngI - picContainer.Left, picZPLView.Top + picZPLView.Height - picContainer.Top, picZPLView.Left + sngI - picContainer.Left, (picZPLView.Top + picZPLView.Height) + 18 - picContainer.Top)
                        x = ((picZPLView.Left + sngI) - ((g.MeasureString(lngJ, ft).Width) / 2)) - 4 - picContainer.Left
                        y = picZPLView.Top - 32 - picContainer.Top
                        g.DrawString(lngJ, ft, New SolidBrush(Color.White), x, y)
                        x = ((picZPLView.Left + sngI) - ((g.MeasureString(lngJ, ft).Width) / 2)) - 4 - picContainer.Left
                        y = picZPLView.Top + picZPLView.Height + &H11 - picContainer.Top
                        g.DrawString(lngJ, ft, New SolidBrush(Color.White), x, y)
                    End If
                Next sngI
                lngI = 0
                lngJ = 0
                For sngI = ((picZPLView.Height) / txtetiquette1.Text) To picZPLView.Height - &H1 Step ((picZPLView.Height) / txtetiquette1.Text)
                    lngI = lngI + 1
                    If lngI < 10 Then
                        If lngI <> 5 Then
                            g.DrawLine(Pens.Blue, picZPLView.Left - 4 - picContainer.Left, picZPLView.Top + sngI - picContainer.Top, picZPLView.Left - picContainer.Left, picZPLView.Top + sngI - picContainer.Top)
                            g.DrawLine(Pens.Blue, picZPLView.Left + picZPLView.Width - picContainer.Left, picZPLView.Top + sngI - picContainer.Top, (picZPLView.Left + picZPLView.Width) + &H4 - picContainer.Left, picZPLView.Top + sngI - picContainer.Top)
                        Else
                            g.DrawLine(Pens.Blue, picZPLView.Left - &H8 - picContainer.Left, picZPLView.Top + sngI - picContainer.Top, picZPLView.Left - picContainer.Left, picZPLView.Top + sngI - picContainer.Top)
                            g.DrawLine(Pens.Blue, picZPLView.Left + picZPLView.Width - picContainer.Left, picZPLView.Top + sngI - picContainer.Top, (picZPLView.Left + picZPLView.Width) + &H8 - picContainer.Left, picZPLView.Top + sngI - picContainer.Top)
                        End If
                    Else
                        lngI = &H0
                        lngJ = lngJ + 10
                        g.DrawLine(Pens.Blue, picZPLView.Left - 18 - picContainer.Left, picZPLView.Top + sngI - picContainer.Top, picZPLView.Left - picContainer.Left, picZPLView.Top + sngI - picContainer.Top)
                        g.DrawLine(Pens.Blue, picZPLView.Left + picZPLView.Width - picContainer.Left, picZPLView.Top + sngI - picContainer.Top, (picZPLView.Left + picZPLView.Width) + 18 - picContainer.Left, picZPLView.Top + sngI - picContainer.Top)
                        x = picZPLView.Left - (g.MeasureString(lngJ, ft).Width) + &H1A - picContainer.Left - 42
                        y = ((picZPLView.Top + sngI) - ((g.MeasureString(lngJ, ft).Width)) / &H2) - picContainer.Top
                        g.DrawString(lngJ, ft, New SolidBrush(Color.White), x, y)
                        x = (picZPLView.Left + picZPLView.Width) + 18 - picContainer.Left
                        y = ((picZPLView.Top + sngI) - ((g.MeasureString(lngJ, ft).Width)) / &H2) - picContainer.Top
                        g.DrawString(lngJ, ft, New SolidBrush(Color.White), x, y)
     
                    End If
                Next
                picContainer.Image = fond
            End If
            Call drawZPL()
        End Sub
     
        Private Sub cmdAction1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAction1.Click
            sngZPLZoom = 6.2
            picZPLView.Image = Nothing
            picZPLView.Width = (txtetiquette0.Text * sngZPLZoom) + &H2
            picZPLView.Height = (txtetiquette1.Text * sngZPLZoom) + &H6
            Call Form_Resize()
        End Sub
     
        Private Sub cmdAction2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAction2.Click
            If sngZPLZoom < 10 Then
                sngZPLZoom = sngZPLZoom + 0.2
                picZPLView.Image = Nothing
                picZPLView.Width = (txtetiquette0.Text * sngZPLZoom) + &H2
                picZPLView.Height = (txtetiquette1.Text * sngZPLZoom) + &H6
                Call Form_Resize()
            End If
        End Sub
     
        Private Sub cmdAction3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAction3.Click
            If sngZPLZoom > 2.4 Then
                sngZPLZoom = sngZPLZoom - 0.2
                picZPLView.Image = Nothing
                picZPLView.Width = (txtetiquette0.Text * sngZPLZoom) + &H2
                picZPLView.Height = (txtetiquette1.Text * sngZPLZoom) + &H6
                Call Form_Resize()
            End If
        End Sub
     
        Private Sub txtetiquette0_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtetiquette0.LostFocus
            If txtetiquette0.Text <> vbNullString Then
                If txtetiquette0.Text > 110 Or txtetiquette0.Text < 0 Then
                    txtetiquette0.Text = 76
                    Call initializ()
                Else
                    Call initializ()
                End If
            Else
                txtetiquette0.Text = 76
                Call initializ()
            End If
        End Sub
     
        Private Sub txtetiquette1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtetiquette1.LostFocus
            If txtetiquette1.Text <> vbNullString Then
                If txtetiquette1.Text > 110 Or txtetiquette1.Text < 0 Then
                    txtetiquette1.Text = 40
                    Call initializ()
                Else
                    Call initializ()
                End If
            Else
                txtetiquette1.Text = 40
                Call initializ()
            End If
        End Sub
     
        Private Sub initializ()
            picZPLView.Image = Nothing
            sngZPLZoom = 6
            picZPLView.Width = (Convert.ToDouble(txtetiquette0.Text) * sngZPLZoom) + &H2
            picZPLView.Height = (Convert.ToDouble(txtetiquette1.Text) * sngZPLZoom) + &H6
            Call Form_Resize()
        End Sub
     
        Private Sub ImprimerImage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
     
     
            ev.Graphics.DrawImageUnscaled(etiq, 0, 0, 76 * 8, 40 * 8)
     
        End Sub
     
     
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     
            AddHandler PrintDocument1.PrintPage, AddressOf Me.ImprimerImage
            PrintDocument1.Print()
     
        End Sub
    End Class
    Et voici le code qui est dans un module et qui me permet d'afficher du text sur l'etiquette:

    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
     
    Module Module1
        Public etiq As Bitmap = New Bitmap(Form1.picZPLView.Width, Form1.picZPLView.Height)
     
        Public Sub drawZPL()
     
            Form1.picZPLView.Image = etiq
            Dim taille As Single
            Dim angle As Single
            taille = 5 * Form1.sngZPLZoom
            angle = 90
            Dim ft2 As Font = New Font("arial", taille, FontStyle.Bold)
            Dim h As Graphics = Graphics.FromImage(Form1.picZPLView.Image)
            h.Clear(Color.White)
            Dim x, y As Single
            x = 10 * Form1.sngZPLZoom
            y = 10 * Form1.sngZPLZoom
            Dim myMatrix As New Drawing2D.Matrix
            myMatrix.RotateAt(angle, New Point(x, y))
            h.Transform = myMatrix
            h.DrawString("essai", ft2, Brushes.Black, x, y)
     
        End Sub
     
    End Module
    Jusque la tout va bien car, le text s'affiche sur la visualisation de l'etiquette et le system de zoom est opérationnel.

    Mon probleme vient lorsque je souhaite imprimer la picturebox (picZLPview) qui contient la representation de mon etiquette... j'ai bien une impression qui sort de la Zebra mais elle est pas a l'echelle.

    Pourtant dans le drivers de l'imprimante j'ai bien stipulé que j'utilisé des etiquettes de 76mm (largeur) par 40mm (longueur)

    d'ou vient le soucis? qu'estce que qui cloche dans le code?

    ps: je suis pas un pro deu vb.net (je decouvre ce language)

    merci pour votre aide
    Fichiers attachés Fichiers attachés

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Mars 2006
    Messages
    362
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2006
    Messages : 362
    Points : 64
    Points
    64
    Par défaut
    personne pour aider un pauvre noobie?

Discussions similaires

  1. [débutant] faire un JAR avec les drivers JDBC
    Par korrigann dans le forum Eclipse Java
    Réponses: 6
    Dernier message: 29/11/2006, 16h46
  2. Connection a DB Oracle avec les drivers natif
    Par Psykotik dans le forum Interfaces de programmation
    Réponses: 3
    Dernier message: 07/09/2006, 11h30
  3. Problème avec les drivers officiels ATI sous debian
    Par b Oo dans le forum Matériel
    Réponses: 1
    Dernier message: 06/06/2006, 20h38
  4. [win98]Reboot intempestif avec les drivers nvidia
    Par Michaël dans le forum Windows 2000/Me/98/95
    Réponses: 5
    Dernier message: 29/10/2005, 22h06
  5. ENVOYER UN FICHER SUR LPTx sans les drivers
    Par AODRENN dans le forum Langage
    Réponses: 7
    Dernier message: 14/09/2005, 19h07

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