begin process at 2010 02 10 08:12:55
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Graphique

 > COMMENT ÉCRIRE DU TEXTE VERTICAL ?

COMMENT ÉCRIRE DU TEXTE VERTICAL ?


 Information sur la source

Note :
8 / 10 - par 2 personnes
8,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Graphique Source .NET ( DotNet ) Classé sous :graphique, ecrire, gdi, vertical, text Niveau :Débutant Date de création :17/10/2005 Vu :21 202

Auteur : zigxag

Ecrire un message privé
Site perso
Commentaire sur cette source (4)
Ajouter un commentaire et/ou une note

 Description

Il est souvent demandé, lorsque des histogrammes doivent être affichés, d’écrire du texte verticalement. Or, rien n’est prévu dan le framework pour faire cela ! La seule solution est de créer une image du texte à afficher, puis de la faire pivoter…
Pour écrire du texte verticalement, la seule solution est de transformer ce texte en image et de faire pivoter cette image de 90°, comme ceci :

Source

  • string message = "Mon texte à afficher";
  • // Création de l'image
  • Bitmap b = new Bitmap(1, 1);
  • Font f = new Font("Arial", 8);
  • Graphics graphics = Graphics.FromImage(b);
  • int width = (int) graphics.MeasureString(message,f).Width;
  • int height = (int) graphics.MeasureString(message,f).Height;
  • b = new Bitmap(b, new Size(height, width));
  • graphics = Graphics.FromImage(b);
  • graphics.Clear(Color.White);
  • graphics.SmoothingMode = SmoothingMode.HighQuality;
  • graphics.SmoothingMode = SmoothingMode.AntiAlias;
  • // Création du texte de l'image
  • StringFormat sf = StringFormat.GenericTypographic;
  • sf.FormatFlags = StringFormatFlags.DirectionVertical; // Position verticale
  • graphics.DrawString(message, f, new SolidBrush(Color.FromArgb(62, 62, 62)), 0, 0, sf);
  • graphics.Flush();
  • // Enregistrement de l'image
  • string directory = System.Configuration.ConfigurationSettings.AppSettings["installPath"];
  • message = message.Replace(" ", "");
  • directory += @"\Images\Generated\" + message + ".gif";
  • b.Save(directory, System.Drawing.Imaging.ImageFormat.Gif);
string message = "Mon texte à afficher";

// Création de l'image
Bitmap b = new Bitmap(1, 1);
Font f = new Font("Arial", 8);
Graphics graphics = Graphics.FromImage(b);			
int width = (int) graphics.MeasureString(message,f).Width;
int height = (int) graphics.MeasureString(message,f).Height;
b = new Bitmap(b, new Size(height, width));
graphics = Graphics.FromImage(b);
graphics.Clear(Color.White);
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.SmoothingMode = SmoothingMode.AntiAlias;
			
// Création du texte de l'image
StringFormat sf = StringFormat.GenericTypographic;
sf.FormatFlags = StringFormatFlags.DirectionVertical;	// Position verticale
graphics.DrawString(message, f, new SolidBrush(Color.FromArgb(62, 62, 62)), 0, 0, sf);
graphics.Flush();

// Enregistrement de l'image
string directory = System.Configuration.ConfigurationSettings.AppSettings["installPath"];
message = message.Replace(" ", "");
directory += @"\Images\Generated\" + message + ".gif";
b.Save(directory, System.Drawing.Imaging.ImageFormat.Gif);

 Conclusion

L’image est créée en fonction du texte à écrire. Cette image doit ensuite être enregistrée sur le disque dur du serveur, ce qui nécessite de donner les bons droits d’accès à ce répertoire.


 Sources de la même categorie

Source avec Zip Source avec une capture Source .NET (Dotnet) NOTIFICATIONS DANS UN DELEGATE ASYNCHRONE par olivieram2
Source avec Zip Source avec une capture Source .NET (Dotnet) PIXEL SHADER - CRÉATION, UTILISATION, ET BINDING par yoannd
Source avec Zip Source avec une capture Source .NET (Dotnet) UITYPEEDITOR HACKING, PROPERTYGRID ET LISTVIEW CONFIGURABLES... par gourky
Source avec Zip Source .NET (Dotnet) CONVERTION D'UNE IMAGE EN G-CODE, GRAVURE CNC par gourky
Source avec Zip Source .NET (Dotnet) CAROUSEL EN WPF (USERCONTROL) par CoolSpirit

 Sources en rapport avec celle ci

