Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you want to draw rotated text at the center of the image, then offset the location of the text by half the measured size of the text:</p> <pre><code>using (Font font = new Font("Arial", 80, FontStyle.Bold)) using (Graphics g = Graphics.FromImage(pictureBox1.Image)) { float w = pictureBox1.Image.Width / 2f; float h = pictureBox1.Image.Height / 2f; g.TranslateTransform(w, h); g.RotateTransform(90); SizeF size = g.MeasureString("Hello world", font); PointF drawPoint = new PointF(-size.Width / 2f, -size.Height / 2f); g.DrawString("Hello world", font, Brushes.White, drawPoint); } pictureBox1.Refresh(); </code></pre> <p>(It's a good idea to dispose of <code>Font</code> and <code>Graphics</code> objects when you're done with them, so I've added a couple <code>using</code> statements.)</p> <p><strong>Variation #1:</strong> This snippet positions the upper-left corner of the text at (400, 200) and then rotates the text around <em>that point</em>:</p> <pre><code>g.TranslateTransform(400, 200); g.RotateTransform(90); PointF drawPoint = new PointF(0, 0); g.DrawString("Hello world", font, Brushes.White, drawPoint); </code></pre> <p><strong>Variation #2:</strong> This snippet positions the upper-left corner of the text at (400, 200) and then rotates the text around <em>the center of the text</em>:</p> <pre><code>SizeF size = g.MeasureString("Hello world", font); g.TranslateTransform(400 + size.Width / 2, 200 + size.Height / 2); g.RotateTransform(90); PointF drawPoint = new PointF(-size.Width / 2, -size.Height / 2); g.DrawString("Hello world", font, Brushes.White, drawPoint); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload