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 :

Imprimer en incliné


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2010
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2010
    Messages : 100
    Par défaut Imprimer en incliné
    Bonjour à tous,

    Je cherche le moyen d'imprimer en incliné selon un angle donné. L'idée est de faire un filigrane (genre "copy" sur une facture).
    J'utilise l'objet Graphics pour l'impression. J'ai bien cherché sur Google mais je ne parviens pas à mes fins.

    Voici une partie de mon code:
    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
    Private Sub GridToPrint_PrintPage(ByVal sender As System.Object, ByVal e As PrintPageEventArgs) Handles GridToPrint.PrintPage
            e.Graphics.PageUnit = GraphicsUnit.Millimeter
            'e.Graphics.FillRectangle(Brushes.Gray, 0, 0, 200, 200)
            PrintString(e, "Test Print", New Font("Arial", 25, FontStyle.Bold), Brushes.Black, 5, 10, 0)
            PrintString(e, InvoiceNumber, New Font("Arial", 18, FontStyle.Bold), Brushes.Black, 5, 25, 0)
            PrintString(e, Format(InvoiceDate, "dd/MM/yyyy"), New Font("Arial", 18, FontStyle.Bold), Brushes.Black, 5, 40, 0)
            PrintString(e, "Facture client", New Font("Arial", 25, FontStyle.Bold), Brushes.Black, 5, 60, 0)
            Dim bmp As Bitmap = New Bitmap(My.Resources.Resource1.Logo_Infotec___Copie)
            Dim imageWidth As Integer, imageHeight As Integer
            imageWidth = CInt(bmp.Width / 16)
            imageHeight = CInt(bmp.Height / 16)
            e.Graphics.DrawImage(bmp, 5, 150, imageWidth, imageHeight)
            e.HasMorePages = False
            'DrawAngledText(e.Graphics, New Font("Arial", 20, FontStyle.Bold), Brushes.Black, "COPY", 5, 70, 20, 5)
            'CurveText(e.Graphics, New Font("Arial", 20, FontStyle.Bold), Brushes.Black, "COPY", 5, 70, 20)
        End Sub
     
        Public Sub DrawAngledText(ByVal gr As Graphics, ByVal _
            the_font As Font, ByVal the_brush As Brush, ByVal txt _
            As String, ByVal x As Integer, ByVal y As Integer, _
            ByVal angle_degrees As Single, ByVal y_scale As Single)
            ' Translate the point to the origin.
            gr.TranslateTransform(-x, -y, _
                Drawing2D.MatrixOrder.Append)
     
            ' Rotate through the angle.
            gr.RotateTransform(angle_degrees, _
                Drawing2D.MatrixOrder.Append)
     
            ' Scale vertically by a factor of Tan(angle).
            Dim angle_radians As Double = angle_degrees * Math.PI / 180
            gr.ScaleTransform(1, y_scale, _
                Drawing2D.MatrixOrder.Append)
     
            ' Find the inverse angle and rotate back.
            angle_radians = Math.Atan(y_scale * Math.Tan(angle_radians))
            angle_degrees = CSng(angle_radians * 180 / Math.PI)
            gr.RotateTransform(-angle_degrees, _
                Drawing2D.MatrixOrder.Append)
     
            ' Translate the origin back to the point.
            gr.TranslateTransform(x, y, _
                Drawing2D.MatrixOrder.Append)
     
            ' Draw the text.
            gr.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAliasGridFit
            gr.DrawString(txt, the_font, the_brush, x, y)
        End Sub
     
        Private Sub PrintString(ByVal e As PrintPageEventArgs, ByVal Value As String, ByVal PrintFont As Font, ByVal ForeColor As Brush, ByVal X As Single, ByVal Y As Single, ByVal Align As Byte)
            e.Graphics.PageUnit = GraphicsUnit.Millimeter
            Dim TextAlign As New StringFormat
            Select Case Align
                Case 0
                    TextAlign.Alignment = StringAlignment.Near
                Case 1
                    TextAlign.Alignment = StringAlignment.Far
                Case 2
                    TextAlign.Alignment = StringAlignment.Center
            End Select
            e.Graphics.DrawString(Value, PrintFont, ForeColor, X, Y, TextAlign)
        End Sub
    Merci de votre aide,

  2. #2
    Membre chevronné
    Profil pro
    Inscrit en
    Février 2010
    Messages
    291
    Détails du profil
    Informations personnelles :
    Âge : 56
    Localisation : France

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

    La magie de GDI+ ....

    La solution est soi de passer par les API32 ou de contourner la chose (mais dans le fond cela revient au même) en créant un objet Logfont GDI et en utilisant la méthode FromLogFont de l'objet system.drawing.font

    Je vous mets ci-dessous la structure LogFont dans sa définition VB6 a adapter pour .NET

    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
    Private Type LOGFONT
            lfHeight As Long
            lfWidth As Long
            lfEscapement As Long
            lfOrientation As Long
            lfWeight As Long
            lfItalic As Byte
            lfUnderline As Byte
            lfStrikeOut As Byte
            lfCharSet As Byte
            lfOutPrecision As Byte
            lfClipPrecision As Byte
            lfQuality As Byte
            lfPitchAndFamily As Byte
            lfFaceName(LF_FACESIZE) As Byte
    End Type

  3. #3
    Membre éprouvé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2010
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2010
    Messages : 100
    Par défaut
    Merci de cette piste, auriez-vous un exemple que ce soit VB6 ou autre d'utilisation de logfont?
    J'avoue ne pas bien avoir compris comment je peux utiliser ce logfont.

    Cordialement,

  4. #4
    Membre chevronné
    Profil pro
    Inscrit en
    Février 2010
    Messages
    291
    Détails du profil
    Informations personnelles :
    Âge : 56
    Localisation : France

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

    Heu ... c'est pas trivial, ci-dessous la fonction WriteText de ma composition, écrite en VB6, elle fait partie d'une classe donc vous aurez des références à des fonctions internes à cette classe, en gros ces fonctions permettent de mapper un DC en mode métrique et de dessiner en coordonnées réelles à l'aide des API, ce pour que vous compreniez l'essentiel. Attachez vous aux fonctions commentées, qui concernent le texte a proprement parler.

    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
    Public Function writetext(MyText As String, x As Double, y As Double, Taille As Double, align As Long, angle As Double, Affiche As Boolean, Optional Color& = 0, Optional weight As Long = 0, Optional underline As Byte = 0)
    Dim lf As LOGFONT
    Dim oldfont&
    Dim alignorigin&
    Dim newfont&
    Dim Oldcolor&
    Dim Usecolor&
    Dim di&
    Dim pointattache As POINTAPI
    Dim pointlog As POINTAPI
    Dim p As POINTGEO
    Dim SI As Size
     
    setmetrique
    p.x = x
    p.y = y
    pointattache = RtoL(p)
    p.x = x + Taille
    p.y = y + Taille
    pointlog = RtoL(p)
     
    'Police logique courante par selection police systeme
    oldfont& = SelectObject(mhdc, GetStockObject(0))
    di& = GetObjectAPI(oldfont&, Len(lf), lf)
     
    'rétablit la police de départ
    di& = SelectObject(mhdc, oldfont&)
     
     
    lf.lfHeight = pointlog.y - pointattache.y
    lf.lfEscapement = -1 * Round(angle * 10, 0)
     
    If weight <> 0 Then
    lf.lfWeight = weight
    End If
     
    If underline = 1 Then
    lf.lfUnderline = 1
    End If
    'création d'une fonte à partir de logfont
    newfont& = CreateFontIndirect(lf)
    oldfont& = SelectObject(mhdc, newfont&)
    di& = GetTextExtentPoint32(mhdc, MyText, Len(MyText), SI)
    mrectText.Bottom = pointattache.y
    mrectText.Top = mrectText.Bottom + SI.Cy
    'stocke l'alignement d'origine
    'calcul l'ancrex en fonction de l'alignement
    'pas de y car pas d'alignement verticale Bottom obligatoire
     
    Select Case align
    Case 0
    alignorigin& = SetTextAlign(mhdc, TA_LEFT Or TA_BOTTOM Or TA_UPDATECP)
    mrectText.Left = pointattache.x
    Case 1
    alignorigin& = SetTextAlign(mhdc, TA_RIGHT Or TA_BOTTOM Or TA_UPDATECP)
    mrectText.Left = pointattache.x - SI.Cx
    Case 2
    alignorigin& = SetTextAlign(mhdc, TA_CENTER Or TA_BOTTOM Or TA_UPDATECP)
    mrectText.Left = pointattache.x - SI.Cx / 2
    End Select
     
     
    mrectText.Right = mrectText.Left + SI.Cx
    ConvertEspaceText
     
    If Affiche Then
    Oldcolor& = GetTextColor(mhdc)
    Usecolor& = Color&
    dummy& = SetTextColor(mhdc, Usecolor)
    di& = MoveToEx&(mhdc, pointattache.x, pointattache.y, pointlog)
    di& = TextOut(mhdc, 0, 0, MyText, Len(MyText))
    Usecolor& = SetTextColor(mhdc, Oldcolor)
    End If
     
    di& = SetTextAlign(mhdc, alignorigin&)
    di& = SelectObject(mhdc, oldfont&)
     
    DeleteObject (newfont&)
     
    exitmetrique
    End Function

  5. #5
    Expert éminent Avatar de Pol63
    Homme Profil pro
    .NET / SQL SERVER
    Inscrit en
    Avril 2007
    Messages
    14 197
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : .NET / SQL SERVER

    Informations forums :
    Inscription : Avril 2007
    Messages : 14 197
    Par défaut
    dessiner le texte sur un graphics rotationné et l'appliquer sur l'autre
    enfin un truc dans le genre

    voir dans system.drawing ou system.drawing.drawing2d, il y a ce qu'il faut pour appliquer des transformations, dont les rotations
    Cours complets, tutos et autres FAQ ici : C# - VB.NET

  6. #6
    Membre éprouvé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Décembre 2010
    Messages
    100
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 41
    Localisation : Belgique

    Informations professionnelles :
    Activité : Développeur .NET
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Décembre 2010
    Messages : 100
    Par défaut
    Merci de vos réponses, je vais me débrouillé avec vos pistes, j'ai déjà trouvé un article intéressant:
    http://www.functionx.com/win32/Lesson14.htm

    Cordialement,

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

Discussions similaires

  1. Imprimer un label incliné, possible ?
    Par Droïde Système7 dans le forum Débuter
    Réponses: 7
    Dernier message: 31/05/2009, 01h00
  2. Comment imprimer des tabulations ?
    Par Invité dans le forum C++Builder
    Réponses: 2
    Dernier message: 27/11/2002, 11h30
  3. [VB6][Flexgrid] Imprimer
    Par tiboleo dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 24/10/2002, 14h14
  4. [VB6] [Outlook] Imprimer un mail en VB
    Par der dans le forum VB 6 et antérieur
    Réponses: 4
    Dernier message: 12/09/2002, 14h20
  5. Comment imprimer le contenu d'un TStringGrid
    Par scorpiwolf dans le forum C++Builder
    Réponses: 2
    Dernier message: 19/06/2002, 15h41

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