using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

using System.Drawing.Drawing2D;
using System.Drawing.Text;

namespace DrawRotatedText
{
    public partial class frm31DrawRotatedText : Form
    {
        public frm31DrawRotatedText()
        {
            InitializeComponent();
        }

        private void frm31DrawRotatedText_Paint(object sender, PaintEventArgs e)
        {
            e.Graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;

            using (Font font = new Font("Comic Sans MS", 20))
            {
                const int dx = 40;
                int x = 10;
                int y = ClientSize.Height - 10;
                DrawRotatedTextAt(e.Graphics, -90, "January", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "February", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "March", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "April", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "May", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "June", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "July", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "August", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "September", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "October", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "November", x, y, font, Brushes.Red);
                x += dx;
                DrawRotatedTextAt(e.Graphics, -90, "December", x, y, font, Brushes.Red);
            }
        }

        // Draw a rotated string at a particular position.
        private void DrawRotatedTextAt(Graphics gr, float angle, string text, int x, int y, Font font, Brush brush)
        {
            // Save the graphics state.
            GraphicsState state = gr.Save();
            gr.ResetTransform();

            // Rotate.
            gr.RotateTransform(angle);

            // Translate to the desired position. Be sure to append
            // the translation so it occurs after the rotation.
            gr.TranslateTransform(x, y, MatrixOrder.Append);

            // Draw the text at the origin.
            gr.DrawString(text, font, brush, 0, 0);

            // Restore the graphics state.
            gr.Restore(state);
        }


        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Windows Form Designer generated code

        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.SuspendLayout();
            // 
            // frm31DrawRotatedText
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(495, 168);
            this.Name = "frm31DrawRotatedText";
            this.Text = "DrawRotatedText";
            this.Paint += new System.Windows.Forms.PaintEventHandler(this.frm31DrawRotatedText_Paint);
            this.ResumeLayout(false);

        }

        #endregion
    }
}