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 :

Probleme Impression en C#


Sujet :

Windows Forms

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Août 2008
    Messages : 10
    Points : 6
    Points
    6
    Par défaut Probleme Impression en C#
    Salut tout le monde,

    je développe une petite application qui permet de gérer les achats d'un client.
    j'utilise une List<Client> pour imprimer des information sur les client, tout vas bien juste que j'ai un champs dans ma Class Client qui contient Beaucoup de caracteres et a l'impression j'ai un dépassement de la marge sans retour a la linge (donc tout ne s'affiche pas ).

    je voulais savoir s'il y a une fonction ou une technique qui permet de gérer mon String et avoir un retour en ligne une fois quand atteint la marge.
    voici une aprtie de mon code que j'utilise pour l'impression
    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
      private void prDoc_PrintPage(object sender, PrintPageEventArgs e)
            {
                int height = 0;
     
                // Draw the title
                if (this._currentPrintPage == 1)
                {
                    this.PrintTitle(e.Graphics, e.MarginBounds);
                    height += 120;
     
     
                }
                // Draw the comments
                if (this._printAction == PrintAction.PrintToPreview && this._comment) this.PrintComment(e);
                // Create the printer
                PersonPrinter personPrint = new PersonPrinter(new Font("Arial", 12), e.Graphics);
                // Print each person
                for (int i = this._personCounter; i < this._persons.Count; i++)
                {
                    personPrint.Draw(++this._personCounter, this._persons[i], new Point(50, height));
                    height += 120;
                    // The page is full, go to the next one
                    if (height + 120 > e.MarginBounds.Height) break;
     
                }
     
                // Check if there is some elements to prints
                if (this._personCounter >= this._persons.Count) e.HasMorePages = false;
                else
                {
                    e.HasMorePages = true;
                    this._currentPrintPage++;
                    if (this._maxPage < this._currentPrintPage) this._maxPage = this._currentPrintPage;
                }
            }
     private class PersonPrinter
            {
                private Font _font = null;
                private Graphics _gfx = null;
                private Point _point = Point.Empty;
                private Brush _brush = Brushes.Black;
     
                /// -------------------------------------------------------------------------
                /// <summary>
                /// Create a new PersonPrinter object.
                /// </summary>
                /// <param name="font"> The font to use. </param>
                /// <param name="gfx"> The current graphic context. </param>
                /// -------------------------------------------------------------------------
                public PersonPrinter(Font font, Graphics gfx)
                {
                    this._font = font;
                    this._gfx = gfx;
                }
     
                /// -------------------------------------------------------------------------
                /// <summary>
                /// Draw a person.
                /// </summary>
                /// <param name="nb"> The person n°. </param>
                /// <param name="person"> The person. </param>
                /// <param name="start"> The starting location to draw. </param>
                /// -------------------------------------------------------------------------
                public void Draw(int nb, Client1.Client person, Point start)
                {
     
     
     
     
                    // New point reference
                    this._point = start;
                    this._brush = person.id == 0 ? Brushes.Red : Brushes.Black;
                    const char subChar = (char)7;
     
                    // Draw
                    this.DrawSub(string.Format("{0}* Nom: {1}", subChar, person.FirstName), 0);
     
                    this.DrawSub(string.Format("{0}* Prénom: {1}", subChar, person.LastName), 1);
                    this.DrawSub(string.Format("{0}  Tel: {1} ", subChar, person.tel), 2);
                    //this.DrawSub(string.Format("{0}  Description: {1} ", subChar, person.Description), 3);
                    this.DrawSub(string.Format("{0}  Description: {1} ", subChar,person.Description), 3);
                }
     
                /// -------------------------------------------------------------------------
                /// <summary>
                /// Draw a person.
                /// </summary>
                /// <param name="txt"> The text to draw. </param>
                /// <param name="lign"> The lign. </param>
                /// -------------------------------------------------------------------------
     
     
     
     
                private void DrawSub(string txt, int lign)
                {
     
     
     
                    int x = lign == 0 ? this._point.X : this._point.X + 0;
                    this._gfx.DrawString(txt, this._font, this._brush, x, this._point.Y + (lign * 35));
                }
            }
    Merci d'avance pour votre aide.

  2. #2
    Membre émérite
    Profil pro
    Mangeur de gauffre
    Inscrit en
    Octobre 2007
    Messages
    4 413
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Mangeur de gauffre

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4 413
    Points : 2 498
    Points
    2 498
    Par défaut
    Salut

    Je me suis fais une petite methode pour cela


    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
        // **********************************************************************
        /// <summary>
        /// 
        /// </summary>
        /// <param name="dum"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="Wi"></param>
        /// <param name="fnt"></param>
        /// <param name="br01"></param>
        /// <param name="g"></param>
        /// <returns></returns>
        public SizeF prBloc(string dum, float x, float y, int Wi, Font fnt, Brush br, Graphics g)
        {
          StringFormat tsf = new StringFormat();
          SizeF MesureChaine = g.MeasureString(dum, fnt, Wi, tsf);
          int nbh = (int)(MesureChaine.Width / Wi) + 1;
          int cX = (int)(x);
          RectangleF posText = new RectangleF(cX, y, Wi, MesureChaine.Height * nbh);
          tsf.Alignment = StringAlignment.Near;
          g.DrawString(dum, fnt, br, posText, tsf);
          MesureChaine.Height *= nbh;
          return MesureChaine;
        }
    « Ils ne savaient pas que c'était impossible, alors ils l'ont fait ». (Twain)

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Août 2008
    Messages : 10
    Points : 6
    Points
    6
    Par défaut
    Merci pour ta réponse,

    Mais je vois pas comment je peut utiliser ta methode dans mon code en haut,
    peut-tu me donner plus d'explication stp.


    Merci d'avance.

  4. #4
    Membre émérite
    Profil pro
    Mangeur de gauffre
    Inscrit en
    Octobre 2007
    Messages
    4 413
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations professionnelles :
    Activité : Mangeur de gauffre

    Informations forums :
    Inscription : Octobre 2007
    Messages : 4 413
    Points : 2 498
    Points
    2 498
    Par défaut
    J'ai ajouté qq commentaires

    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
       // **********************************************************************
        /// <summary>
        /// Imprime un texte a la position x,y et le decoupe eventuellement pour passe a la ligne
        /// Si on déborde wi
        /// </summary>
        /// <param name="dum">La chaine a imprimer</param>
        /// <param name="x">X supérieur gauche</param>
        /// <param name="y">Y supérieur gauche</param>
        /// <param name="Wi">Largeur permise pour l'impression</param>
        /// <param name="fnt">Font</param>
        /// <param name="br01">Brush</param>
        /// <param name="g">graphics</param>
        /// <returns></returns>
        public SizeF prBloc(string dum, float x, float y, int Wi, Font fnt, Brush br, Graphics g)
        {
          StringFormat tsf = new StringFormat();
          SizeF MesureChaine = g.MeasureString(dum, fnt, Wi, tsf);
          int nbh = (int)(MesureChaine.Width / Wi) + 1;
          int cX = (int)(x);
          RectangleF posText = new RectangleF(cX, y, Wi, MesureChaine.Height * nbh);
          tsf.Alignment = StringAlignment.Near;
          g.DrawString(dum, fnt, br, posText, tsf);
          MesureChaine.Height *= nbh;
          return MesureChaine;
        }
    « Ils ne savaient pas que c'était impossible, alors ils l'ont fait ». (Twain)

  5. #5
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2008
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Août 2008
    Messages : 10
    Points : 6
    Points
    6
    Par défaut
    Merci ca Marche Nikel

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

Discussions similaires

  1. [CSS] probleme impression
    Par fabricew59 dans le forum Mise en page CSS
    Réponses: 2
    Dernier message: 06/07/2006, 15h48
  2. [VB]Probleme impression texte
    Par molpor dans le forum VB 6 et antérieur
    Réponses: 21
    Dernier message: 03/04/2006, 13h10
  3. probleme impression page
    Par toome dans le forum Langage
    Réponses: 38
    Dernier message: 17/11/2005, 15h29
  4. [VB.NET] Probleme impression document word
    Par lord_kyshow dans le forum ASP.NET
    Réponses: 36
    Dernier message: 09/06/2005, 16h07
  5. [FLASH MX 2004] probleme impression
    Par dens63 dans le forum Flash
    Réponses: 6
    Dernier message: 30/04/2004, 14h29

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