Source avec Zip Source avec une capture Source .NET (Dotnet) PIXEL SHADER - CRÉATION, UTILISATION, ET BINDING par yoannd
Source avec Zip Source avec une capture Source .NET (Dotnet) METHODE GRAPHIQUE EN PROGRAMMATION LINÉAIRE par vindos
Source avec Zip PILOTER EXCEL VIA MICROSOFT.OFFICE.INTEROP.EXCEL par whismeril
Source avec Zip Source avec une capture Source .NET (Dotnet) RICHTEXTBOX NUMÉROTÉ (NUMÉROS DE LIGNES) par jray
Source avec Zip Source avec une capture Source .NET (Dotnet) GRAPHIQUE TYPE SECTEUR par Yxion

Commentaires et avis

Commentaire de badrbadr le 18/10/2005 17:41:21

interresante ta méthode, mais je pense bien que le framework .net a prevu qqch pour ces situations-la, je m'explique:

voici une fonction que j'avais trouver sur msdn qui ecrit du texte vertical:

private void DrawVerticalText()
{
   System.Drawing.Graphics formGraphics = this.CreateGraphics();
   string drawString = "Sample Text";
   System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 16);
   System.Drawing.SolidBrush drawBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Black);
   float x = 150.0f;
   float y = 50.0f;
   System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);
   formGraphics.DrawString(drawString, drawFont, drawBrush, x, y, drawFormat);
   drawFont.Dispose();
   drawBrush.Dispose();
   formGraphics.Dispose();
}

tout se joue dans le format du string
System.Drawing.StringFormat drawFormat = new System.Drawing.StringFormat(StringFormatFlags.DirectionVertical);
avec le flag StringFormatFlags.DirectionVertical

en tout cas, ton code nous apprend a faire d autre chose comme par exemple comment dessiner ou ecrire dans une image.

bonne contuniation

Commentaire de bucherb le 04/11/2005 11:05:21

Tu peux aussi utiliser tourner ton objet Graphics par la propriété "Transform" en lui passant un objet Matrix (qui contient tout ce qu'il faut pour faire des transformations), puis faire ton DrawString normalement et ensuite rétablit ton Graphics en faisant ResetTransform... Ca a l'avantage de pouvoir écrire du texte selon n'importe quel angle.

Commentaire de ahaccoun le 12/09/2008 20:14:17

j'ai fait comme ceci:

private static void drawVerticalString(string text, Point p, Font font, Form myForm)
        {
            System.Drawing.Drawing2D.GraphicsPath gp = new System.Drawing.Drawing2D.GraphicsPath();
            gp.AddString(text, font.FontFamily, (int)font.Style, font.Size+4, p, StringFormat.GenericTypographic);
            System.Drawing.Drawing2D.Matrix m = new System.Drawing.Drawing2D.Matrix();
            m.RotateAt(270, p, System.Drawing.Drawing2D.MatrixOrder.Append);
            gp.Transform(m);
            myForm.CreateGraphics().FillPath(new SolidBrush(Color.Black), gp);
        }

Commentaire de gillardg le 14/10/2008 01:39:26

salut,
3 méthode pour le prix d'une seule ,
merci

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

Texte editeur [ par rintchu ] Salut, je voudrais creer un text editeur mélangé avec un treeview, un peu ce que l'on a quand on programme avec Microsoft .Net 2003 ( on peut ecrire e gdi+ et crystal report [ par matmat86 ] Bonjour,j'ai créé un graphique a l'aide de gdi+ et il m'a été demandé de permettre l'impression de ce graphique.J'ai entendu parler de Crystal Report Ecrire dans un panel en GDI [ par iow4 ] Bonjour, J'utilise le framework 2 avec VC#.J'ai inseré sur une winform un panel et j'aimerais tracer un rectangle par dessus Seulement lorsque le rect ecrire dans une panel [ par fayrous ] Salut tout le monde , dans mon form j'ai un textBox ,un button et une panel je veux afficher le texte dans la panel et voila le code private void but probleme de recuperation de donnees d'un formulaire cross post-back [ par atino ] bonjour,j'ai un probleme ,je n'arrive pas à récupérer les données dans  un formulaire pour les mettre sur une autre pagevoici le code de ma 1ere page C# é base de données [ par nehAm ] Salut tt l monde, j ve exécuté une requete d'ajout alor k jé d champs facultatif a remplir comme champ email (textbox7) é champs numéro de téléphone p base de donnée&c# [ par medinfo87 ] <link rel="Fi combobox [ par teksakina ] salut tout le mondeje voudrais afficher les informations d'un personnel  dans des textbox en choisissant son id à partir d'un comboboxlanguage utilisé base de donnée&c# [ par medinfo87 ] Salut tout le monde, Je veux exécuter une requete d'ajout alors que j'ai des champs facultatifs à remplir comme champ email (textbox7) et champs nu Menu c# [ par shedex ] Bonjour, Est -il possible de créer un menu vertical sous c# ??Car je cherche mais je ne trouve pas je c'est faire le menu horizontal mais le vertical


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,593 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales