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

Windows Forms Discussion :

[C#] Problème d'Impression


Sujet :

Windows Forms

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2005
    Messages : 10
    Par défaut [C#] Problème d'Impression
    Bonjour,

    J'ai reussi a faire un bouton pour imprimé ma form facture mais lorque je fais une impression ou si je fais un apercu avec impression, c'est une page blanche à la place de ce que contient ma form.

    Quelqu'un aurait il une idée ??

    Merci

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 43
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Par défaut
    Montre nous le code que tu utilises (tu passes bien par un PrintDocument et autre : )

  3. #3
    Membre habitué
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2005
    Messages : 10
    Par défaut
    oui enfin je donne mon code ce sera plus parlant

    j'ai mis sa pour pouvoir choisir l'imprimante que l'on veut utilisé pour imprimer
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    private void btn_imprimer_Click(object sender, EventArgs e)
    		{
    			PrintDialog printDialog1 = new PrintDialog();
    			printDialog1.Document = printDocument1;
    			DialogResult result = printDialog1.ShowDialog();
    			if (result == DialogResult.OK)
    			{
    				printDocument1.Print();
    			}
    		}
    Et cette partie aussi

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    		{
     
    e.Graphics.DrawString("Facture",new Font("Arial",80,FontStyle.Regular),Brushes.Black, 808, 728);
    		}

  4. #4
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627

  5. #5
    Membre habitué
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2005
    Messages : 10
    Par défaut


    Desolé neguib mais je ne comprends pas comment ce topic pourrait m'aider, j'ai bien sur essaillé de comprendre avant de te repondre.
    Mais pourrais tu juste me dire ce qui cloche dans mon code pour me mettre sur la voie, j'ai peut etre mal compris quelque chose sur la page que tu m'a donné.

    J'ai cherché sur le forum avant de posté mon probleme et je n'est rien trouvé de concluant, j'ai même essaillé de convertir le code suivant parce qu'apparement faut faire une capture d'image de la form pour pouvoir ensuite l'imprimé, seulement sa me dit qu'il y a une erreur et vu que j'ai jamais fais de VB

    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
     
    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
    Private Sub PrintButton_Click(ByVal sender As System.Object, ByVal e As _
       System.EventArgs) Handles PrintButton.Click
       CaptureScreen()
       PrintDocument1.Print()
    End Sub

  6. #6
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut
    Citation Envoyé par ShinS16
    seulement sa me dit qu'il y a une erreur ...
    Et je suis censé deviné laquelle :
    Convertisseur VBNet>CSharp

  7. #7
    Membre habitué
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2005
    Messages : 10
    Par défaut
    Voila ce que sa me dit :

    Erreur lors de l'analyse du texte/fichier
    -- line 1 col 9: invalid NonModuleDeclaration

  8. #8
    Expert confirmé
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 65
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Par défaut
    La traduction en C# du code que tu as donné dans le convertisseur dont je t'ai donné le lien

    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
     
    public class truc
    {
        [System.Runtime.InteropServices.DllImport("gdi32.dll", EntryPoint="BitBlt")]
        private static extern long BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, System.Int32 dwRop);
        Bitmap memoryImage;
     
        private void CaptureScreen()
        {
            Graphics mygraphics = this.CreateGraphics();
            Size s = this.Size;
            memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
            Graphics memoryGraphics = Graphics.FromImage(memoryImage);
            IntPtr dc1 = mygraphics.GetHdc;
            IntPtr dc2 = memoryGraphics.GetHdc;
            BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
            mygraphics.ReleaseHdc(dc1);
            memoryGraphics.ReleaseHdc(dc2);
        }
     
        private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.Graphics.DrawImage(memoryImage, 0, 0);
        }
     
        private void PrintButton_Click(object sender, System.EventArgs e)
        {
            CaptureScreen();
            PrintDocument1.Print();
        }
    }

  9. #9
    Membre habitué
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2005
    Messages
    10
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2005
    Messages : 10
    Par défaut
    cool, sa marche merci beaucoup

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

Discussions similaires

  1. problème d'impression
    Par davedenice dans le forum AWT/Swing
    Réponses: 6
    Dernier message: 28/07/2005, 16h57
  2. [PowerBuilder] Problème d'impression datawindow composite
    Par jpdar dans le forum Powerbuilder
    Réponses: 2
    Dernier message: 17/05/2005, 13h33
  3. Réponses: 16
    Dernier message: 17/03/2005, 13h54
  4. [Rave] problème d'impression
    Par romstarr dans le forum Rave
    Réponses: 2
    Dernier message: 09/06/2004, 15h48
  5. Problème d'impression
    Par IngBen dans le forum C++Builder
    Réponses: 7
    Dernier message: 22/05/2002, 11h37

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