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

C# Discussion :

Imprimer un fichier en C#


Sujet :

C#

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre actif
    Homme Profil pro
    Jean ZAY - Jarny
    Inscrit en
    Juin 2011
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Jean ZAY - Jarny
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 25
    Par défaut Imprimer un fichier en C#
    Bonjour,

    J'ai un petit soucis lors que j'essaye d'imprimer un fichier, j'essaye d'utiliser la classe PrintDocument.

    Pouvez vous m’éclairez sur le code à réaliser?

    Cordialement Jérémy

  2. #2
    Membre averti
    Inscrit en
    Avril 2009
    Messages
    14
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 14
    Par défaut
    Bonjour,

    As tu regardé ici ?
    http://msdn.microsoft.com/fr-fr/libr...tdocument.aspx

    C'est pas trop mal comme code

  3. #3
    Membre actif
    Homme Profil pro
    Jean ZAY - Jarny
    Inscrit en
    Juin 2011
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Jean ZAY - Jarny
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 25
    Par défaut
    Oui j'ai regarde j'ai tester et ça me ressort des erreurs ...

  4. #4
    Membre averti
    Inscrit en
    Avril 2009
    Messages
    14
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 14
    Par défaut
    Quels sont les erreurs ? Quel est le bout de code qui t'embêtes ?

    Comme ça, je peux pas faire mieux que msdn

  5. #5
    Membre actif
    Homme Profil pro
    Jean ZAY - Jarny
    Inscrit en
    Juin 2011
    Messages
    25
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Jean ZAY - Jarny
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2011
    Messages : 25
    Par défaut
    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
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.IO;
    using System.Drawing.Printing;
     
    namespace taxatel
    {
        public partial class SuitePayer : Form
        {
            private Font printFont;
            private StreamReader streamToPrint;
            public string Prenom, Nom;
            public static string Ancien;
            public static string Nouveau;
            string TotalPrix;
     
            Email frmEmail = new Email();
            public SuitePayer()
            {
                InitializeComponent();
            }
     
            private void Annuler_Click(object sender, EventArgs e)
            {
                this.Hide();
            }
     
            private void Email_Click(object sender, EventArgs e)
            {
                Ancien = "C:\\Projet\\Facture_detail.txt";
                Nouveau = "C:\\Projet\\" + Nom + "_" + Prenom + ".txt";
                File.Move(Ancien, Nouveau);
                frmEmail.Show();
                this.Hide();
     
            }
     
            private void SuitePayer_Load(object sender, EventArgs e)
            {
                TotalPrix = Convert.ToString(Payer.TotalCost);
                NumPoste.Text = Payer.NumPoste;
                NbrComunication.Text = Payer.compteur;
                Cout.Text = TotalPrix;
                PrenomSuitePayer.Text = "";
                NomSuitePayer.Text = "";
            }
     
            private void PrenomSuitePayer_TextChanged(object sender, EventArgs e)
            {
                Prenom = PrenomSuitePayer.Text;
            }
     
            private void NomSuitePayer_TextChanged(object sender, EventArgs e)
            {
                Nom = NomSuitePayer.Text;
            }
     
            private void Imprimer_Click(object sender, EventArgs e)
            {
                Ancien = "C:\\Projet\\Facture_detail.txt";
                Nouveau = "C:\\Projet\\" + Nom + "_" + Prenom + ".txt";
                try
                {
                    streamToPrint = new StreamReader (Nouveau);
                    try
                    {
                        printFont = new Font("Arial", 10);
                        PrintDocument pd = new PrintDocument();
                        pd.PrintPage += new PrintPageEventHandler (this.pd_PrintPage);
                        pd.Print();
                    }
                    finally
                    {
                        streamToPrint.Close();
                    }
                }
                catch (Exception ex)
                {
                MessageBox.Show(ex.Message);
                }
            }
            private void pd_PrintPage(object sender, PrintPageEventArgs ev)
            {
                float linesPerPage = 0;
                float yPos = 0;
                int count = 0;
                float leftMargin = ev.MarginBounds.Left;
                float topMargin = ev.MarginBounds.Top;
                string line = null;
     
                // Calculate the number of lines per page.
                linesPerPage = ev.MarginBounds.Height /
                   printFont.GetHeight(ev.Graphics);
     
                // Print each line of the file.
                while (count < linesPerPage &&
                   ((line = streamToPrint.ReadLine()) != null))
                {
                    yPos = topMargin + (count *
                       printFont.GetHeight(ev.Graphics));
                    ev.Graphics.DrawString(line, printFont, Brushes.Black,
                       leftMargin, yPos, new StringFormat());
                    count++;
                }
     
                // If more lines exist, print another page.
                if (line != null)
                    ev.HasMorePages = true;
                else
                    ev.HasMorePages = false;
            }
     
     
            // The Windows Forms Designer requires the following procedure.
            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.Imprimer = new System.Windows.Forms.Button();
     
                this.ClientSize = new System.Drawing.Size(504, 381);
                this.Text = "Print Example";
     
                Imprimer.ImageAlign =
                   System.Drawing.ContentAlignment.MiddleLeft;
                Imprimer.Location = new System.Drawing.Point(32, 110);
                Imprimer.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
                Imprimer.TabIndex = 0;
                Imprimer.Text = "Print the file.";
                Imprimer.Size = new System.Drawing.Size(136, 40);
                Imprimer.Click += new System.EventHandler(Imprimer_Click);
     
                this.Controls.Add(Imprimer);
            }
     
        }
    }

    C 'est à la ligne :


    et l'erreur c'est :
    Le type 'taxatel.SuitePayer' définit déjà un membre appelé 'InitializeComponent' avec les mêmes types de paramètres

  6. #6
    Membre averti
    Inscrit en
    Avril 2009
    Messages
    14
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 14
    Par défaut
    Si tu as utilisé une windows Form généré automatiquement et repris le code de msdn, tu as peut être dans le designer de ta classe SuitePlayer la fonction InitializeComponent() déjà écrite.

    Si c'est le cas, il ne devra t'en rester qu'une !

Discussions similaires

  1. Imprimer automatiquement fichiers de plusieurs formats
    Par lutin511 dans le forum Windows
    Réponses: 5
    Dernier message: 07/12/2005, 18h38
  2. Comment imprimer un fichier text existant?
    Par AODRENN dans le forum Langage
    Réponses: 2
    Dernier message: 12/09/2005, 17h26
  3. Imprimer un fichier EXCEL
    Par bianconeri dans le forum C++Builder
    Réponses: 3
    Dernier message: 16/03/2005, 11h15
  4. Imprimer un fichier texte avec un script vbs
    Par Persons dans le forum Windows
    Réponses: 3
    Dernier message: 23/12/2004, 16h47
  5. [Imprimer] Imprimer un fichier avec Java
    Par gwendo dans le forum API standards et tierces
    Réponses: 2
    Dernier message: 13/11/2004, 20h23

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