views:

579

answers:

1

I am attempting to rotate some text within a label. I have a cusom label which allows me to have control over the text rendering process.

protected override void OnPaint ( PaintEventArgs pe )
{
    Graphics g = pe.Graphics;
    g.RotateTransform( angle );

    g.drawString( text );

    g.ResetTransform();
}

The problem I am having is that the rotation appears to occur aroundthe origin of the control i.e. co-ordinates (0,0). Is there a method to allow the text to rotate about the center of the control rather than the oragin?

I am aware of the function 'g.RotateTransform( )' so one possible solution would be to rotate the text and then translate it to the centre of the control. If this is the only way to manage the job, is there a generic manner which I can caluclate the transfor to ensure that the text is in the centre of the control?

Thanks

+2  A: 

A rotation around an arbitrary point is usually a translation of that point to the origin, then a rotation and a translation back again. The problem would probably be to determine the dimensions of the text after rotation to move it back accordingly.

Joey