10659 : How to rotate something in the background draw…

Question

In my application I would like to draw some background text (using OnTimeItemAreaPaintBackground) to have some vertical text along a vertical line (where I can name a holiday, name a deadline, or whatever).

I tried doing this using a combination of G.TranslateTransform, G.RotateTransform, and G.DrawString in this event. I can successfully draw the string, but it seems to be messing up the Gantt’s own drawing when I do this.

Do you have any sample code on how to successfully draw background text like this?

Answer

When you rotate a Graphics object it will stay rotated until you rotate it back. In the sample below we draw some text at an 22 degree angle.

We then rotate the Graphics object back -22 degrees…

        Font font=new Font(FontFamily.GenericMonospace,46,FontStyle.Bold);
        Matrix matrix=new Matrix();
        matrix.RotateAt(22,new Point(0,0));
        G.Transform=matrix;
        G.DrawString(“Hey I am 22”,font,new SolidBrush(Color.FromArgb(alpha,255,0,0)),60,-40);
        Matrix matrix2=new Matrix();
        matrix2.RotateAt(-22,new Point(0,0));
        G.Transform=matrix2;
        font.Dispose

Leave a Reply