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

Développement Windows Discussion :

Rotation de texte en Draw


Sujet :

Développement Windows

  1. #1
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vosges (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 151
    Points : 89
    Points
    89
    Par défaut Rotation de texte en Draw
    Bonjour à tous,

    Voilà mon problème j'aimerais faire une rotation de texte à 90° voilà mon bout de code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    e.Graphics.RotateTransform(90);
                e.Graphics.DrawString(text1, font1, Brushes.Black, val13);
    Je n'arrive pas à comprendre comment marche la fonction RotateTransform. Je n'arrive pas à positionner mon texte sur ma page comme je le veux ...

    Merci de votre aide !!!

  2. #2
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour theuma

    L'origine des axes du system en gdi sont en topleft..
    La rotation par defaut a son origine à topleft du form(ou tout autre control)...
    Aberrant.........mais on s'habitue...

    voici un code qui montre comment s'y prendre avec les transformation(transform,rotate,scale et autre):

    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
     
    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.Drawing.Drawing2D;
    namespace WinCloningDGV
    {
        public partial class Form3 : Form
        {
            public Form3()
            {
                InitializeComponent();
     
     
     
     
            }
     
            //Par defaut l'origine des coord (0,0 ) est
            //le coin sup haut-gauche du form(topleft)
            // la rotation se fait par rapport à cette origine 
            // si tu fais une rotation >=90 ou <=-90 tu ne vois plus le texte
            //tout cela est decevant et ridicule ...
            string str1 =string.Empty ;
            private void button1_Click(object sender, EventArgs e)
            {
                str1 = "texte obeissant";
                this.Invalidate();
     
            }
     
            private void Form3_Paint(object sender, PaintEventArgs e)
            {
     
                //Pour remedier on utilise un matrix qui permet de 
                //specifier la position de l'axe de rotation 
                //du "TEXTE OBEISSANT"
     
                Font myFont = new Font("Arial", 16, FontStyle.Bold);
                PointF position = new PointF(300, 300);
     
     
                //1-position initiale san rotation
                e.Graphics.DrawString(str1, myFont, Brushes.DarkBlue , position);
     
                //2-rotation par rapport au point 300,300  de 90
     
                Matrix myMat = new Matrix();
                myMat.RotateAt(90, position);
                e.Graphics.Transform = myMat;
                e.Graphics.DrawString(str1, myFont, Brushes.Red, position);
     
     
                //3-tourne par rapport au centre de son rectangle englobant
                myMat.RotateAt(-90, position);
                e.Graphics.Transform = myMat;
     
                //string format mesure taille de son rectangle englobant
                SizeF strSize = e.Graphics.MeasureString(str1, myFont);
     
                PointF center = new PointF(position.X + strSize.Width / 2, position.Y + strSize.Height);
                myMat.RotateAt(45, center);
                e.Graphics.Transform = myMat;
     
                //dessine son rect
                e.Graphics.FillRectangle(Brushes.Yellow, position.X,position.Y,strSize.Width,strSize.Height);
                e.Graphics.DrawString(str1, myFont, Brushes.Red , position);
            }
     
     
     
     
        }
    }
    bon code........

  3. #3
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vosges (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 151
    Points : 89
    Points
    89
    Par défaut
    Merci beaucoup MABROUKI ...

    Si je comprend bien, on doit changer l'origine XY qui est de base en haut a gauche.
    Ensuite on fait notre rotation depuis se point ... Bizarre comme conception mais il suffit de faire avec ...

    Merci encore ...

  4. #4
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vosges (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 151
    Points : 89
    Points
    89
    Par défaut
    Peut ton dupliquer un dessin fait au préalable ? voilà j'ai fait un dessin en 128 par 82 et j'aimerais le dupliquer sur un autre dessin en 210 297 ....

  5. #5
    Nouveau Candidat au Club
    Femme Profil pro
    Inscrit en
    Août 2012
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Cameroun

    Informations forums :
    Inscription : Août 2012
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Rotation d'un texte vers le haut
    Bonsoir.
    SVP j'aimerai savoir comment est ce qu'on peut roter un texte vers le haut avec phpexcel.
    en faite au lieu d'écrire horizontalement, j'aimerai plutot écrire verticalement , mais je n'ai pas la commande PHEXCEL pour le faire et je ne trouve pas sur google.
    Merci , aidez moi SVP

  6. #6
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    bonjour

    Oui bien sur .

    Le 1er dessin(210x297) et le 2eme dessin( 128x82) ...

    Peut ton dupliquer un dessin fait au préalable ? voilà j'ai fait un dessin en 128 par 82 et j'aimerais le dupliquer sur un autre dessin en 210 297
    Quel unite emploie tu pour les dessins? c'est pas clair là....
    Sur quoi l'as-tu fait?

    bon code.......

  7. #7
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vosges (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 151
    Points : 89
    Points
    89
    Par défaut
    J'ai fais un dessin en 128 x 82 mm et j'aimerais le dupliqué 5 fois sur un 210 x 297 mm
    le but c'est d'imprimer une carte d'un format 128 x 82 directement imposé sur une feuille A4 pret à etre imprimer à l'imprimante ...

    donc si on prend notre feuille A4 en portrait on en met 3 à l'horizontal à gauche et 2 autres à la vertical à droite, d'ou la rotation ...

    Merci de ton aide

  8. #8
    Expert confirmé
    Inscrit en
    Avril 2008
    Messages
    2 564
    Détails du profil
    Informations personnelles :
    Âge : 64

    Informations forums :
    Inscription : Avril 2008
    Messages : 2 564
    Points : 4 441
    Points
    4 441
    Par défaut
    rebonjour

    Etant donne ce que tu veux faire et les transformations gdi sont cumulatives,il vaut mieux dessiner en memoire sur un bitmap...
    Le dessin du texte peut etre sur un bitmap en memoire et envoye à l'imprimante.....

    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
    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
     
     
    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.Drawing.Drawing2D;
    using System.Drawing.Printing;
    using System.Drawing.Text;
     
    // ajouter control :
    //- bouton
    //- printDocument
    //- printPreviewDialog
     
    namespace WinPrinting
    {
        public partial class Form1 : Form
        {
            //un bitmap pour dessiner le texte
            //en 2 passes (normal et rotated)
            private Bitmap bmp ; 
            private string monTexte = "Mathieu";
            //selon toi largeur =128 mm,hauteur =82 mm
            private Rectangle rect = new Rectangle(0, 0, 128, 82);
     
            public Form1()
            {
                InitializeComponent();
            }
     
            private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
            {
                Graphics g = e.Graphics;
                g.DrawImage(bmp,new Point(0,0));
                e.HasMorePages = false;
            }
     
            private void btnPrint_Click(object sender, EventArgs e)
            {
                //unites en millimetres pour l'image
                //page selon toi largeur =210 mm,hauteur =297 mm
     
                bmp = new Bitmap(2100, 2970); 
                DrawTextSurBmp();
     
                printPreviewDialog1.Document=  printDocument1;
                printPreviewDialog1.Show();
     
            }
            //dessin sur bitmap
            private void DrawTextSurBmp()
            {
                Graphics g = Graphics.FromImage(bmp);
                //unite de page en mm
                g.PageUnit = GraphicsUnit.Millimeter; 
     
                g.Clear(Color.Yellow);
     
                // 1ere passe (text normal)
                int counter = 0;
                while (counter < 3)
                {
                    DrawString(g, monTexte, rect);
     
                   //Incremente Coord Y de Height;
                    rect.Y += rect.Height;
                    counter++;
                }
     
                // 2e passe 
                // reset counter
                counter = 0;
                // reset Origin du rectangle
                rect.Location = new Point(0,0);
     
                Matrix myMatrix = new Matrix();
     
                //text deplace et  rotated
                //Move origin to (128 + 82, 0)
                myMatrix.Translate(128 + 82, 0);
                myMatrix.Rotate(90);
                g.Transform = myMatrix; 
                while (counter < 3)
                {
                    DrawString(g, monTexte, rect);
     
                    // Incremente Coord  X de  Width les axes 
                    //ayant subi une rotation
                    rect.X += rect.Width ;
                    counter++;
                }
     
            }
            //dessine le texte
            private void DrawString(Graphics g, string str, Rectangle rect)
            {
                Font myFont = new Font("Arial", 28, FontStyle.Bold);
                g.SmoothingMode = SmoothingMode.HighQuality;
                g.TextRenderingHint=TextRenderingHint.ClearTypeGridFit;
                StringFormat fmt = new StringFormat();
                fmt.Alignment = StringAlignment.Center;
                fmt.LineAlignment = StringAlignment.Center;
     
                g.DrawRectangle(Pens.Black, rect.X, rect.Y,
                   rect.Width, rect.Height);
                g.DrawString(str, myFont, Brushes.Red, rect, fmt);
     
            }
        }
    }
    bon code..........

  9. #9
    Membre régulier
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2011
    Messages
    151
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Vosges (Lorraine)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Industrie

    Informations forums :
    Inscription : Avril 2011
    Messages : 151
    Points : 89
    Points
    89
    Par défaut
    J'essaye ca et je te redis ... merci de passer du temps à m'aider c'est vraiment super sympa

Discussions similaires

  1. probleme de rotation de texte
    Par Kobe70 dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 14/03/2008, 14h36
  2. [Direct3D] Rotation de texte
    Par tnarol dans le forum DirectX
    Réponses: 4
    Dernier message: 26/01/2007, 18h13
  3. Tcanvas Rotation de texte et impression
    Par kilog dans le forum Delphi
    Réponses: 2
    Dernier message: 21/08/2006, 10h42
  4. [TLabel] rotation du text dans un label
    Par Bourak dans le forum Delphi
    Réponses: 1
    Dernier message: 16/05/2006, 18h08
  5. Rotation de texte et impression
    Par rizom dans le forum Langage
    Réponses: 6
    Dernier message: 16/11/2004, 20h46

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