2016-07-13 8 views
0

I Zugschnur Methode Text innerhalb Rechteck zu zeichnen, .. i wollte den Text 180 Grad drehen, so dass ich diesen Code verwendetZugschnur drehen Langtext 180

Rectangle displayRectangleh = 
     new Rectangle(new Point((int)posh.X, (int)posh.Y), new Size(rectwdh, recth)); 

    StringFormat format1h = new StringFormat(StringFormatFlags.DirectionVertical); 
    format1h.LineAlignment = StringAlignment.Center; 
    format1h.Alignment = StringAlignment.Center; 
    b = new SolidBrush(Color.Black); 
    e.ChartGraphics.Graphics.TranslateTransform((float)rectwdh/2 + posh.X, recth/2 + posh.Y); 
    e.ChartGraphics.Graphics.RotateTransform(180); 
    e.ChartGraphics.Graphics.TranslateTransform(-((float)rectwdh/2 + posh.X), -(recth/2 + posh.Y)); 
      Font boldFonth = new Font(FontFamily.GenericSansSerif, 16, FontStyle.Bold, GraphicsUnit.Pixel, 1, true); 
    e.ChartGraphics.Graphics.DrawRectangle(new Pen(Color.Black, 2), displayRectangleh); 
    e.ChartGraphics.Graphics.DrawString("This is rotated long text test ", boldFonth, b, (RectangleF)displayRectangleh, format1h); 
    e.ChartGraphics.Graphics.ResetTransform(); 

wo posh.X und posh.Y (recatangle Position), rectwdh (Rechteck Breite) und recth (Rechteck Höhe)

Es funktioniert für kurzen Text perfekt, aber für langen Text der neue Linie wird über meiner alte Linie siehe nächstes Bild sein:

enter image description here

Ich habe sogar versucht, neue Zeile Zeichen \ n aber das gleiche Ergebnis hinzuzufügen. meine Frage: wie man den Text 180 innerhalb des Rechtecks ​​dreht und am Ende mit richtiger Ausrichtung endet ??

Antwort

0

nie selbst der String APIs, bevor sie verwendet hat, ich es zufällig schlug, bis ich diese gefunden:

StringFormat format1h = new StringFormat(StringFormatFlags.DirectionVertical | StringFormatFlags.DirectionRightToLeft);

+0

Dank, hat den Trick und funktioniert für mich – user1477332